eitri-cli 1.0.2
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/README.md +54 -0
- package/bitbucket-pipelines.toBeChanged.yml +64 -0
- package/boilerplate/mini-app-cafe-madeira.zip +0 -0
- package/check-version.js +12 -0
- package/config/default-eitri.js +1 -0
- package/config/dev.js +91 -0
- package/config/k8s-eitri.js +92 -0
- package/config/loc-eitri.js +92 -0
- package/config/prod-eitri.js +92 -0
- package/config/test-eitri.js +2 -0
- package/index-eitri.js +6 -0
- package/index.js +182 -0
- package/install-dev.bat +1 -0
- package/install-dev.sh +1 -0
- package/jest.config.js +6 -0
- package/jsconfig.json +9 -0
- package/package.json +80 -0
- package/publisher.js +53 -0
- package/src/cmd/clean.js +179 -0
- package/src/cmd/create.js +281 -0
- package/src/cmd/credentials.js +105 -0
- package/src/cmd/invite.js +87 -0
- package/src/cmd/list.js +36 -0
- package/src/cmd/login.js +51 -0
- package/src/cmd/manage-env.js +129 -0
- package/src/cmd/open-share.js +6 -0
- package/src/cmd/order-details.js +6 -0
- package/src/cmd/push-version.js +182 -0
- package/src/cmd/show-message-if-outdated-package.js +32 -0
- package/src/cmd/signup.js +69 -0
- package/src/cmd/start.js +171 -0
- package/src/cmd/tail-logs.js +26 -0
- package/src/cmd/test-initialization-params.js +6 -0
- package/src/cmd/validate.js +170 -0
- package/src/cmd/version.js +29 -0
- package/src/enum/WatcherOpts.js +3 -0
- package/src/enum/target.js +6 -0
- package/src/helpers/request-listener-helper.js +55 -0
- package/src/model/Payload.js +45 -0
- package/src/model/Target.js +76 -0
- package/src/model/User.js +11 -0
- package/src/service/AuthConfig.js +88 -0
- package/src/service/BlindGuardian.js +134 -0
- package/src/service/CliLogin.js +47 -0
- package/src/service/ConfigService.js +16 -0
- package/src/service/CredentialsService.js +47 -0
- package/src/service/GATrackingStrategy.js +16 -0
- package/src/service/HashFolder.js +79 -0
- package/src/service/Http.js +234 -0
- package/src/service/InviteService.js +45 -0
- package/src/service/ManageEnvService.js +10 -0
- package/src/service/MiniLog.js +132 -0
- package/src/service/QRCodeFactory.js +43 -0
- package/src/service/Server.js +239 -0
- package/src/service/StarterService.js +31 -0
- package/src/service/TagTree.js +101 -0
- package/src/service/TargetService.js +97 -0
- package/src/service/TrackService.js +11 -0
- package/src/service/TrackingEitriAnalytics.js +32 -0
- package/src/service/TrackingService.js +183 -0
- package/src/service/ValidateResult.js +57 -0
- package/src/service/Watcher.js +119 -0
- package/src/service/Workspace.js +1069 -0
- package/src/service/WorkspaceManager.js +74 -0
- package/src/service/factories/DoubtsStarterFactory.js +25 -0
- package/src/service/factories/MiniWebAppFactory.js +43 -0
- package/src/service/factories/QRCodeStarterFactory.js +78 -0
- package/src/service/factories/WebStarterFactory.js +88 -0
- package/src/service/factories/WoodCoffeeFactory.js +230 -0
- package/src/util/AboutTemplate.jsx +14 -0
- package/src/util/UrlUtils.js +12 -0
- package/src/util/UserLocalCredential.js +122 -0
- package/src/util/error-messages/error-messages.js +24 -0
- package/src/util/error-messages/invite/invite-error-messages.js +14 -0
- package/src/util/getCliVersion.js +13 -0
- package/src/util/getCreateFactory.js +9 -0
- package/src/util/ipv4.js +19 -0
- package/src/util/manage-env.js +65 -0
- package/src/util/open-docs.js +7 -0
- package/src/util/os.js +39 -0
- package/src/util/server-url.js +15 -0
- package/src/util/template-utils.js +21 -0
- package/src/view/index.html +19 -0
- package/targetMobileStickyness.md +47 -0
- package/targetWebStickyness.md +40 -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 +3 -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/credentials.test.js +159 -0
- package/test/cmd/list.test.js +74 -0
- package/test/cmd/manage-env.test.js +168 -0
- package/test/cmd/signup.test.js +20 -0
- package/test/cmd/start.test.js +5 -0
- package/test/miniapp.conf.js +3 -0
- package/test/model/Payload.test.js +35 -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 +364 -0
- package/thinQrCode.md +58 -0
- package/v1.5.0.md +3 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
|
|
3
|
+
const nock = require('nock')
|
|
4
|
+
const Http = require('../../src/service/Http')
|
|
5
|
+
const BlindGuardian = require('../../src/service/BlindGuardian')
|
|
6
|
+
const FormData = require('form-data')
|
|
7
|
+
|
|
8
|
+
describe('Http', () => {
|
|
9
|
+
let blindGuardian, tokenCount
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
tokenCount = 1
|
|
13
|
+
blindGuardian = new BlindGuardian()
|
|
14
|
+
blindGuardian.getToken = async () => {
|
|
15
|
+
let accessToken = `xpto ${tokenCount++}`
|
|
16
|
+
return { accessToken }
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
nock.cleanAll()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('.postForm(url, formData)', () => {
|
|
25
|
+
it('envia o token no header', async () => {
|
|
26
|
+
let bodyReceived
|
|
27
|
+
nock('http://myhost')
|
|
28
|
+
.matchHeader('authorization', /Bearer xpto 1/)
|
|
29
|
+
.post('/somepath', (body) => {
|
|
30
|
+
bodyReceived = body
|
|
31
|
+
return true
|
|
32
|
+
})
|
|
33
|
+
.reply(200, { ok: true })
|
|
34
|
+
let http = new Http(null)
|
|
35
|
+
http.setTokenFactory(blindGuardian)
|
|
36
|
+
const formData = new FormData()
|
|
37
|
+
formData.append('test', '123')
|
|
38
|
+
|
|
39
|
+
await http.postForm('http://myhost/somepath', formData)
|
|
40
|
+
expect(bodyReceived).toBeDefined()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('tenta novamente com um novo token quando o servidor retorna 401 ', async () => {
|
|
44
|
+
nock('http://myhost').post('/somepath').reply(401, { error: '' })
|
|
45
|
+
let bodyReceived
|
|
46
|
+
nock('http://myhost')
|
|
47
|
+
.matchHeader('authorization', /Bearer xpto 2/)
|
|
48
|
+
.post('/somepath', (body) => {
|
|
49
|
+
bodyReceived = body
|
|
50
|
+
return true
|
|
51
|
+
})
|
|
52
|
+
.reply(200, { ok: true, statusCode: 200 })
|
|
53
|
+
let http = new Http(null)
|
|
54
|
+
http.setTokenFactory(blindGuardian)
|
|
55
|
+
const formData = new FormData()
|
|
56
|
+
formData.append('test', '123')
|
|
57
|
+
|
|
58
|
+
const response = await http.postForm(
|
|
59
|
+
'http://myhost/somepath',
|
|
60
|
+
formData
|
|
61
|
+
)
|
|
62
|
+
expect(bodyReceived).toBeDefined()
|
|
63
|
+
expect(response.ok).toBeTruthy()
|
|
64
|
+
expect(response.statusCode).toStrictEqual(200)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('tenta somente 3x com um novo token quando o servidor retorna 401', async () => {
|
|
68
|
+
nock('http://myhost')
|
|
69
|
+
.post(/\/somepath.*/)
|
|
70
|
+
.reply(401, { error: '' })
|
|
71
|
+
nock('http://myhost')
|
|
72
|
+
.matchHeader('authorization', /Bearer xpto 2/)
|
|
73
|
+
.post(/\/somepath.*/)
|
|
74
|
+
.reply(401, { ok: true })
|
|
75
|
+
let scope = nock('http://myhost')
|
|
76
|
+
.matchHeader('authorization', /Bearer xpto 3/)
|
|
77
|
+
.post(/\/somepath.*/)
|
|
78
|
+
.reply(401, { ok: true })
|
|
79
|
+
let scope2 = nock('http://myhost')
|
|
80
|
+
.matchHeader('authorization', /Bearer xpto 4/)
|
|
81
|
+
.post(/\/somepath.*/)
|
|
82
|
+
.reply(200, { ok: true })
|
|
83
|
+
let http = new Http(null)
|
|
84
|
+
http.setTokenFactory(blindGuardian)
|
|
85
|
+
const formData = new FormData()
|
|
86
|
+
formData.append('test', '123')
|
|
87
|
+
try {
|
|
88
|
+
await http.postForm('http://myhost/somepath', formData)
|
|
89
|
+
} catch (e) {
|
|
90
|
+
expect(e.response.status).toBe(401)
|
|
91
|
+
}
|
|
92
|
+
expect(scope.isDone()).toBe(true)
|
|
93
|
+
expect(scope2.isDone()).toBe(false)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('mostra um erro educadamente', async (done) => {
|
|
97
|
+
nock('http://myhost')
|
|
98
|
+
.matchHeader('authorization', /Bearer xpto 1/)
|
|
99
|
+
.post('/somepath', (body) => {
|
|
100
|
+
bodyReceived = body
|
|
101
|
+
return true
|
|
102
|
+
})
|
|
103
|
+
.reply(422, { error: 'Mensagem de erro' })
|
|
104
|
+
let http = new Http(null)
|
|
105
|
+
http.setTokenFactory(blindGuardian)
|
|
106
|
+
const formData = new FormData()
|
|
107
|
+
formData.append('test', '123')
|
|
108
|
+
try {
|
|
109
|
+
await http.postForm('http://myhost/somepath', formData)
|
|
110
|
+
done('nao deveria chegar aqui')
|
|
111
|
+
} catch (e) {
|
|
112
|
+
expect(e.message).toContain('Mensagem de erro')
|
|
113
|
+
done()
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('exibe erro 500', async (done) => {
|
|
119
|
+
nock('http://myhost')
|
|
120
|
+
.post('/somepath')
|
|
121
|
+
.reply(500, { error: 'Meu Erro' })
|
|
122
|
+
let http = new Http(null)
|
|
123
|
+
http.setTokenFactory(blindGuardian)
|
|
124
|
+
let formData = { test: '123' }
|
|
125
|
+
try {
|
|
126
|
+
await http.postForm('http://myhost/somepath', formData)
|
|
127
|
+
done('Nao deveria passar aqui')
|
|
128
|
+
} catch (e) {
|
|
129
|
+
done()
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
describe('.delete(url, options)', () => {
|
|
134
|
+
it('envia o token no header', async () => {
|
|
135
|
+
let scope = nock('http://myhost')
|
|
136
|
+
.matchHeader('authorization', /Bearer xpto 1/)
|
|
137
|
+
.delete(/\/somepath.*/)
|
|
138
|
+
.reply(200, { ok: true, statusCode: 200 })
|
|
139
|
+
|
|
140
|
+
let http = new Http(null)
|
|
141
|
+
http.setTokenFactory(blindGuardian)
|
|
142
|
+
|
|
143
|
+
let params = { filepath: 'myfile' }
|
|
144
|
+
const response = await http.delete('http://myhost/somepath', {
|
|
145
|
+
params,
|
|
146
|
+
})
|
|
147
|
+
expect(scope.isDone()).toBeTruthy()
|
|
148
|
+
expect(response.ok).toBeTruthy()
|
|
149
|
+
expect(response.statusCode).toStrictEqual(200)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('tenta novamente com um novo token quando o servidor retorna 401 ', async () => {
|
|
153
|
+
nock('http://myhost')
|
|
154
|
+
.delete(/\/somepath.*/)
|
|
155
|
+
.reply(401, { error: '' })
|
|
156
|
+
let scope = nock('http://myhost')
|
|
157
|
+
.matchHeader('authorization', /Bearer xpto 2/)
|
|
158
|
+
.delete(/\/somepath.*/)
|
|
159
|
+
.reply(200, { ok: true })
|
|
160
|
+
let http = new Http(null)
|
|
161
|
+
http.setTokenFactory(blindGuardian)
|
|
162
|
+
|
|
163
|
+
let params = { filepath: 'myfile' }
|
|
164
|
+
await http.delete('http://myhost/somepath', { params })
|
|
165
|
+
expect(scope.isDone()).toBe(true)
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
describe('.get(url, options)', () => {
|
|
170
|
+
it('envia o token no header', async () => {
|
|
171
|
+
let scope = nock('http://myhost')
|
|
172
|
+
.matchHeader('authorization', /Bearer xpto 1/)
|
|
173
|
+
.get(/\/somepath.*/)
|
|
174
|
+
.reply(200, { ok: true })
|
|
175
|
+
|
|
176
|
+
let http = new Http(null)
|
|
177
|
+
http.setTokenFactory(blindGuardian)
|
|
178
|
+
await http.get('http://myhost/somepath')
|
|
179
|
+
expect(scope.isDone()).toBe(true)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it('tenta novamente com um novo token quando o servidor retorna 401 ', async () => {
|
|
183
|
+
nock('http://myhost')
|
|
184
|
+
.get(/\/somepath.*/)
|
|
185
|
+
.reply(401, { error: '' })
|
|
186
|
+
let scope = nock('http://myhost')
|
|
187
|
+
.matchHeader('authorization', /Bearer xpto 2/)
|
|
188
|
+
.get(/\/somepath.*/)
|
|
189
|
+
.reply(200, { ok: true })
|
|
190
|
+
let http = new Http(null)
|
|
191
|
+
http.setTokenFactory(blindGuardian)
|
|
192
|
+
let result = await http.get('http://myhost/somepath')
|
|
193
|
+
expect(result.ok).toBe(true)
|
|
194
|
+
expect(scope.isDone()).toBe(true)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('tenta somente 3x com um novo token quando o servidor retorna 401', async () => {
|
|
198
|
+
nock('http://myhost')
|
|
199
|
+
.get(/\/somepath.*/)
|
|
200
|
+
.reply(401, { error: '' })
|
|
201
|
+
nock('http://myhost')
|
|
202
|
+
.matchHeader('authorization', /Bearer xpto 2/)
|
|
203
|
+
.get(/\/somepath.*/)
|
|
204
|
+
.reply(401, { ok: true })
|
|
205
|
+
let scope = nock('http://myhost')
|
|
206
|
+
.matchHeader('authorization', /Bearer xpto 3/)
|
|
207
|
+
.get(/\/somepath.*/)
|
|
208
|
+
.reply(401, { ok: true })
|
|
209
|
+
let scope2 = nock('http://myhost')
|
|
210
|
+
.matchHeader('authorization', /Bearer xpto 4/)
|
|
211
|
+
.get(/\/somepath.*/)
|
|
212
|
+
.reply(200, { ok: true })
|
|
213
|
+
let http = new Http(null)
|
|
214
|
+
http.setTokenFactory(blindGuardian)
|
|
215
|
+
try {
|
|
216
|
+
await http.get('http://myhost/somepath')
|
|
217
|
+
} catch (e) {
|
|
218
|
+
expect(e.response.status).toBe(401)
|
|
219
|
+
}
|
|
220
|
+
expect(scope.isDone()).toBe(true)
|
|
221
|
+
expect(scope2.isDone()).toBe(false)
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
describe('.put(url, data)', () => {
|
|
226
|
+
it('envia o token no header', async () => {
|
|
227
|
+
let scope = nock('http://myhost')
|
|
228
|
+
.matchHeader('authorization', /Bearer xpto 1/)
|
|
229
|
+
.put(/\/somepath.*/)
|
|
230
|
+
.reply(200, { ok: true })
|
|
231
|
+
|
|
232
|
+
let http = new Http(null)
|
|
233
|
+
http.setTokenFactory(blindGuardian)
|
|
234
|
+
await http.put('http://myhost/somepath', { foo: 'bar' })
|
|
235
|
+
expect(scope.isDone()).toBe(true)
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('tenta novamente com um novo token quando o servidor retorna 401 ', async () => {
|
|
239
|
+
nock('http://myhost')
|
|
240
|
+
.get(/\/somepath.*/)
|
|
241
|
+
.reply(401, { error: '' })
|
|
242
|
+
let scope = nock('http://myhost')
|
|
243
|
+
.matchHeader('authorization', /Bearer xpto 2/)
|
|
244
|
+
.get(/\/somepath.*/)
|
|
245
|
+
.reply(200, { ok: true })
|
|
246
|
+
let http = new Http(null)
|
|
247
|
+
http.setTokenFactory(blindGuardian)
|
|
248
|
+
let result = await http.get('http://myhost/somepath')
|
|
249
|
+
expect(result.ok).toBe(true)
|
|
250
|
+
expect(scope.isDone()).toBe(true)
|
|
251
|
+
})
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
describe('Interceptor', () => {
|
|
255
|
+
it('deve retornar o objeto de warning message', async () => {
|
|
256
|
+
nock('https://dev.eitri.calindra.com.br')
|
|
257
|
+
.get('/workspace/health')
|
|
258
|
+
.reply(200, {
|
|
259
|
+
'warning': {
|
|
260
|
+
'message': 'Tem breaking changes, atualize a cli.',
|
|
261
|
+
'status': 'VALID'
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
let http = new Http(null)
|
|
265
|
+
http.setTokenFactory(blindGuardian)
|
|
266
|
+
let result = await http.get('https://dev.eitri.calindra.com.br/workspace/health')
|
|
267
|
+
expect(result.warning).toBeDefined()
|
|
268
|
+
expect(result.warning.message).toEqual('Tem breaking changes, atualize a cli.')
|
|
269
|
+
expect(result.warning.status).toEqual('VALID')
|
|
270
|
+
})
|
|
271
|
+
it('deve retornar o objeto de greeting message', async () => {
|
|
272
|
+
nock('https://dev.eitri.calindra.com.br')
|
|
273
|
+
.get('/workspace/health')
|
|
274
|
+
.reply(200, {
|
|
275
|
+
'greeting': {
|
|
276
|
+
'message': 'FELIZ NATAL!',
|
|
277
|
+
'status': 'VALID'
|
|
278
|
+
}
|
|
279
|
+
})
|
|
280
|
+
let http = new Http(null)
|
|
281
|
+
http.setTokenFactory(blindGuardian)
|
|
282
|
+
let result = await http.get('https://dev.eitri.calindra.com.br/workspace/health')
|
|
283
|
+
expect(result.greeting).toBeDefined()
|
|
284
|
+
expect(result.greeting.message).toEqual('FELIZ NATAL!')
|
|
285
|
+
expect(result.greeting.status).toEqual('VALID')
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
it('deve retornar o objeto de greeting e waring message', async () => {
|
|
289
|
+
nock('https://dev.eitri.calindra.com.br')
|
|
290
|
+
.get('/workspace/health')
|
|
291
|
+
.reply(200, {
|
|
292
|
+
'greeting': {
|
|
293
|
+
'message': 'FELIZ NATAL!',
|
|
294
|
+
'status': 'VALID'
|
|
295
|
+
},
|
|
296
|
+
'warning': {
|
|
297
|
+
'message': 'Tem breaking changes, atualize a cli.',
|
|
298
|
+
'status': 'VALID'
|
|
299
|
+
}
|
|
300
|
+
})
|
|
301
|
+
let http = new Http(null)
|
|
302
|
+
http.setTokenFactory(blindGuardian)
|
|
303
|
+
let result = await http.get('https://dev.eitri.calindra.com.br/workspace/health')
|
|
304
|
+
expect(result.greeting).toBeDefined()
|
|
305
|
+
expect(result.greeting.message).toEqual('FELIZ NATAL!')
|
|
306
|
+
expect(result.greeting.status).toEqual('VALID')
|
|
307
|
+
expect(result.warning).toBeDefined()
|
|
308
|
+
expect(result.warning.message).toEqual('Tem breaking changes, atualize a cli.')
|
|
309
|
+
expect(result.warning.status).toEqual('VALID')
|
|
310
|
+
})
|
|
311
|
+
})
|
|
312
|
+
})
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const nock = require('nock')
|
|
5
|
+
const InviteService = require('../../src/service/InviteService')
|
|
6
|
+
|
|
7
|
+
describe('InviteService', () => {
|
|
8
|
+
|
|
9
|
+
let workspace, folder2watch, inviteService, invite
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
nock.cleanAll()
|
|
13
|
+
invite = {
|
|
14
|
+
id: 18,
|
|
15
|
+
email: 'dev@calindra.com.br',
|
|
16
|
+
miniAppName: 'Nome do miniapp',
|
|
17
|
+
slug: 'miniapp-slug',
|
|
18
|
+
status: 'ACTIVE',
|
|
19
|
+
token: 'RandwYNDBvsebQpR721',
|
|
20
|
+
inviterEmail: 'revisor@calindra.com.br',
|
|
21
|
+
}
|
|
22
|
+
folder2watch = path.resolve(__dirname, '..', '_fixtures')
|
|
23
|
+
|
|
24
|
+
workspace = require('../../src/service/Workspace').workspace
|
|
25
|
+
workspace.setFolder2Watch(folder2watch)
|
|
26
|
+
workspace.setServerUrl('https://dev.eitri.calindra.com.br')
|
|
27
|
+
|
|
28
|
+
// para pegar um token de verdade basta comentar o codigo abaixo
|
|
29
|
+
workspace.blindGuardian.getToken = async () => {
|
|
30
|
+
return { accessToken: 'xpto' }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
inviteService = new InviteService(workspace)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
nock.cleanAll()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const mockReadInvitesEndPoint = () => {
|
|
42
|
+
nock('https://dev.eitri.calindra.com.br', { allowUnmocked: true })
|
|
43
|
+
.get('/miniapp-manager-api/p/myInvites')
|
|
44
|
+
.reply(200, [invite])
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const mockFindInvitesBySlugEndPoint = () => {
|
|
48
|
+
nock('https://dev.eitri.calindra.com.br', { allowUnmocked: true })
|
|
49
|
+
.get(/\/miniapp-manager-api\/p\/invites\/s\/.*/)
|
|
50
|
+
.reply(200, [invite])
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
it('lista os convites do desenvolvedor', async () => {
|
|
54
|
+
mockReadInvitesEndPoint()
|
|
55
|
+
let invites = await inviteService.findAllPending()
|
|
56
|
+
expect(invites[0].email).toBeDefined()
|
|
57
|
+
expect(invites[0].miniAppName).toBeDefined()
|
|
58
|
+
expect(invites[0].slug).toBeDefined()
|
|
59
|
+
expect(invites[0].status).toBeDefined()
|
|
60
|
+
expect(invites[0].token).toBeDefined()
|
|
61
|
+
expect(invites[0].inviterEmail).toBeDefined()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('aceita um convite', async () => {
|
|
65
|
+
let bodySentToApi
|
|
66
|
+
mockReadInvitesEndPoint()
|
|
67
|
+
nock('https://dev.eitri.calindra.com.br', { allowUnmocked: true })
|
|
68
|
+
.put(`/miniapp-manager-api/p/invites/accept`, body => {
|
|
69
|
+
bodySentToApi = body
|
|
70
|
+
return true
|
|
71
|
+
})
|
|
72
|
+
.reply(200, {})
|
|
73
|
+
let invites = await inviteService.findAllPending()
|
|
74
|
+
await inviteService.accept(invites[0])
|
|
75
|
+
expect(bodySentToApi).toBeDefined()
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('envia um convite', async () => {
|
|
79
|
+
let bodySentToApi
|
|
80
|
+
nock('https://dev.eitri.calindra.com.br', { allowUnmocked: true })
|
|
81
|
+
.post('/miniapp-manager-api/p/invites', body => {
|
|
82
|
+
bodySentToApi = body
|
|
83
|
+
return true
|
|
84
|
+
})
|
|
85
|
+
.reply(200, {})
|
|
86
|
+
await inviteService.sendInvite('teste-convite-dev', 'fabio.oshiro@calindra.com.br')
|
|
87
|
+
expect(bodySentToApi.email).toBe('fabio.oshiro@calindra.com.br')
|
|
88
|
+
expect(bodySentToApi.slug).toBe('teste-convite-dev')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('lista os convites de um miniapp', async () => {
|
|
92
|
+
mockFindInvitesBySlugEndPoint()
|
|
93
|
+
let invites = await inviteService.findAllBySlug('teste-convite-dev')
|
|
94
|
+
expect(invites[0]).toBeDefined()
|
|
95
|
+
expect(invites[0].email).toBeDefined()
|
|
96
|
+
expect(invites[0].token).toBeDefined()
|
|
97
|
+
expect(invites[0].slug).toBeDefined()
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('remove um convite', async () => {
|
|
101
|
+
let bodySentToApi
|
|
102
|
+
mockFindInvitesBySlugEndPoint()
|
|
103
|
+
nock('https://dev.eitri.calindra.com.br', { allowUnmocked: true })
|
|
104
|
+
.delete(`/miniapp-manager-api/p/invites/${invite.token}`, body => {
|
|
105
|
+
bodySentToApi = body
|
|
106
|
+
return true
|
|
107
|
+
})
|
|
108
|
+
.reply(200, {})
|
|
109
|
+
|
|
110
|
+
// somente para testar a vera
|
|
111
|
+
// await inviteService.sendInvite('teste-convite-dev', 'fabio.oshiro@calindra.com.br')
|
|
112
|
+
|
|
113
|
+
let invites = await inviteService.findAllBySlug('teste-convite-dev')
|
|
114
|
+
await inviteService.remove(invites.find(inv => inv.status !== 'CANCELLED'))
|
|
115
|
+
expect(bodySentToApi).toBeDefined()
|
|
116
|
+
})
|
|
117
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
|
|
6
|
+
const MiniWebAppFactory = require('../../src/service/factories/MiniWebAppFactory')
|
|
7
|
+
|
|
8
|
+
describe('MiniWebAppFactory', () => {
|
|
9
|
+
let miniWebAppFactory
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
miniWebAppFactory = new MiniWebAppFactory()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('.writeAmeConf(project, conf, libsName)', () => {
|
|
15
|
+
it('valida se o miniapp.conf.js foi criado corretamente', async () => {
|
|
16
|
+
let conf = {}
|
|
17
|
+
conf['version'] = '0.1.0'
|
|
18
|
+
|
|
19
|
+
let project = {}
|
|
20
|
+
project['projectPath'] = path.resolve(__dirname, '..', '_fixtures', 'miniWebApp')
|
|
21
|
+
|
|
22
|
+
let libsName = ['eitri-mini-app-sdk-support']
|
|
23
|
+
await miniWebAppFactory.writeAmeConf(project, conf, libsName)
|
|
24
|
+
|
|
25
|
+
let expectedConf = {
|
|
26
|
+
'version': '0.1.0',
|
|
27
|
+
'eitri-mini-app-sdk-support': '2.0.0'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let expected = `module.exports = ${JSON.stringify(expectedConf, null, 4)}`
|
|
31
|
+
|
|
32
|
+
const data = fs.readFileSync(path.join(project.projectPath, 'miniapp.conf.js'), {
|
|
33
|
+
encoding: 'utf-8',
|
|
34
|
+
flag: 'r'
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
expect(data).toBe(expected)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const TagTree = require('../../src/service/TagTree')
|
|
5
|
+
const componentsPath = path.resolve(
|
|
6
|
+
__dirname,
|
|
7
|
+
'..',
|
|
8
|
+
'_fixtures',
|
|
9
|
+
'src',
|
|
10
|
+
'components'
|
|
11
|
+
)
|
|
12
|
+
describe('TagTree', () => {
|
|
13
|
+
describe('.tagsFilesSorted(tagsPath)', () => {
|
|
14
|
+
it('ordena os arquivos de acordo com a sua dependencia', async () => {
|
|
15
|
+
let expected = ['TagC.jsx', 'TagB.jsx', 'TagA.jsx', 'TagD.jsx']
|
|
16
|
+
let filesSorted = await new TagTree().tagsFilesSorted(
|
|
17
|
+
componentsPath
|
|
18
|
+
)
|
|
19
|
+
expect(filesSorted).toEqual(expected)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
describe('.extractTagsFromContent(markup)', () => {
|
|
23
|
+
it('encontra as tags dentro de um jsx', () => {
|
|
24
|
+
let markup = '<View><MyTag>Content</MyTag></View>'
|
|
25
|
+
let tags = new TagTree().extractTagsFromContent(markup)
|
|
26
|
+
expect(tags).toContain('View')
|
|
27
|
+
expect(tags).toContain('MyTag')
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
describe('.buildTagMap(tagsPath)', () => {
|
|
31
|
+
it('gera uma estrutura das tags em um diretorio', async () => {
|
|
32
|
+
let expected = {
|
|
33
|
+
TagA: {
|
|
34
|
+
name: 'TagA',
|
|
35
|
+
fileName: 'TagA.jsx',
|
|
36
|
+
children: [
|
|
37
|
+
{
|
|
38
|
+
name: 'TagB',
|
|
39
|
+
fileName: 'TagB.jsx',
|
|
40
|
+
children: [
|
|
41
|
+
{
|
|
42
|
+
name: 'TagC',
|
|
43
|
+
fileName: 'TagC.jsx',
|
|
44
|
+
children: [],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'TagC',
|
|
50
|
+
fileName: 'TagC.jsx',
|
|
51
|
+
children: [],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
TagB: {
|
|
56
|
+
name: 'TagB',
|
|
57
|
+
fileName: 'TagB.jsx',
|
|
58
|
+
children: [
|
|
59
|
+
{
|
|
60
|
+
name: 'TagC',
|
|
61
|
+
fileName: 'TagC.jsx',
|
|
62
|
+
children: [],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
TagC: {
|
|
67
|
+
name: 'TagC',
|
|
68
|
+
fileName: 'TagC.jsx',
|
|
69
|
+
children: [],
|
|
70
|
+
},
|
|
71
|
+
TagD: {
|
|
72
|
+
name: 'TagD',
|
|
73
|
+
fileName: 'TagD.jsx',
|
|
74
|
+
children: [],
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
let tree = await new TagTree().buildTagMap(componentsPath)
|
|
78
|
+
expect(tree).toEqual(expected)
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
const TargetService = require('../../src/service/TargetService')
|
|
3
|
+
const {workspace} = require('../../src/service/Workspace')
|
|
4
|
+
const nock = require('nock')
|
|
5
|
+
describe('TargetService Tests', () => {
|
|
6
|
+
/**
|
|
7
|
+
* @type {TargetService}
|
|
8
|
+
*/
|
|
9
|
+
let service, targets
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
workspace.setServerUrl('https://dev.eitri.calindra.com.br')
|
|
12
|
+
service = new TargetService(workspace)
|
|
13
|
+
targets = [
|
|
14
|
+
{
|
|
15
|
+
id: 7,
|
|
16
|
+
name: 'CALINDRA_MOBILE',
|
|
17
|
+
minimumCliVersion: '1.16.5',
|
|
18
|
+
boilerplateUrl: 'https://github.com/Calindra/servless-backend-template.git',
|
|
19
|
+
superAppClientLibName: 'eitri-app-client',
|
|
20
|
+
componentsLibName: 'eitri-app-components',
|
|
21
|
+
description: 'AME_DIGITAL_MOBILE',
|
|
22
|
+
status: 'ACTIVE',
|
|
23
|
+
platform: 'mobile',
|
|
24
|
+
targetConfig: [],
|
|
25
|
+
bodyClass: 'eitri-mobile',
|
|
26
|
+
sdkSupport: 'eitri-mini-app-sdk-support',
|
|
27
|
+
default: true,
|
|
28
|
+
miniAppBoilerplate: [
|
|
29
|
+
{
|
|
30
|
+
name: 'serverless',
|
|
31
|
+
boilerplateUrl: 'https://github.com/Calindra/servless-backend-template.git',
|
|
32
|
+
description: 'Para uso de miniapp com serverless'
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
nock('https://dev.eitri.calindra.com.br', { allowUnmocked: true })
|
|
39
|
+
.get('/workspace/targets')
|
|
40
|
+
.reply(200, targets)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('should return all targets', async () => {
|
|
44
|
+
const response = await service.getTargets()
|
|
45
|
+
expect(response.length).toBeGreaterThan(0)
|
|
46
|
+
expect(response).toEqual(targets)
|
|
47
|
+
})
|
|
48
|
+
})
|