Skip to content

Commit cff87f7

Browse files
committed
tests: add service to validate tests
need to change the assertion structure because there's no way to know which service fetched the zipcode without getting it from response.
1 parent f92feed commit cff87f7

File tree

2 files changed

+89
-67
lines changed

2 files changed

+89
-67
lines changed

test/e2e/cep-promise.spec.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,30 @@ let expect = chai.expect
1414

1515
describe('cep-promise (E2E)', () => {
1616
describe('when invoked with a valid "05010000" string', () => {
17-
it('should fulfill with correct address', () => {
18-
return expect(cep('05010000')).to.eventually.deep.equal({
19-
cep: '05010000',
20-
state: 'SP',
21-
city: 'São Paulo',
22-
neighborhood: 'Perdizes',
23-
street: 'Rua Caiubi'
24-
})
25-
})
17+
it('should fulfill with correct address', () => cep('05010000')
18+
.then(address => expect(address).to.deep.equal({
19+
cep: '05010000',
20+
state: 'SP',
21+
city: 'São Paulo',
22+
neighborhood: 'Perdizes',
23+
street: 'Rua Caiubi',
24+
service: address.service
25+
}))
26+
)
2627
})
2728

28-
describe('when invoked with a valid 5010000 number', () => {
29-
it('should fulfill with correct address', () => {
30-
return expect(cep(5010000)).to.eventually.deep.equal({
31-
cep: '05010000',
32-
state: 'SP',
33-
city: 'São Paulo',
34-
neighborhood: 'Perdizes',
35-
street: 'Rua Caiubi'
36-
})
29+
describe('when invoked with a valid 05010000 number', () => {
30+
it('should fulfill with correct address', async () => {
31+
const address = await cep(5010000)
32+
33+
expect(address).to.deep.equal({
34+
cep: '05010000',
35+
state: 'SP',
36+
city: 'São Paulo',
37+
neighborhood: 'Perdizes',
38+
street: 'Rua Caiubi',
39+
service: address.service
40+
})
3741
})
3842
})
3943

test/unit/cep-promise.spec.js

Lines changed: 67 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,16 @@ describe('cep-promise (unit)', () => {
159159
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
160160
)
161161

162-
return expect(cep('05010000')).to.eventually.deep.equal({
163-
cep: '05010000',
164-
state: 'SP',
165-
city: 'São Paulo',
166-
neighborhood: 'Perdizes',
167-
street: 'Rua Caiubi'
168-
})
162+
return cep('05010000')
163+
.then(address => expect(address).to.deep.equal({
164+
cep: '05010000',
165+
state: 'SP',
166+
city: 'São Paulo',
167+
neighborhood: 'Perdizes',
168+
street: 'Rua Caiubi',
169+
service: address.service
170+
})
171+
)
169172
})
170173
})
171174

@@ -192,13 +195,16 @@ describe('cep-promise (unit)', () => {
192195
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
193196
)
194197

195-
return expect(cep(5010000)).to.eventually.deep.equal({
196-
cep: '05010000',
197-
state: 'SP',
198-
city: 'São Paulo',
199-
neighborhood: 'Perdizes',
200-
street: 'Rua Caiubi'
201-
})
198+
return cep(5010000)
199+
.then(address => expect(address).to.deep.equal({
200+
cep: '05010000',
201+
state: 'SP',
202+
city: 'São Paulo',
203+
neighborhood: 'Perdizes',
204+
street: 'Rua Caiubi',
205+
service: address.service
206+
})
207+
)
202208
})
203209
})
204210

@@ -225,13 +231,16 @@ describe('cep-promise (unit)', () => {
225231
path.join(__dirname, '/fixtures/widenet-cep-99999999-error.json')
226232
)
227233

228-
return expect(cep('5010000')).to.eventually.deep.equal({
229-
cep: '05010000',
230-
state: 'SP',
231-
city: 'São Paulo',
232-
neighborhood: 'Perdizes',
233-
street: 'Rua Caiubi'
234-
})
234+
return cep('05010000')
235+
.then(address => expect(address).to.deep.equal({
236+
cep: '05010000',
237+
state: 'SP',
238+
city: 'São Paulo',
239+
neighborhood: 'Perdizes',
240+
street: 'Rua Caiubi',
241+
service: address.service
242+
})
243+
)
235244
})
236245
})
237246

@@ -258,13 +267,16 @@ describe('cep-promise (unit)', () => {
258267
path.join(__dirname, '/fixtures/widenet-cep-99999999-error.json')
259268
)
260269

261-
return expect(cep('5010000')).to.eventually.deep.equal({
262-
cep: '05010000',
263-
state: 'SP',
264-
city: 'São Paulo',
265-
neighborhood: 'Perdizes',
266-
street: 'Rua Caiubi'
267-
})
270+
return cep('05010000')
271+
.then(address => expect(address).to.deep.equal({
272+
cep: '05010000',
273+
state: 'SP',
274+
city: 'São Paulo',
275+
neighborhood: 'Perdizes',
276+
street: 'Rua Caiubi',
277+
service: address.service
278+
})
279+
)
268280
})
269281
})
270282

@@ -291,14 +303,16 @@ describe('cep-promise (unit)', () => {
291303
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
292304
)
293305

294-
return expect(cep('5010000')).to.eventually.deep.equal({
295-
cep: '05010000',
296-
state: 'SP',
297-
city: 'São Paulo',
298-
neighborhood: 'Perdizes',
299-
street: 'Rua Caiubi'
306+
return cep('5010000')
307+
.then(address => expect(address).to.deep.equal({
308+
cep: '05010000',
309+
state: 'SP',
310+
city: 'São Paulo',
311+
neighborhood: 'Perdizes',
312+
street: 'Rua Caiubi',
313+
service: address.service
314+
}))
300315
})
301-
})
302316
})
303317

304318
describe('when its not possible to parse the returned XML and then succeed to one failover service', () => {
@@ -324,13 +338,15 @@ describe('cep-promise (unit)', () => {
324338
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
325339
)
326340

327-
return expect(cep('5010000')).to.eventually.deep.equal({
328-
cep: '05010000',
329-
state: 'SP',
330-
city: 'São Paulo',
331-
neighborhood: 'Perdizes',
332-
street: 'Rua Caiubi'
333-
})
341+
return cep('5010000')
342+
.then(address => expect(address).to.deep.equal({
343+
cep: '05010000',
344+
state: 'SP',
345+
city: 'São Paulo',
346+
neighborhood: 'Perdizes',
347+
street: 'Rua Caiubi',
348+
service: address.service
349+
}))
334350
})
335351
})
336352

@@ -356,13 +372,15 @@ describe('cep-promise (unit)', () => {
356372
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
357373
)
358374

359-
return expect(cep('5010000')).to.eventually.deep.equal({
360-
cep: '05010000',
361-
state: 'SP',
362-
city: 'São Paulo',
363-
neighborhood: 'Perdizes',
364-
street: 'Rua Caiubi'
365-
})
375+
return cep('5010000')
376+
.then(address => expect(address).to.deep.equal({
377+
cep: '05010000',
378+
state: 'SP',
379+
city: 'São Paulo',
380+
neighborhood: 'Perdizes',
381+
street: 'Rua Caiubi',
382+
service: address.service
383+
}))
366384
})
367385
})
368386

0 commit comments

Comments
 (0)