eitri-cli 1.10.0 → 1.10.1-beta.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/eitri-cli-v2/eitri-cli-v2.darwin-arm64.node +0 -0
- package/eitri-cli-v2/eitri-cli-v2.darwin-x64.node +0 -0
- package/eitri-cli-v2/eitri-cli-v2.linux-x64-gnu.node +0 -0
- package/eitri-cli-v2/eitri-cli-v2.win32-x64-msvc.node +0 -0
- package/package.json +1 -1
- package/src/modules/vegvisir/VegvisirService.js +1 -1
- package/src/service/Emulator/AndroidEmulatorService.js +25 -3
- package/src/service/MiniLog.js +5 -46
- package/src/service/factories/WoodCoffeeFactory.js +4 -3
- package/src/util/LibUtil.js +32 -0
- package/eitri-cli-v2/src/commands/mod.rs +0 -2
- package/eitri-cli-v2/src/commands/publish.rs +0 -35
- package/eitri-cli-v2/src/commands/run_test.rs +0 -41
- package/eitri-cli-v2/src/config/mod.rs +0 -1
- package/eitri-cli-v2/src/config/user_credentials.rs +0 -38
- package/eitri-cli-v2/src/infra/http_client.rs +0 -493
- package/eitri-cli-v2/src/infra/mod.rs +0 -1
- package/eitri-cli-v2/src/lib.rs +0 -30
- package/eitri-cli-v2/src/model/auth_response.rs +0 -8
- package/eitri-cli-v2/src/model/credentials.rs +0 -8
- package/eitri-cli-v2/src/model/eitri_conf.rs +0 -43
- package/eitri-cli-v2/src/model/mod.rs +0 -8
- package/eitri-cli-v2/src/model/process_output.rs +0 -8
- package/eitri-cli-v2/src/model/revision.rs +0 -14
- package/eitri-cli-v2/src/model/test_config.rs +0 -7
- package/eitri-cli-v2/src/model/url.rs +0 -11
- package/eitri-cli-v2/src/model/workspace_auth.rs +0 -4
- package/eitri-cli-v2/src/services/blind_guardian.rs +0 -87
- package/eitri-cli-v2/src/services/eitri_foundry.rs +0 -84
- package/eitri-cli-v2/src/services/eitri_manager.rs +0 -78
- package/eitri-cli-v2/src/services/mod.rs +0 -4
- package/eitri-cli-v2/src/services/workspace.rs +0 -49
- package/eitri-cli-v2/src/utils/convert_eitri_conf.rs +0 -98
- package/eitri-cli-v2/src/utils/mod.rs +0 -1
- package/test/Executor.js +0 -60
- package/test/Factory.js +0 -13
- package/test/Helper.js +0 -15
- package/test/_fixtures/factory.js +0 -30
- package/test/_fixtures/miniWebApp/miniapp.conf.js +0 -4
- package/test/_fixtures/miniapp.conf.js +0 -5
- package/test/_fixtures/server/HelloWorldBackend.js +0 -7
- package/test/_fixtures/src/Home.js +0 -5
- package/test/_fixtures/src/Home2.js +0 -5
- package/test/_fixtures/src/commons/util.js +0 -3
- package/test/_fixtures/src/components/TagA.jsx +0 -4
- package/test/_fixtures/src/components/TagB.jsx +0 -4
- package/test/_fixtures/src/components/TagC.jsx +0 -3
- package/test/_fixtures/src/components/TagD.jsx +0 -3
- package/test/_fixtures/src/server/foo.js +0 -7
- package/test/_fixtures/src/views/AboutTemplate.jsx +0 -14
- package/test/_fixtures/woodcoffee/miniapp.conf.js +0 -5
- package/test/ame.conf.js +0 -3
- package/test/cmd/clean.test.js +0 -66
- package/test/cmd/create.test.js +0 -252
- package/test/cmd/list.test.js +0 -74
- package/test/cmd/manage-env.test.js +0 -168
- package/test/e2e/cli.test.js +0 -473
- package/test/miniapp.conf.js +0 -3
- package/test/model/Payload.test.js +0 -35
- package/test/modules/vegvisir/VegvisirService.test.js +0 -37
- package/test/service/BlindGuardian.test.js +0 -84
- package/test/service/CheckAmeConf.test.js +0 -313
- package/test/service/Http.test.js +0 -312
- package/test/service/InviteService.test.js +0 -117
- package/test/service/MiniWebAppFactory.test.js +0 -40
- package/test/service/TagTree.test.js +0 -81
- package/test/service/TargetService.test.js +0 -48
- package/test/service/TrackingService.test.js +0 -105
- package/test/service/UserAmeConf.test.js +0 -47
- package/test/service/WoodCoffeeFactory.test.js +0 -148
- package/test/service/Workspace.test.js +0 -211
- package/test/utils/getWorkspaceId.test.js +0 -17
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-undef */
|
|
2
|
-
const Validate = require('../../src/cmd/validate').validate
|
|
3
|
-
|
|
4
|
-
describe('Field Validate', () => {
|
|
5
|
-
let elementpublish
|
|
6
|
-
//categoria do teste
|
|
7
|
-
it('Json Correto', done => {
|
|
8
|
-
elementpublish = {
|
|
9
|
-
organization: {
|
|
10
|
-
name: 'Meu Mini App'
|
|
11
|
-
},
|
|
12
|
-
name: 'Izabella',
|
|
13
|
-
title: 'Meu super mini app',
|
|
14
|
-
slug: 'com.amedigital.loja',
|
|
15
|
-
version: '1.0.0'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let validateResult = Validate(elementpublish)
|
|
19
|
-
expect(validateResult.isSuccess()).toBe(true) // espera o resultado
|
|
20
|
-
done()
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('Json slug com letra maiuscula', done => {
|
|
24
|
-
elementpublish = {
|
|
25
|
-
organization: {
|
|
26
|
-
name: 'Meu Mini App'
|
|
27
|
-
},
|
|
28
|
-
name: 'Izabella',
|
|
29
|
-
title: 'Meu super mini app',
|
|
30
|
-
slug: 'MeuSlug',
|
|
31
|
-
version: '1.0.0'
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let validateResult = Validate(elementpublish)
|
|
35
|
-
expect(validateResult.isSuccess()).toBe(true) // espera o resultado
|
|
36
|
-
done()
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('Name com caracteres ! - &', done => {
|
|
40
|
-
elementpublish = {
|
|
41
|
-
organization: {
|
|
42
|
-
name: 'Meu Mini App'
|
|
43
|
-
},
|
|
44
|
-
name: 'Izabella! & - +',
|
|
45
|
-
title: 'Meu super mini app',
|
|
46
|
-
slug: 'MeuSlug',
|
|
47
|
-
version: '1.0.0'
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
let validateResult = Validate(elementpublish)
|
|
51
|
-
expect(validateResult.isSuccess()).toBe(true) // espera o resultado
|
|
52
|
-
done()
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('Title com caracteres ! - &', done => {
|
|
56
|
-
elementpublish = {
|
|
57
|
-
organization: {
|
|
58
|
-
name: 'Meu Mini App'
|
|
59
|
-
},
|
|
60
|
-
name: 'Izabella! & - +',
|
|
61
|
-
title: 'MiniApp ! & - +',
|
|
62
|
-
slug: 'MeuSlug',
|
|
63
|
-
version: '1.0.0'
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
let validateResult = Validate(elementpublish)
|
|
67
|
-
expect(validateResult.isSuccess()).toBe(true) // espera o resultado
|
|
68
|
-
done()
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('Validação do campo OrganizationName', done => {
|
|
72
|
-
elementorganization = {
|
|
73
|
-
organization: {
|
|
74
|
-
name: 'Meu Mini App'
|
|
75
|
-
},
|
|
76
|
-
name: 'Izabella Assad',
|
|
77
|
-
title: 'Meu super mini app',
|
|
78
|
-
slug: 'com.amedigital.loja',
|
|
79
|
-
version: '1.0'
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let validateResult = Validate(elementorganization)
|
|
83
|
-
expect(validateResult.isSuccess()).toBe(false)
|
|
84
|
-
done()
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('Validação do campo Name', done => {
|
|
88
|
-
elementorganization = {
|
|
89
|
-
organization: {
|
|
90
|
-
name: 'Meu Mini App'
|
|
91
|
-
},
|
|
92
|
-
name: 'Izabella_Assad',
|
|
93
|
-
title: 'Meu super mini app',
|
|
94
|
-
slug: 'com.amedigital.loja',
|
|
95
|
-
version: '1.0.0'
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
let validateResult = Validate(elementorganization)
|
|
99
|
-
expect(validateResult.isSuccess()).toBe(false)
|
|
100
|
-
done()
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('name, title e version incorretos', done => {
|
|
104
|
-
elementpublish = {
|
|
105
|
-
organization: {
|
|
106
|
-
name: 'Meu Mini App'
|
|
107
|
-
},
|
|
108
|
-
name: 'Izabella--.',
|
|
109
|
-
title: 'Meu super mini app,.;',
|
|
110
|
-
slug: 'com.amedigital.loja',
|
|
111
|
-
version: '1.0'
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let validateResult = Validate(elementpublish)
|
|
115
|
-
expect(validateResult.isSuccess()).toBe(false) // espera o resultado
|
|
116
|
-
expect(validateResult.errors.length).toBe(3)
|
|
117
|
-
done()
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('Valida name errado', done => {
|
|
121
|
-
elementpublish = {
|
|
122
|
-
organization: {
|
|
123
|
-
name: 'Meu Mini App'
|
|
124
|
-
},
|
|
125
|
-
name: 'Izabel$la',
|
|
126
|
-
title: 'Meu super mini app',
|
|
127
|
-
slug: 'com.amedigital.loja',
|
|
128
|
-
version: '1.0.0'
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
let validateResult = Validate(elementpublish)
|
|
132
|
-
expect(validateResult.isSuccess()).toBe(false) // espera o resultado
|
|
133
|
-
expect(validateResult.errors.length).toBe(1)
|
|
134
|
-
expect(validateResult.errors[0]).toBe(
|
|
135
|
-
'Por Favor, preencha o campo \'name\' corretamente antes de publicar'
|
|
136
|
-
)
|
|
137
|
-
done()
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
it('Valida NAME inexistente', done => {
|
|
141
|
-
elementpublish = {
|
|
142
|
-
organization: {
|
|
143
|
-
name: 'Meu Mini App'
|
|
144
|
-
},
|
|
145
|
-
title: 'Meu super mini app',
|
|
146
|
-
slug: 'com.amedigital.loja',
|
|
147
|
-
version: '1.0.0'
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
let validateResult = Validate(elementpublish)
|
|
151
|
-
expect(validateResult.isSuccess()).toBe(false) // espera o resultado
|
|
152
|
-
expect(validateResult.errors.length).toBe(1)
|
|
153
|
-
expect(validateResult.errors[0]).toBe(
|
|
154
|
-
'Por Favor, preencha o campo \'name\' (Utilize apenas caracteres maiusculo, minusculo e espaco. Ex: \'Meu Mini App\').'
|
|
155
|
-
)
|
|
156
|
-
done()
|
|
157
|
-
})
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
it('Valida tipo da Version', done => {
|
|
161
|
-
elementpublish = {
|
|
162
|
-
organization: {
|
|
163
|
-
name: 'Meu Mini App'
|
|
164
|
-
},
|
|
165
|
-
|
|
166
|
-
name: 'Izabella',
|
|
167
|
-
title: 'Meu super mini app',
|
|
168
|
-
slug: 'com.amedigital.loja',
|
|
169
|
-
version: 10
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
let validateResult = Validate(elementpublish)
|
|
173
|
-
expect(validateResult.isSuccess()).toBe(false) // espera o resultado
|
|
174
|
-
expect(validateResult.errors[0]).toBe(
|
|
175
|
-
'Por Favor, preencha o campo \'version\' (Utilize esse formato X.Y.Z. Ex: \'1.0.0\').'
|
|
176
|
-
)
|
|
177
|
-
|
|
178
|
-
done()
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
it('Json Correto', done => {
|
|
182
|
-
elementpublish = {
|
|
183
|
-
organization: {
|
|
184
|
-
name: 'Meu Mini App'
|
|
185
|
-
},
|
|
186
|
-
name: 'Izabella',
|
|
187
|
-
title: 'Meu super mini app',
|
|
188
|
-
slug: 'com.amedigital.loja',
|
|
189
|
-
version: '17.45.323'
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
let validateResult = Validate(elementpublish)
|
|
193
|
-
expect(validateResult.isSuccess()).toBe(true)
|
|
194
|
-
done()
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
describe('OnBoarding', () => {
|
|
198
|
-
|
|
199
|
-
it('Quando houver objeto para onboarding, validar com sucesso seus campos', done => {
|
|
200
|
-
elementpublish = {
|
|
201
|
-
organization: {
|
|
202
|
-
name: 'Meu Mini App'
|
|
203
|
-
},
|
|
204
|
-
name: 'Izabella',
|
|
205
|
-
title: 'Meu super mini app',
|
|
206
|
-
slug: 'com.amedigital.loja',
|
|
207
|
-
version: '17.45.323',
|
|
208
|
-
privacy: {
|
|
209
|
-
onBoarding: {
|
|
210
|
-
items: [
|
|
211
|
-
{
|
|
212
|
-
img: 'http://minha.url/da/imagem',
|
|
213
|
-
title: 'Meu titulo de Onboarding',
|
|
214
|
-
description: 'Minha descricao de Onboarding',
|
|
215
|
-
}
|
|
216
|
-
]
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
let validateResult = Validate(elementpublish)
|
|
222
|
-
expect(validateResult.isSuccess()).toBe(true)
|
|
223
|
-
done()
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
it('Quando houver objeto para onboarding, falhar na validacao quando faltar um campo', done => {
|
|
227
|
-
elementpublish = {
|
|
228
|
-
organization: {
|
|
229
|
-
name: 'Meu Mini App'
|
|
230
|
-
},
|
|
231
|
-
name: 'Izabella',
|
|
232
|
-
title: 'Meu super mini app',
|
|
233
|
-
slug: 'com.amedigital.loja',
|
|
234
|
-
version: '17.45.323',
|
|
235
|
-
privacy: {
|
|
236
|
-
onBoarding: {
|
|
237
|
-
items: [
|
|
238
|
-
{
|
|
239
|
-
img: 'http://minha.url/da/imagem',
|
|
240
|
-
title: 'Meu titulo de Onboarding',
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
img: 'http://minha.url/da/imagem2',
|
|
244
|
-
title: 'Meu titulo de Onboarding2',
|
|
245
|
-
description: 'Minha description'
|
|
246
|
-
}
|
|
247
|
-
]
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
let validateResult = Validate(elementpublish)
|
|
253
|
-
expect(validateResult.isSuccess()).toBe(false)
|
|
254
|
-
expect(validateResult.errors[0]).toMatch(/Um ou mais itens do objeto de "onBoarding" nao possui as propriedades {img, title, description}+/)
|
|
255
|
-
done()
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
it('Quando houver objeto para onboarding, falhar na validacao quando "onboarding.items" nao for um array', done => {
|
|
259
|
-
elementpublish = {
|
|
260
|
-
organization: {
|
|
261
|
-
name: 'Meu Mini App'
|
|
262
|
-
},
|
|
263
|
-
name: 'Izabella',
|
|
264
|
-
title: 'Meu super mini app',
|
|
265
|
-
slug: 'com.amedigital.loja',
|
|
266
|
-
version: '17.45.323',
|
|
267
|
-
privacy: {
|
|
268
|
-
onBoarding: {
|
|
269
|
-
items:
|
|
270
|
-
{
|
|
271
|
-
img: 'http://minha.url/da/imagem',
|
|
272
|
-
title: 'Meu titulo de Onboarding',
|
|
273
|
-
description: 'Minha descricao de Onboarding',
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
let validateResult = Validate(elementpublish)
|
|
280
|
-
expect(validateResult.isSuccess()).toBe(false)
|
|
281
|
-
expect(validateResult.errors[0]).toBe('Objeto de configuração "privacy.onBoarding.items" deve ser um array de {img, title, description}')
|
|
282
|
-
done()
|
|
283
|
-
})
|
|
284
|
-
|
|
285
|
-
it('Quando houver objeto para onboarding, falhar na validacao se a propriedade img nao for uma url', done => {
|
|
286
|
-
elementpublish = {
|
|
287
|
-
organization: {
|
|
288
|
-
name: 'Meu Mini App'
|
|
289
|
-
},
|
|
290
|
-
name: 'Izabella',
|
|
291
|
-
title: 'Meu super mini app',
|
|
292
|
-
slug: 'com.amedigital.loja',
|
|
293
|
-
version: '17.45.323',
|
|
294
|
-
privacy: {
|
|
295
|
-
onBoarding: {
|
|
296
|
-
items: [
|
|
297
|
-
{
|
|
298
|
-
img: 'foobar',
|
|
299
|
-
title: 'Meu titulo de Onboarding',
|
|
300
|
-
description: 'Minha descricao de Onboarding',
|
|
301
|
-
}
|
|
302
|
-
]
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
let validateResult = Validate(elementpublish)
|
|
308
|
-
expect(validateResult.isSuccess()).toBe(false)
|
|
309
|
-
expect(validateResult.errors[0]).toBe('onBoarding.Item[0] invalido. Atributo "img" nao eh uma URL: foobar')
|
|
310
|
-
done()
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
})
|
|
@@ -1,312 +0,0 @@
|
|
|
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
|
-
})
|