eitri-cli 1.10.1-beta.1 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eitri-cli-v2/eitri-cli-v2.win32-x64-msvc.node +0 -0
- package/eitri-cli-v2/src/commands/mod.rs +2 -0
- package/eitri-cli-v2/src/commands/publish.rs +35 -0
- package/eitri-cli-v2/src/commands/run_test.rs +41 -0
- package/eitri-cli-v2/src/config/mod.rs +1 -0
- package/eitri-cli-v2/src/config/user_credentials.rs +38 -0
- package/eitri-cli-v2/src/infra/http_client.rs +493 -0
- package/eitri-cli-v2/src/infra/mod.rs +1 -0
- package/eitri-cli-v2/src/lib.rs +30 -0
- package/eitri-cli-v2/src/model/auth_response.rs +8 -0
- package/eitri-cli-v2/src/model/credentials.rs +8 -0
- package/eitri-cli-v2/src/model/eitri_conf.rs +43 -0
- package/eitri-cli-v2/src/model/mod.rs +8 -0
- package/eitri-cli-v2/src/model/process_output.rs +8 -0
- package/eitri-cli-v2/src/model/revision.rs +14 -0
- package/eitri-cli-v2/src/model/test_config.rs +7 -0
- package/eitri-cli-v2/src/model/url.rs +11 -0
- package/eitri-cli-v2/src/model/workspace_auth.rs +4 -0
- package/eitri-cli-v2/src/services/blind_guardian.rs +87 -0
- package/eitri-cli-v2/src/services/eitri_foundry.rs +84 -0
- package/eitri-cli-v2/src/services/eitri_manager.rs +78 -0
- package/eitri-cli-v2/src/services/mod.rs +4 -0
- package/eitri-cli-v2/src/services/workspace.rs +49 -0
- package/eitri-cli-v2/src/utils/convert_eitri_conf.rs +98 -0
- package/eitri-cli-v2/src/utils/mod.rs +1 -0
- package/package.json +1 -1
- package/src/modules/vegvisir/VegvisirService.js +1 -1
- package/src/service/Emulator/AndroidEmulatorService.js +3 -25
- package/src/service/MiniLog.js +46 -5
- package/test/Executor.js +60 -0
- package/test/Factory.js +13 -0
- package/test/Helper.js +15 -0
- package/test/_fixtures/factory.js +30 -0
- package/test/_fixtures/miniWebApp/miniapp.conf.js +4 -0
- package/test/_fixtures/miniapp.conf.js +5 -0
- package/test/_fixtures/server/HelloWorldBackend.js +7 -0
- package/test/_fixtures/src/Home.js +5 -0
- package/test/_fixtures/src/Home2.js +5 -0
- package/test/_fixtures/src/commons/util.js +3 -0
- package/test/_fixtures/src/components/TagA.jsx +4 -0
- package/test/_fixtures/src/components/TagB.jsx +4 -0
- package/test/_fixtures/src/components/TagC.jsx +3 -0
- package/test/_fixtures/src/components/TagD.jsx +3 -0
- package/test/_fixtures/src/server/foo.js +7 -0
- package/test/_fixtures/src/views/AboutTemplate.jsx +14 -0
- package/test/_fixtures/woodcoffee/miniapp.conf.js +5 -0
- package/test/ame.conf.js +3 -0
- package/test/cmd/clean.test.js +66 -0
- package/test/cmd/create.test.js +252 -0
- package/test/cmd/list.test.js +74 -0
- package/test/cmd/manage-env.test.js +168 -0
- package/test/e2e/cli.test.js +473 -0
- package/test/miniapp.conf.js +3 -0
- package/test/model/Payload.test.js +35 -0
- package/test/modules/vegvisir/VegvisirService.test.js +37 -0
- package/test/service/BlindGuardian.test.js +84 -0
- package/test/service/CheckAmeConf.test.js +313 -0
- package/test/service/Http.test.js +312 -0
- package/test/service/InviteService.test.js +117 -0
- package/test/service/MiniWebAppFactory.test.js +40 -0
- package/test/service/TagTree.test.js +81 -0
- package/test/service/TargetService.test.js +48 -0
- package/test/service/TrackingService.test.js +105 -0
- package/test/service/UserAmeConf.test.js +47 -0
- package/test/service/WoodCoffeeFactory.test.js +148 -0
- package/test/service/Workspace.test.js +211 -0
- package/test/utils/getWorkspaceId.test.js +17 -0
package/test/Executor.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const exec = require("child_process").exec
|
|
2
|
+
|
|
3
|
+
class Executor {
|
|
4
|
+
|
|
5
|
+
constructor(execOptions) {
|
|
6
|
+
this.listeners = {}
|
|
7
|
+
this.execOptions = execOptions
|
|
8
|
+
this.children = []
|
|
9
|
+
this.stdout = ''
|
|
10
|
+
this.child = {
|
|
11
|
+
kill: (killArg) => {
|
|
12
|
+
this.children.forEach(c => c.kill(killArg))
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exec(cmdStr, options) {
|
|
18
|
+
console.log(`Executando: ${cmdStr}`)
|
|
19
|
+
const child = exec(cmdStr, options || this.execOptions)
|
|
20
|
+
child.stdout.on('data', lines => {
|
|
21
|
+
this.stdout += lines
|
|
22
|
+
for (const listener in this.listeners) {
|
|
23
|
+
this.listeners[listener](lines)
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
child.stderr.on('data', (lines) => {
|
|
27
|
+
if (lines && lines.includes('Error:')) {
|
|
28
|
+
throw new Error(lines)
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
child.on('exit', (code) => {
|
|
32
|
+
console.log(`child process exited with code ${code}\n\tCommand: ${cmdStr}`);
|
|
33
|
+
const missing = Object.keys(this.listeners)
|
|
34
|
+
if (missing.length) {
|
|
35
|
+
this.reject(new Error(`Ainda aguardando:\n\t ${missing.join('\n\t')}`))
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
this.children.push(child)
|
|
39
|
+
return this
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async waitFor(regex) {
|
|
43
|
+
console.log('Esperando uma linha que case com', regex)
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
this.reject = reject
|
|
46
|
+
this.listeners[regex.toString()] = (lines) => {
|
|
47
|
+
let lineFound = lines.split('\n').find(line => regex.test(line))
|
|
48
|
+
if (lineFound) {
|
|
49
|
+
console.log(`Devolvendo resultado que casou com ${regex}:\n${lineFound}`);
|
|
50
|
+
delete this.listeners[regex.toString()]
|
|
51
|
+
resolve(lineFound)
|
|
52
|
+
} else {
|
|
53
|
+
console.log(`Ignorando child stdout:\n${lines}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = Executor
|
package/test/Factory.js
ADDED
package/test/Helper.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const BlindGuardian = require("../src/service/BlindGuardian");
|
|
2
|
+
const Http = require("../src/service/Http");
|
|
3
|
+
|
|
4
|
+
class Helper {
|
|
5
|
+
|
|
6
|
+
static async delete(eitriAppId) {
|
|
7
|
+
console.log(`Apagando eitri app id ${eitriAppId}...`)
|
|
8
|
+
const blindGuardian = new BlindGuardian();
|
|
9
|
+
const http = new Http(blindGuardian);
|
|
10
|
+
await http.delete(`https://api.eitri.tech/eitri-manager-api/eitri-apps/${eitriAppId}`)
|
|
11
|
+
console.log(`Eitri app id ${eitriAppId} apagado.`)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = Helper
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
const getTarget = () => {
|
|
3
|
+
return {
|
|
4
|
+
id: 7,
|
|
5
|
+
name: 'CALINDRA_MOBILE',
|
|
6
|
+
minimumCliVersion: '1.16.5',
|
|
7
|
+
boilerplateUrl: 'https://github.com/Calindra/eitri-mobile-mini-app-template',
|
|
8
|
+
superAppClientLibName: 'eitri-app-client',
|
|
9
|
+
componentsLibName: 'eitri-app-components',
|
|
10
|
+
description: 'CALINDRA_MOBILE',
|
|
11
|
+
status: 'ACTIVE',
|
|
12
|
+
platform: 'mobile',
|
|
13
|
+
targetConfig: [],
|
|
14
|
+
bodyClass: 'eitri-mobile',
|
|
15
|
+
sdkSupport: 'eitri-mini-app-sdk-support',
|
|
16
|
+
default: true,
|
|
17
|
+
miniAppBoilerplateList: [
|
|
18
|
+
{
|
|
19
|
+
name: 'serverless',
|
|
20
|
+
boilerplateUrl: 'https://github.com/Calindra/eitri-mobile-mini-app-template',
|
|
21
|
+
description: 'Para uso de Eitri-App com serverless'
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
getTarget
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<Window>
|
|
2
|
+
<Group>
|
|
3
|
+
<Circle icon={require('../assets/images/icon_ame.svg')} />
|
|
4
|
+
<Spacing size="sm" />
|
|
5
|
+
<Subtitle fontSize="xs" textAlign="center" color="neutralcolor-darkest">Detalhes desta versão</Subtitle>
|
|
6
|
+
<View>
|
|
7
|
+
<Subtitle textAlign="center" fontSize="xxxs" color="neutralcolor-darkest">Este Eitri-App foi desenvolvido utilizando as seguintes versões:</Subtitle>
|
|
8
|
+
<Spacing size="sm" />
|
|
9
|
+
<Paragraph textAlign="center">Versão da biblioteca de componentes: ###COMPONENTS_LIBRARY_VERSION_HIGHLIGHTER###</Paragraph>
|
|
10
|
+
<Spacing size="sm" />
|
|
11
|
+
<Paragraph textAlign="center">Versão da API de Super Client: ###SUPER_APP_CLIENT_VERSION_HIGHLIGHTER###</Paragraph>
|
|
12
|
+
</View>
|
|
13
|
+
</Group>
|
|
14
|
+
</Window>
|
package/test/ame.conf.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
|
|
3
|
+
const nock = require('nock')
|
|
4
|
+
const MOCK = true
|
|
5
|
+
const HOST = 'https://dev.eitri.calindra.com.br'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
describe('clean', () => {
|
|
9
|
+
|
|
10
|
+
let workspace
|
|
11
|
+
// let developerToken
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
nock.cleanAll()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
workspace = require('../../src/service/Workspace').workspace
|
|
17
|
+
// workspace.setFolder2Watch(folder2watch)
|
|
18
|
+
workspace.setServerUrl(HOST)
|
|
19
|
+
workspace.setMiniConf({ version: '0.1.0' })
|
|
20
|
+
workspace.blindGuardian.getToken = async () => {
|
|
21
|
+
return { accessToken: 'xpto' }
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('should successfully clean remote workspace', async () => {
|
|
26
|
+
if (MOCK) {
|
|
27
|
+
nock(HOST)
|
|
28
|
+
.delete('/foundry/sources')
|
|
29
|
+
.matchHeader('authorization', 'Bearer xpto')
|
|
30
|
+
.reply(204)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const error = await workspace.clean().catch(e => e)
|
|
34
|
+
|
|
35
|
+
expect(error).toBeUndefined()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('should successfully finish operation workspace fails with ENOENT error', async () => {
|
|
39
|
+
if (MOCK) {
|
|
40
|
+
nock(HOST)
|
|
41
|
+
.delete('/foundry/sources')
|
|
42
|
+
.matchHeader('authorization', 'Bearer xpto')
|
|
43
|
+
.reply(500, {
|
|
44
|
+
'req_id': 'b7fc6b22-c6e3-4025-b0c4-96bb7eafc826',
|
|
45
|
+
'error': 'Error: ENOENT: no such file or directory, rename \'/home/node/app/storage/fulano@gmail.com\' -> \'/home/node/app/storage/fulano@gmail.com_expired_1663767068880\''
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const error = await workspace.clean().catch(e => e)
|
|
50
|
+
|
|
51
|
+
expect(error.response.data.error).toMatch(/.+ENOENT: no such file or directory.+/)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('should throw an error when workspace fails with forbidden error', async () => {
|
|
55
|
+
if (MOCK) {
|
|
56
|
+
nock(HOST)
|
|
57
|
+
.delete('/foundry/sources')
|
|
58
|
+
.matchHeader('authorization', 'Bearer xpto')
|
|
59
|
+
.reply(403, '403 Acesso Negado')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const error = await workspace.clean().catch(e => e)
|
|
63
|
+
|
|
64
|
+
expect(error.response.data).toBe('403 Acesso Negado')
|
|
65
|
+
})
|
|
66
|
+
})
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const childProcess = require('child_process')
|
|
5
|
+
const create = require('../../src/cmd/create')
|
|
6
|
+
const nock = require('nock')
|
|
7
|
+
const inquirer = require('inquirer')
|
|
8
|
+
const {faker} = require('@faker-js/faker')
|
|
9
|
+
const WoodCoffee = require('../../src/service/factories/WoodCoffeeFactory')
|
|
10
|
+
const getCreateFactory = require('../../src/util/getCreateFactory')
|
|
11
|
+
const {getTarget} = require('../_fixtures/factory')
|
|
12
|
+
const {workspace} = require('../../src/service/Workspace')
|
|
13
|
+
jest.setTimeout(15000)
|
|
14
|
+
|
|
15
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
16
|
+
|
|
17
|
+
jest.mock('../../src/util/getCreateFactory', () => jest.fn())
|
|
18
|
+
|
|
19
|
+
describe('create', () => {
|
|
20
|
+
xit('cria o mini app no backend ao rodar create', async () => {
|
|
21
|
+
const env = Object.create(process.env)
|
|
22
|
+
|
|
23
|
+
env.NODE_ENV = 'lab'
|
|
24
|
+
console.log(env.NODE_APP_INSTANCE)
|
|
25
|
+
childProcess.execSync('rm -rf ./apagar-pasta')
|
|
26
|
+
child = childProcess.spawn(
|
|
27
|
+
'node',
|
|
28
|
+
['index.js', 'create', 'apagar-pasta'],
|
|
29
|
+
{ env: env }
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
child.stdin.setEncoding('utf8')
|
|
33
|
+
child.stdout.pipe(process.stdout)
|
|
34
|
+
await delay(500)
|
|
35
|
+
child.stdin.write(`Nome-${Date.now()}+1\n`)
|
|
36
|
+
await delay(500)
|
|
37
|
+
child.stdin.write(`titulo-${Date.now()}\n`)
|
|
38
|
+
await delay(500)
|
|
39
|
+
child.stdin.write(`slug-${Date.now()}\n`)
|
|
40
|
+
await delay(500)
|
|
41
|
+
child.stdin.write('empresa\n')
|
|
42
|
+
await delay(7000)
|
|
43
|
+
child.stdin.end()
|
|
44
|
+
|
|
45
|
+
let content = fs.readFileSync(
|
|
46
|
+
path.join(__dirname, '../../apagar-pasta/miniapp.conf.js'),
|
|
47
|
+
'utf8'
|
|
48
|
+
)
|
|
49
|
+
expect(content).toMatch(
|
|
50
|
+
/"public-key": "\w{8}-\w{4}-\w{4}-\w{4}-\w{12}"/
|
|
51
|
+
)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
xit('trata nome ja existente', async () => {
|
|
55
|
+
const env = Object.create(process.env)
|
|
56
|
+
|
|
57
|
+
env.NODE_ENV = 'lab'
|
|
58
|
+
childProcess.execSync('rm -rf ./apagar-pasta')
|
|
59
|
+
child = childProcess.spawn(
|
|
60
|
+
'node',
|
|
61
|
+
['index.js', 'create', 'apagar-pasta'],
|
|
62
|
+
{ env: env }
|
|
63
|
+
)
|
|
64
|
+
child.stdin.setEncoding('utf8')
|
|
65
|
+
child.stdout.pipe(process.stdout)
|
|
66
|
+
let allOutput = ''
|
|
67
|
+
child.stdout.on('data', function (data) {
|
|
68
|
+
data = data.toString()
|
|
69
|
+
allOutput += data
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
await delay(500)
|
|
73
|
+
child.stdin.write('Depositar\n')
|
|
74
|
+
await delay(500)
|
|
75
|
+
child.stdin.write(`titulo-${Date.now()}\n`)
|
|
76
|
+
await delay(500)
|
|
77
|
+
child.stdin.write(`slug-${Date.now()}\n`)
|
|
78
|
+
await delay(500)
|
|
79
|
+
child.stdin.write('empresa\n')
|
|
80
|
+
await delay(5000)
|
|
81
|
+
expect(allOutput).toContain('Outro nome')
|
|
82
|
+
await delay(500)
|
|
83
|
+
child.stdin.write(`Nome ${Date.now()}\n`)
|
|
84
|
+
console.log('ok')
|
|
85
|
+
await delay(5000)
|
|
86
|
+
child.stdin.end()
|
|
87
|
+
let content = fs.readFileSync(
|
|
88
|
+
path.join(__dirname, '../../apagar-pasta/miniapp.conf.js'),
|
|
89
|
+
'utf8'
|
|
90
|
+
)
|
|
91
|
+
expect(content).toMatch(
|
|
92
|
+
/"public-key": "\w{8}-\w{4}-\w{4}-\w{4}-\w{12}"/
|
|
93
|
+
)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
xit('trata slug ja existente', async () => {
|
|
97
|
+
const env = Object.create(process.env)
|
|
98
|
+
|
|
99
|
+
env.NODE_ENV = 'lab'
|
|
100
|
+
childProcess.execSync('rm -rf ./apagar-pasta')
|
|
101
|
+
child = childProcess.spawn(
|
|
102
|
+
'node',
|
|
103
|
+
['index.js', 'create', 'apagar-pasta'],
|
|
104
|
+
{ env: env }
|
|
105
|
+
)
|
|
106
|
+
child.stdin.setEncoding('utf8')
|
|
107
|
+
child.stdout.pipe(process.stdout)
|
|
108
|
+
let allOutput = ''
|
|
109
|
+
child.stdout.on('data', function (data) {
|
|
110
|
+
data = data.toString()
|
|
111
|
+
allOutput += data
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
await delay(500)
|
|
115
|
+
child.stdin.write(`Nome ${Date.now()}\n`)
|
|
116
|
+
await delay(500)
|
|
117
|
+
child.stdin.write(`titulo-${Date.now()}\n`)
|
|
118
|
+
await delay(500)
|
|
119
|
+
child.stdin.write('transaction-cashin\n')
|
|
120
|
+
await delay(500)
|
|
121
|
+
child.stdin.write('empresa\n')
|
|
122
|
+
await delay(5000)
|
|
123
|
+
expect(allOutput).toContain('Outro slug')
|
|
124
|
+
await delay(500)
|
|
125
|
+
child.stdin.write(`slug-${Date.now()}\n`)
|
|
126
|
+
console.log('ok')
|
|
127
|
+
await delay(5000)
|
|
128
|
+
child.stdin.end()
|
|
129
|
+
let content = fs.readFileSync(
|
|
130
|
+
path.join(__dirname, '../../apagar-pasta/miniapp.conf.js'),
|
|
131
|
+
'utf8'
|
|
132
|
+
)
|
|
133
|
+
expect(content).toMatch(
|
|
134
|
+
/"public-key": "\w{8}-\w{4}-\w{4}-\w{4}-\w{12}"/
|
|
135
|
+
)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
describe('--application', () => {
|
|
139
|
+
const expectedTarget = getTarget()
|
|
140
|
+
|
|
141
|
+
// stub inquirer
|
|
142
|
+
let backup
|
|
143
|
+
beforeEach(async () => {
|
|
144
|
+
backup = inquirer.prompt
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('should succesfully show all available targets', async () => {
|
|
148
|
+
|
|
149
|
+
const targets = [expectedTarget, {...expectedTarget, name: 'TARGET_WHATEVER_2'}]
|
|
150
|
+
nock('https://dev.eitri.calindra.com.br')
|
|
151
|
+
.post('/blind-guardian-api/v1/o/auth')
|
|
152
|
+
.reply(200, { accessToken: 'xpto' })
|
|
153
|
+
|
|
154
|
+
nock('https://dev.eitri.calindra.com.br')
|
|
155
|
+
.get('/workspace/targets')
|
|
156
|
+
.matchHeader('Authorization', 'Bearer xpto')
|
|
157
|
+
.reply(200, targets)
|
|
158
|
+
|
|
159
|
+
inquirer.prompt = (questions) => {
|
|
160
|
+
// Checando se o que foi exibido para o usuario esta correto
|
|
161
|
+
expect(questions[0].choices).toMatchObject([
|
|
162
|
+
'CALINDRA_MOBILE',
|
|
163
|
+
'TARGET_WHATEVER_2',
|
|
164
|
+
'Dúvidas? Veja documentação no browser',
|
|
165
|
+
])
|
|
166
|
+
|
|
167
|
+
// Apos a montagem da lista, nao queremos mais que o codigo de negocio restante execute,
|
|
168
|
+
// pois ja identificamos que a lista foi exibida corretamente, que é o objetivo deste teste.
|
|
169
|
+
throw 'success'
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const cmdObjStub = {
|
|
173
|
+
target: 'TARGET_WHATEVER_2',
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const pseudoError = await create('my_project', cmdObjStub).catch(
|
|
177
|
+
(e) => e
|
|
178
|
+
)
|
|
179
|
+
expect(pseudoError).toBe('success')
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
// restore
|
|
183
|
+
afterEach(() => {
|
|
184
|
+
inquirer.prompt = backup
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
afterAll(async () => {
|
|
188
|
+
await nock.cleanAll()
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
describe('--template', () => {
|
|
193
|
+
|
|
194
|
+
let projectName
|
|
195
|
+
let woodCoffee
|
|
196
|
+
let target
|
|
197
|
+
class WoodCoffeeStub extends WoodCoffee {
|
|
198
|
+
// eslint-disable-next-line no-unused-vars
|
|
199
|
+
verifyFolder(_projectName, _options) {
|
|
200
|
+
return new Promise(resolve => resolve('/tmp'))
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// eslint-disable-next-line no-unused-vars
|
|
204
|
+
create(_projectName, _templateUrl) {
|
|
205
|
+
return new Promise(resolve => resolve({projectPath: '/tmp'}))
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
beforeEach(() => {
|
|
210
|
+
nock.cleanAll()
|
|
211
|
+
target = getTarget()
|
|
212
|
+
jest.spyOn(workspace, 'availableTargets').mockImplementationOnce(new Promise(resolve => resolve([target])))
|
|
213
|
+
projectName = faker.commerce.product() + Date.now()
|
|
214
|
+
woodCoffee = new WoodCoffeeStub()
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
afterAll(() => {
|
|
218
|
+
nock.cleanAll()
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
it('should create miniapp with selected template', async () => {
|
|
223
|
+
jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ accepted: 'CALINDRA_MOBILE' })
|
|
224
|
+
getCreateFactory.mockImplementation(() => woodCoffee)
|
|
225
|
+
const factorySpy = jest.spyOn(woodCoffee, 'create')
|
|
226
|
+
const args = {
|
|
227
|
+
target: 'CALINDRA_MOBILE',
|
|
228
|
+
yes: true,
|
|
229
|
+
template: 'serverless'
|
|
230
|
+
}
|
|
231
|
+
await create(projectName, args)
|
|
232
|
+
|
|
233
|
+
expect(factorySpy).toHaveBeenCalledWith(projectName, 'https://github.com/Calindra/eitri-mobile-mini-app-template', target)
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it.skip('should return error on select invalid template', async () => {
|
|
237
|
+
jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ accepted: 'CALINDRA_MOBILE' })
|
|
238
|
+
getCreateFactory.mockImplementation(() => woodCoffee)
|
|
239
|
+
const consoleSpy = jest.spyOn(console, 'error')
|
|
240
|
+
jest.spyOn(process, 'exit')
|
|
241
|
+
.mockImplementation((number) => {return number})
|
|
242
|
+
const args = {
|
|
243
|
+
target: 'CALINDRA_MOBILE',
|
|
244
|
+
yes: true,
|
|
245
|
+
template: 'inexistent template'
|
|
246
|
+
}
|
|
247
|
+
await create(projectName, args)
|
|
248
|
+
|
|
249
|
+
expect(consoleSpy).toHaveBeenCalledWith('O template [inexistent template] não existe para o target selecionado.')
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
})
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
// eslint-disable-next-line no-unused-vars
|
|
3
|
+
const inquirer = require('inquirer')
|
|
4
|
+
const process = require('process')
|
|
5
|
+
const list = require('../../src/cmd/list')
|
|
6
|
+
const { workspace } = require('../../src/service/Workspace')
|
|
7
|
+
const { getTarget } = require('../_fixtures/factory')
|
|
8
|
+
const nock = require('nock')
|
|
9
|
+
|
|
10
|
+
jest.mock('inquirer', () => ({
|
|
11
|
+
prompt: jest.fn(() => {
|
|
12
|
+
return new Promise(resolve => resolve({selected: 'AME_DIGITAL_MOBILE'}))
|
|
13
|
+
})
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
describe.skip('List command test', () => {
|
|
17
|
+
let fakeTarget
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
nock.cleanAll()
|
|
20
|
+
workspace.setServerUrl('https://dev.eitri.calindra.com.br')
|
|
21
|
+
fakeTarget = getTarget()
|
|
22
|
+
})
|
|
23
|
+
it('should print all miniapp templates of selected target', async () => {
|
|
24
|
+
const args = {
|
|
25
|
+
template: true
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
jest.spyOn(workspace, 'availableTargets').mockResolvedValueOnce([fakeTarget])
|
|
29
|
+
const consoleSpy = jest.spyOn(console, 'log')
|
|
30
|
+
await list(args)
|
|
31
|
+
expect(consoleSpy).toHaveBeenCalledTimes(1)
|
|
32
|
+
expect(consoleSpy).toHaveBeenCalledWith('serverless: Para uso de miniapp com serverless \n')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('should return error if target dont have templates', async () => {
|
|
36
|
+
const args = {
|
|
37
|
+
template: true
|
|
38
|
+
}
|
|
39
|
+
fakeTarget.miniAppBoilerplateList = null
|
|
40
|
+
|
|
41
|
+
jest.spyOn(process, 'exit')
|
|
42
|
+
.mockImplementation((number) => {return number})
|
|
43
|
+
|
|
44
|
+
jest.spyOn(workspace, 'availableTargets').mockResolvedValueOnce([fakeTarget])
|
|
45
|
+
|
|
46
|
+
const consoleSpy = jest.spyOn(console, 'error')
|
|
47
|
+
await list(args)
|
|
48
|
+
expect(consoleSpy).toHaveBeenCalledTimes(1)
|
|
49
|
+
expect(consoleSpy).toHaveBeenCalledWith('O Target AME_DIGITAL_MOBILE não possui boilerplates disponíveis.')
|
|
50
|
+
consoleSpy.mockClear()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should return error if doesnt have target', async () => {
|
|
54
|
+
const args = {
|
|
55
|
+
template: true
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
nock('https://dev.eitri.calindra.com.br', { allowUnmocked: true })
|
|
59
|
+
.get('/workspace/targets')
|
|
60
|
+
.reply(400, {message: 'xpto'})
|
|
61
|
+
|
|
62
|
+
const consoleSpy = jest.spyOn(console, 'error')
|
|
63
|
+
|
|
64
|
+
await list(args)
|
|
65
|
+
|
|
66
|
+
jest.spyOn(process, 'exit')
|
|
67
|
+
.mockImplementation((number) => {return number})
|
|
68
|
+
|
|
69
|
+
expect(consoleSpy).toHaveBeenCalledTimes(1)
|
|
70
|
+
expect(consoleSpy).toHaveBeenLastCalledWith('Houve um erro ao listar os targets.')
|
|
71
|
+
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
})
|