File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ declare module 'cep-promise' {
2424
2525 export interface Configurations {
2626 providers ?: AvaliableProviders [ ] ,
27- timeout ?: Number
27+ timeout ?: number
2828 }
2929
3030 export function cep ( cep : string | number , configurations : Configurations ) : Promise < CEP >
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ import chai from 'chai'
4+ import chaiSubset from 'chai-subset'
5+ import nock from 'nock'
6+ import path from 'path'
7+
8+ import cep from '../../src/cep-promise.js'
9+ import CepPromiseError from '../../src/errors/cep-promise.js'
10+
11+ chai . use ( chaiSubset )
12+
13+ let expect = chai . expect
14+
15+ describe ( 'when invoked with timeout parameter' , ( ) => {
16+ before ( ( ) => {
17+ nock . disableNetConnect ( )
18+ } )
19+
20+ describe ( 'and the providers exceed the timeout' , ( ) => {
21+ it ( 'should reject with "service_error"' , ( ) => {
22+ nock ( 'https://brasilapi.com.br/' )
23+ . get ( '/api/cep/v1/05010000' )
24+ . delay ( 3 )
25+ . replyWithFile (
26+ 200 ,
27+ path . join ( __dirname , '/fixtures/brasilapi-cep-05010000-found.json' )
28+ )
29+ return cep ( '05010000' , { timeout : 1 , providers : [ 'brasilapi' ] } )
30+ . then ( ( ) => expect ( true ) . to . be . equal ( false ) )
31+ . catch ( error => {
32+ return expect ( error )
33+ . to . be . an . instanceOf ( CepPromiseError )
34+ . and . containSubset ( {
35+ name : 'CepPromiseError' ,
36+ message : 'Todos os serviços de CEP retornaram erro.' ,
37+ type : 'service_error' ,
38+ errors : [
39+ {
40+ message : 'Erro ao se conectar com o serviço BrasilAPI.' ,
41+ service : 'brasilapi'
42+ }
43+ ]
44+ } )
45+ } )
46+
47+ } )
48+ } )
49+
50+ afterEach ( ( ) => {
51+ nock . cleanAll ( )
52+ } )
53+ } )
You can’t perform that action at this time.
0 commit comments