@@ -34,6 +34,13 @@ describe('[unit] cep-promise for node', () => {
3434 path . join ( __dirname , '/fixtures/response-cep-05010000-found.xml' )
3535 )
3636
37+ nock ( 'https://buscacepinter.correios.com.br' )
38+ . post ( '/app/cep/carrega-cep.php' )
39+ . replyWithFile (
40+ 200 ,
41+ path . join ( __dirname , '/fixtures/correios-alt-cep-05010000-found.json' )
42+ )
43+
3744 nock ( 'https://viacep.com.br' )
3845 . get ( '/ws/05010000/json/' )
3946 . replyWithFile (
@@ -156,6 +163,13 @@ describe('[unit] cep-promise for node', () => {
156163 path . join ( __dirname , '/fixtures/response-cep-05010000-found.xml' )
157164 )
158165
166+ nock ( 'https://buscacepinter.correios.com.br' )
167+ . post ( '/app/cep/carrega-cep.php' )
168+ . replyWithFile (
169+ 200 ,
170+ path . join ( __dirname , '/fixtures/correios-alt-cep-05010000-found.json' )
171+ )
172+
159173 nock ( 'https://viacep.com.br' )
160174 . get ( '/ws/05010000/json/' )
161175 . replyWithFile (
@@ -199,6 +213,13 @@ describe('[unit] cep-promise for node', () => {
199213 path . join ( __dirname , '/fixtures/response-cep-05010000-found.xml' )
200214 )
201215
216+ nock ( 'https://buscacepinter.correios.com.br' )
217+ . post ( '/app/cep/carrega-cep.php' )
218+ . replyWithFile (
219+ 200 ,
220+ path . join ( __dirname , '/fixtures/correios-alt-cep-05010000-found.json' )
221+ )
222+
202223 nock ( 'https://viacep.com.br' )
203224 . get ( '/ws/05010000/json/' )
204225 . replyWithFile (
@@ -242,6 +263,64 @@ describe('[unit] cep-promise for node', () => {
242263 path . join ( __dirname , '/fixtures/response-cep-05010000-found.xml' )
243264 )
244265
266+ nock ( 'https://buscacepinter.correios.com.br' )
267+ . post ( '/app/cep/carrega-cep.php' )
268+ . replyWithFile (
269+ 200 ,
270+ path . join ( __dirname , '/fixtures/correios-alt-cep-99999999-error.json' )
271+ )
272+
273+ nock ( 'https://viacep.com.br' )
274+ . get ( '/ws/05010000/json/' )
275+ . replyWithFile (
276+ 200 ,
277+ path . join ( __dirname , '/fixtures/viacep-cep-99999999-error.json' )
278+ )
279+
280+ nock ( 'https://cep.widenet.host' )
281+ . get ( '/busca-cep/api/cep/05010000.json' )
282+ . replyWithFile (
283+ 200 ,
284+ path . join ( __dirname , '/fixtures/widenet-cep-99999999-error.json' )
285+ )
286+
287+ nock ( 'https://brasilapi.com.br/' )
288+ . get ( '/api/cep/v1/99999999' )
289+ . replyWithFile (
290+ 404 ,
291+ path . join ( __dirname , '/fixtures/brasilapi-cep-99999999-error.json' )
292+ )
293+
294+
295+ return cep ( '05010000' )
296+ . then ( address => expect ( address ) . to . deep . equal ( {
297+ cep : '05010000' ,
298+ state : 'SP' ,
299+ city : 'São Paulo' ,
300+ neighborhood : 'Perdizes' ,
301+ street : 'Rua Caiubi' ,
302+ service : 'correios'
303+ } )
304+ )
305+ } )
306+ } )
307+
308+ describe ( 'Should succeed only with correios-alt service' , ( ) => {
309+ it ( 'should fulfill with correct address' , ( ) => {
310+ nock ( 'https://apps.correios.com.br' )
311+ . post ( '/SigepMasterJPA/AtendeClienteService/AtendeCliente' )
312+ . replyWithFile (
313+ 500 ,
314+ path . join ( __dirname , '/fixtures/response-unknown-format.xml' )
315+ )
316+
317+ nock ( 'https://buscacepinter.correios.com.br' )
318+ . post ( '/app/cep/carrega-cep.php' )
319+ . replyWithFile (
320+ 200 ,
321+ path . join ( __dirname , '/fixtures/correios-alt-cep-05010000-found.json' )
322+ )
323+
245324 nock ( 'https://viacep.com.br' )
246325 . get ( '/ws/05010000/json/' )
247326 . replyWithFile (
@@ -271,7 +350,7 @@ describe('[unit] cep-promise for node', () => {
271350 city : 'São Paulo' ,
272351 neighborhood : 'Perdizes' ,
273352 street : 'Rua Caiubi' ,
274- service : 'correios'
353+ service : 'correios-alt '
275354 } )
276355 )
277356 } )
@@ -286,6 +365,13 @@ describe('[unit] cep-promise for node', () => {
286365 path . join ( __dirname , '/fixtures/response-unknown-format.xml' )
287366 )
288367
368+ nock ( 'https://buscacepinter.correios.com.br' )
369+ . post ( '/app/cep/carrega-cep.php' )
370+ . replyWithFile (
371+ 200 ,
372+ path . join ( __dirname , '/fixtures/correios-alt-cep-99999999-error.json' )
373+ )
374+
289375 nock ( 'https://viacep.com.br' )
290376 . get ( '/ws/05010000/json/' )
291377 . replyWithFile (
@@ -329,6 +415,13 @@ describe('[unit] cep-promise for node', () => {
329415 path . join ( __dirname , '/fixtures/response-unknown-format.xml' )
330416 )
331417
418+ nock ( 'https://buscacepinter.correios.com.br' )
419+ . post ( '/app/cep/carrega-cep.php' )
420+ . replyWithFile (
421+ 200 ,
422+ path . join ( __dirname , '/fixtures/correios-alt-cep-99999999-error.json' )
423+ )
424+
332425 nock ( 'https://viacep.com.br' )
333426 . get ( '/ws/05010000/json/' )
334427 . replyWithFile (
@@ -371,6 +464,13 @@ describe('[unit] cep-promise for node', () => {
371464 path . join ( __dirname , '/fixtures/response-unknown-format.xml' )
372465 )
373466
467+ nock ( 'https://buscacepinter.correios.com.br' )
468+ . post ( '/app/cep/carrega-cep.php' )
469+ . replyWithFile (
470+ 200 ,
471+ path . join ( __dirname , '/fixtures/correios-alt-cep-99999999-error.json' )
472+ )
473+
374474 nock ( 'https://viacep.com.br' )
375475 . get ( '/ws/05010000/json/' )
376476 . replyWithFile (
@@ -413,6 +513,13 @@ describe('[unit] cep-promise for node', () => {
413513 path . join ( __dirname , '/fixtures/response-bad-xml.xml' )
414514 )
415515
516+ nock ( 'https://buscacepinter.correios.com.br' )
517+ . post ( '/app/cep/carrega-cep.php' )
518+ . replyWithFile (
519+ 200 ,
520+ path . join ( __dirname , '/fixtures/correios-alt-cep-05010000-found.json' )
521+ )
522+
416523 nock ( 'https://viacep.com.br' )
417524 . get ( '/ws/05010000/json/' )
418525 . replyWithFile (
@@ -454,6 +561,13 @@ describe('[unit] cep-promise for node', () => {
454561 'getaddrinfo ENOTFOUND apps.correios.com.br apps.correios.com.br:443'
455562 )
456563
564+ nock ( 'https://buscacepinter.correios.com.br' )
565+ . post ( '/app/cep/carrega-cep.php' )
566+ . replyWithFile (
567+ 200 ,
568+ path . join ( __dirname , '/fixtures/correios-alt-cep-05010000-found.json' )
569+ )
570+
457571 nock ( 'https://viacep.com.br' )
458572 . get ( '/ws/05010000/json/' )
459573 . replyWithFile (
@@ -496,6 +610,13 @@ describe('[unit] cep-promise for node', () => {
496610 path . join ( __dirname , '/fixtures/response-cep-not-found.xml' )
497611 )
498612
613+ nock ( 'https://buscacepinter.correios.com.br' )
614+ . post ( '/app/cep/carrega-cep.php' )
615+ . replyWithFile (
616+ 200 ,
617+ path . join ( __dirname , '/fixtures/correios-alt-cep-99999999-error.json' )
618+ )
619+
499620 nock ( 'https://viacep.com.br' )
500621 . get ( '/ws/99999999/json/' )
501622 . replyWithFile (
@@ -529,6 +650,10 @@ describe('[unit] cep-promise for node', () => {
529650 message : 'CEP NAO ENCONTRADO' ,
530651 service : 'correios'
531652 } ,
653+ {
654+ message : 'CEP não encontrado na base dos Correios.' ,
655+ service : 'correios-alt'
656+ } ,
532657 {
533658 message : 'CEP não encontrado na base do ViaCEP.' ,
534659 service : 'viacep'
@@ -571,6 +696,10 @@ describe('[unit] cep-promise for node', () => {
571696 'getaddrinfo ENOTFOUND apps.correios.com.br apps.correios.com.br:443'
572697 )
573698
699+ nock ( 'https://buscacepinter.correios.com.br' )
700+ . post ( '/app/cep/carrega-cep.php' )
701+ . reply ( 400 , '<h2>Bad Request (400)</h2>' )
702+
574703 nock ( 'https://viacep.com.br' )
575704 . get ( '/ws/05010000/json/' )
576705 . reply ( 400 , '<h2>Bad Request (400)</h2>' )
@@ -595,6 +724,10 @@ describe('[unit] cep-promise for node', () => {
595724 message : 'Erro ao se conectar com o serviço dos Correios.' ,
596725 service : 'correios'
597726 } ,
727+ {
728+ message : 'Erro ao se conectar com o serviço dos Correios Alt.' ,
729+ service : 'correios-alt'
730+ } ,
598731 {
599732 message : 'Erro ao se conectar com o serviço ViaCEP.' ,
600733 service : 'viacep'
@@ -623,6 +756,10 @@ describe('[unit] cep-promise for node', () => {
623756 path . join ( __dirname , '/fixtures/response-bad-xml.xml' )
624757 )
625758
759+ nock ( 'https://buscacepinter.correios.com.br' )
760+ . post ( '/app/cep/carrega-cep.php' )
761+ . reply ( 200 , { erro :true } )
762+
626763 nock ( 'https://viacep.com.br' )
627764 . get ( '/ws/05010000/json/' )
628765 . reply ( 400 , '<h2>Bad Request (400)</h2>' )
@@ -647,6 +784,10 @@ describe('[unit] cep-promise for node', () => {
647784 message : 'Não foi possível interpretar o XML de resposta.' ,
648785 service : 'correios'
649786 } ,
787+ {
788+ message : 'CEP não encontrado na base dos Correios.' ,
789+ service : 'correios-alt'
790+ } ,
650791 {
651792 message : 'Erro ao se conectar com o serviço ViaCEP.' ,
652793 service : 'viacep'
@@ -674,6 +815,10 @@ describe('[unit] cep-promise for node', () => {
674815 'getaddrinfo ENOTFOUND apps.correios.com.br apps.correios.com.br:443'
675816 )
676817
818+ nock ( 'https://buscacepinter.correios.com.br' )
819+ . post ( '/app/cep/carrega-cep.php' )
820+ . reply ( 200 , { erro :true } )
821+
677822 nock ( 'https://viacep.com.br' )
678823 . get ( '/ws/05010000/json/' )
679824 . replyWithError (
@@ -704,6 +849,10 @@ describe('[unit] cep-promise for node', () => {
704849 message : 'Erro ao se conectar com o serviço dos Correios.' ,
705850 service : 'correios'
706851 } ,
852+ {
853+ message : 'CEP não encontrado na base dos Correios.' ,
854+ service : 'correios-alt'
855+ } ,
707856 {
708857 message : 'Erro ao se conectar com o serviço ViaCEP.' ,
709858 service : 'viacep'
0 commit comments