diff --git a/README.md b/README.md index 25d7e90..04e6861 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ Teste e aprenda aqu Por ser multifornecedor, a biblioteca irá resolver a Promise com o fornecedor que **mais rápido** lhe responder. ``` js -import cep from 'cep-promise' +import cepPromise from 'cep-promise' -cep('05010000') +cepPromise('05010000') .then(console.log) // { @@ -68,10 +68,10 @@ cep('05010000') Em muitos sistemas o CEP é utilizado erroneamente como um Inteiro (e com isto cortando todos os zeros à esquerda). Caso este seja o seu caso, não há problema, pois a biblioteca irá preencher os caracteres faltantes na String, por exemplo: ``` js -import cep from 'cep-promise' +import cepPromise from 'cep-promise' // enviando sem ter um zero à esquerda do CEP "05010000" -cep(5010000) +cepPromise(5010000) .then(console.log) // { @@ -88,9 +88,9 @@ cep(5010000) Neste caso será retornado um `"service_error"` e por ser multifornecedor, a biblioteca irá rejeitar a Promise apenas quando tiver a resposta negativa de todos os fornecedores. ``` js -import cep from 'cep-promise' +import cepPromise from 'cep-promise' -cep('99999999') +cepPromise('99999999') .catch(console.log) // { @@ -116,9 +116,9 @@ cep('99999999') Neste caso será retornado um `"validation_error"` e a biblioteca irá rejeitar imediatamente a Promise, sem chegar a consultar nenhum fornecedor. ``` js -import cep from 'cep-promise' +import cepPromise from 'cep-promise' -cep('123456789123456789') +cepPromise('123456789123456789') .catch(console.log) // { @@ -157,7 +157,7 @@ $ bower install --save cep-promise ``` ts import * as cep from 'cep-promise' -cep('05010000') +cepPromise('05010000') .then(console.log) ``` diff --git a/dist/cep-promise-browser.js b/dist/cep-promise-browser.js index 9a1e5fa..788e141 100644 --- a/dist/cep-promise-browser.js +++ b/dist/cep-promise-browser.js @@ -78,7 +78,7 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options) return new Promise(function (resolve, reject) { var request = new XMLHttpRequest(); - request.open(options.method || 'get', url, true); + request.open(options.method || 'get', url); for (var i in options.headers) { request.setRequestHeader(i, options.headers[i]); @@ -92,7 +92,7 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options) request.onerror = reject; - request.send(options.body || null); + request.send(options.body); function response() { var _keys = [], @@ -100,7 +100,7 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options) headers = {}, header; - request.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function (m, key, value) { + request.getAllResponseHeaders().replace(/^(.*?):\s*([\s\S]*?)$/gm, function (m, key, value) { _keys.push(key = key.toLowerCase()); all.push([key, value]); header = headers[key]; @@ -108,7 +108,7 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options) }); return { - ok: (request.status / 100 | 0) == 2, // 200-299 + ok: (request.status / 200 | 0) == 1, // 200-299 status: request.status, statusText: request.statusText, url: request.responseURL, diff --git a/dist/cep-promise-browser.min.js b/dist/cep-promise-browser.min.js index 8677ab1..199f2b7 100644 --- a/dist/cep-promise-browser.min.js +++ b/dist/cep-promise-browser.min.js @@ -1 +1 @@ -!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.cep=r()}(this,function(){"use strict";function e(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",a=s+"http://www.cepaberto.com/api/v2/ceps.json?cep="+e,i={method:"GET",mode:"cors",headers:{"content-type":"application/json;charset=utf-8",Authorization:"Token token="+V}};return H(a,i).then(r).then(t).then(o).catch(n)}function r(e){if(e.ok)return e.json();throw Error("Erro ao se conectar com o serviço Cep Aberto.")}function t(e){if(!Object.keys(e).length)throw new Error("CEP não encontrado na base do Cep Aberto.");return e}function o(e){return{cep:e.cep,state:e.estado,city:e.cidade,neighborhood:e.bairro,street:e.logradouro}}function n(e){var r=new M({message:e.message,service:"cepaberto"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço Cep Aberto."),r}function s(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=r+"https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente",o={method:"POST",body:'\n\n \n \n \n '+e+"\n \n \n",headers:{"Content-Type":"text/xml;charset=UTF-8","cache-control":"no-cache"}};return H(t,o).then(a).catch(p)}function a(e){return e.ok?e.text().then(i).then(f):e.text().then(c).then(u)}function i(e){try{var r=e.replace(/\r?\n|\r/g,"").match(/(.*)<\/return>/)[0]||"",t=r.replace("","").replace("",""),o=t.split(/");return t.length>1&&t[1].length&&(e[t[0]]=t[1]),e},{});return o}catch(e){throw new Error("Não foi possível interpretar o XML de resposta.")}}function c(e){try{var r=e.match(/(.*)<\/faultstring>/)[0]||"",t=r.replace("","").replace("","");return t}catch(e){throw new Error("Não foi possível interpretar o XML de resposta.")}}function u(e){throw new Error(e)}function f(e){return{cep:e.cep,state:e.uf,city:e.cidade,neighborhood:e.bairro,street:e.end}}function p(e){var r=new M({message:e.message,service:"correios"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço dos Correios."),r}function h(e){var r="https://viacep.com.br/ws/"+e+"/json/",t={method:"GET",mode:"cors",headers:{"content-type":"application/json;charset=utf-8"}};return H(r,t).then(l).then(d).then(m).catch(v)}function l(e){if(e.ok)return e.json();throw Error("Erro ao se conectar com o serviço ViaCEP.")}function d(e){if(e.erro===!0)throw new Error("CEP não encontrado na base do ViaCEP.");return e}function m(e){return{cep:e.cep.replace("-",""),state:e.uf,city:e.localidade,neighborhood:e.bairro,street:e.logradouro}}function v(e){var r=new M({message:e.message,service:"viacep"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço ViaCEP."),r}function y(){return"undefined"!=typeof window}function g(e){return function(r){return e(r,N)}}function w(e){return Promise.resolve(e).then(b).then(E).then(C).then(P).then(x).catch(_).catch(j)}function b(e){var r="undefined"==typeof e?"undefined":S(e);if("number"===r||"string"===r)return e;throw new L({message:"Erro ao inicializar a instância do CepPromise.",type:"validation_error",errors:[{message:"Você deve chamar o construtor utilizando uma String ou um Number.",service:"cep_validation"}]})}function E(e){return e.toString().replace(/\D+/g,"")}function P(e){return"0".repeat(J-e.length)+e}function C(e){if(e.length<=J)return e;throw new L({message:"CEP deve conter exatamente "+J+" caracteres.",type:"validation_error",errors:[{message:"CEP informado possui mais do que "+J+" caracteres.",service:"cep_validation"}]})}function x(e){return Promise.any([q(e),B(e),X(e)])}function _(e){if(void 0!==e.length)throw new L({message:"Todos os serviços de CEP retornaram erro.",type:"service_error",errors:e});throw e}function j(e){var r=e.message,t=e.type,o=e.errors;throw new L({message:r,type:t,errors:o})}var S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},O=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},T=function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)},A=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r},k=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r0&&void 0!==arguments[0]?arguments[0]:{},t=e.message,o=e.type,n=e.errors;O(this,r);var s=A(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return s.name="CepPromiseError",s.message=t,s.type=o,s.errors=n,s}return T(r,e),r}(Error),R="function"==typeof fetch?fetch.bind():function(e,r){return r=r||{},new Promise(function(t,o){function n(){var e,r=[],t=[],o={};return s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(n,s,a){r.push(s=s.toLowerCase()),t.push([s,a]),e=o[s],o[s]=e?e+","+a:a}),{ok:2==(s.status/100|0),status:s.status,statusText:s.statusText,url:s.responseURL,clone:n,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},headers:{keys:function(){return r},entries:function(){return t},get:function(e){return o[e.toLowerCase()]},has:function(e){return e.toLowerCase()in o}}}}var s=new XMLHttpRequest;s.open(r.method||"get",e,!0);for(var a in r.headers)s.setRequestHeader(a,r.headers[a]);s.withCredentials="include"==r.credentials,s.onload=function(){t(n())},s.onerror=o,s.send(r.body||null)})},z=Object.freeze({default:R}),F=z&&R||z,H=window.fetch||(window.fetch=F.default||F),M=function(e){function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.message,o=e.service;O(this,r);var n=A(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return n.name="ServiceError",n.message=t,n.service=o,n}return T(r,e),r}(Error),N="https://proxier.now.sh/",V="37d718d2984e6452584a76d3d59d3a26",q=y()?g(e):e,B=y()?g(s):s,X=h,G=function(e){return new Promise(function(r,t){return Promise.resolve(e).then(t,r)})};Promise.any=function(e){return G(Promise.all([].concat(k(e)).map(G)))};var J=8;return w}); \ No newline at end of file +!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.cep=r()}(this,function(){"use strict";function e(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",a=s+"http://www.cepaberto.com/api/v2/ceps.json?cep="+e,i={method:"GET",mode:"cors",headers:{"content-type":"application/json;charset=utf-8",Authorization:"Token token="+V}};return H(a,i).then(r).then(t).then(o).catch(n)}function r(e){if(e.ok)return e.json();throw Error("Erro ao se conectar com o serviço Cep Aberto.")}function t(e){if(!Object.keys(e).length)throw new Error("CEP não encontrado na base do Cep Aberto.");return e}function o(e){return{cep:e.cep,state:e.estado,city:e.cidade,neighborhood:e.bairro,street:e.logradouro}}function n(e){var r=new M({message:e.message,service:"cepaberto"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço Cep Aberto."),r}function s(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=r+"https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente",o={method:"POST",body:'\n\n \n \n \n '+e+"\n \n \n",headers:{"Content-Type":"text/xml;charset=UTF-8","cache-control":"no-cache"}};return H(t,o).then(a).catch(p)}function a(e){return e.ok?e.text().then(i).then(f):e.text().then(c).then(u)}function i(e){try{var r=e.replace(/\r?\n|\r/g,"").match(/(.*)<\/return>/)[0]||"",t=r.replace("","").replace("",""),o=t.split(/");return t.length>1&&t[1].length&&(e[t[0]]=t[1]),e},{});return o}catch(e){throw new Error("Não foi possível interpretar o XML de resposta.")}}function c(e){try{var r=e.match(/(.*)<\/faultstring>/)[0]||"",t=r.replace("","").replace("","");return t}catch(e){throw new Error("Não foi possível interpretar o XML de resposta.")}}function u(e){throw new Error(e)}function f(e){return{cep:e.cep,state:e.uf,city:e.cidade,neighborhood:e.bairro,street:e.end}}function p(e){var r=new M({message:e.message,service:"correios"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço dos Correios."),r}function h(e){var r="https://viacep.com.br/ws/"+e+"/json/",t={method:"GET",mode:"cors",headers:{"content-type":"application/json;charset=utf-8"}};return H(r,t).then(l).then(d).then(m).catch(v)}function l(e){if(e.ok)return e.json();throw Error("Erro ao se conectar com o serviço ViaCEP.")}function d(e){if(e.erro===!0)throw new Error("CEP não encontrado na base do ViaCEP.");return e}function m(e){return{cep:e.cep.replace("-",""),state:e.uf,city:e.localidade,neighborhood:e.bairro,street:e.logradouro}}function v(e){var r=new M({message:e.message,service:"viacep"});throw"FetchError"===e.name&&(r.message="Erro ao se conectar com o serviço ViaCEP."),r}function y(){return"undefined"!=typeof window}function g(e){return function(r){return e(r,N)}}function w(e){return Promise.resolve(e).then(b).then(E).then(C).then(P).then(x).catch(_).catch(j)}function b(e){var r="undefined"==typeof e?"undefined":S(e);if("number"===r||"string"===r)return e;throw new L({message:"Erro ao inicializar a instância do CepPromise.",type:"validation_error",errors:[{message:"Você deve chamar o construtor utilizando uma String ou um Number.",service:"cep_validation"}]})}function E(e){return e.toString().replace(/\D+/g,"")}function P(e){return"0".repeat(J-e.length)+e}function C(e){if(e.length<=J)return e;throw new L({message:"CEP deve conter exatamente "+J+" caracteres.",type:"validation_error",errors:[{message:"CEP informado possui mais do que "+J+" caracteres.",service:"cep_validation"}]})}function x(e){return Promise.any([q(e),B(e),X(e)])}function _(e){if(void 0!==e.length)throw new L({message:"Todos os serviços de CEP retornaram erro.",type:"service_error",errors:e});throw e}function j(e){var r=e.message,t=e.type,o=e.errors;throw new L({message:r,type:t,errors:o})}var S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},O=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},T=function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)},A=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r},k=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r0&&void 0!==arguments[0]?arguments[0]:{},t=e.message,o=e.type,n=e.errors;O(this,r);var s=A(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return s.name="CepPromiseError",s.message=t,s.type=o,s.errors=n,s}return T(r,e),r}(Error),R="function"==typeof fetch?fetch.bind():function(e,r){return r=r||{},new Promise(function(t,o){function n(){var e,r=[],t=[],o={};return s.getAllResponseHeaders().replace(/^(.*?):\s*([\s\S]*?)$/gm,function(n,s,a){r.push(s=s.toLowerCase()),t.push([s,a]),e=o[s],o[s]=e?e+","+a:a}),{ok:1==(s.status/200|0),status:s.status,statusText:s.statusText,url:s.responseURL,clone:n,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},headers:{keys:function(){return r},entries:function(){return t},get:function(e){return o[e.toLowerCase()]},has:function(e){return e.toLowerCase()in o}}}}var s=new XMLHttpRequest;s.open(r.method||"get",e);for(var a in r.headers)s.setRequestHeader(a,r.headers[a]);s.withCredentials="include"==r.credentials,s.onload=function(){t(n())},s.onerror=o,s.send(r.body)})},z=Object.freeze({default:R}),F=z&&R||z,H=window.fetch||(window.fetch=F.default||F),M=function(e){function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.message,o=e.service;O(this,r);var n=A(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return n.name="ServiceError",n.message=t,n.service=o,n}return T(r,e),r}(Error),N="https://proxier.now.sh/",V="37d718d2984e6452584a76d3d59d3a26",q=y()?g(e):e,B=y()?g(s):s,X=h,G=function(e){return new Promise(function(r,t){return Promise.resolve(e).then(t,r)})};Promise.any=function(e){return G(Promise.all([].concat(k(e)).map(G)))};var J=8;return w}); \ No newline at end of file diff --git a/package.json b/package.json index cc55a9b..5ef8c7e 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "zipcode", "zip", "promise", - "viacep" + "viacep", + "cepPromise" ], "homepage": "https://github.com/filipedeschamps/cep-promise", "devDependencies": { diff --git a/test/e2e/cep-promise.spec.js b/test/e2e/cep-promise.spec.js index e98e380..c69f544 100644 --- a/test/e2e/cep-promise.spec.js +++ b/test/e2e/cep-promise.spec.js @@ -4,7 +4,7 @@ import chai from 'chai' import chaiAsPromised from 'chai-as-promised' import chaiSubset from 'chai-subset' -import cep from '../../src/cep-promise.js' +import cepPromise from '../../src/cep-promise.js' import CepPromiseError from '../../src/errors/cep-promise.js' chai.use(chaiAsPromised) @@ -15,7 +15,7 @@ let expect = chai.expect describe('cep-promise (E2E)', () => { describe('when invoked with a valid "05010000" string', () => { it('should fulfill with correct address', () => { - return expect(cep('05010000')).to.eventually.deep.equal({ + return expect(cepPromise('05010000')).to.eventually.deep.equal({ cep: '05010000', state: 'SP', city: 'São Paulo', @@ -27,7 +27,7 @@ describe('cep-promise (E2E)', () => { describe('when invoked with a valid 5010000 number', () => { it('should fulfill with correct address', () => { - return expect(cep(5010000)).to.eventually.deep.equal({ + return expect(cepPromise(5010000)).to.eventually.deep.equal({ cep: '05010000', state: 'SP', city: 'São Paulo', @@ -39,7 +39,7 @@ describe('cep-promise (E2E)', () => { describe('when invoked with an inexistent "99999999" CEP', () => { it('should reject with "service_error"', () => { - return cep('99999999') + return cepPromise('99999999') .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError) @@ -61,7 +61,7 @@ describe('cep-promise (E2E)', () => { describe('when invoked with an invalid "123456789" CEP', () => { it('should reject with "validation_error"', () => { - return cep('123456789') + return cepPromise('123456789') .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError) diff --git a/test/unit/cep-promise.spec.js b/test/unit/cep-promise.spec.js index 5bb296f..04ddee9 100644 --- a/test/unit/cep-promise.spec.js +++ b/test/unit/cep-promise.spec.js @@ -6,7 +6,7 @@ import chaiSubset from 'chai-subset' import nock from 'nock' import path from 'path' -import cep from '../../src/cep-promise.js' +import cepPromise from '../../src/cep-promise.js' import CepPromiseError from '../../src/errors/cep-promise.js' chai.use(chaiAsPromised) @@ -17,7 +17,7 @@ let expect = chai.expect describe('cep-promise (unit)', () => { describe('when imported', () => { it('should return a Function', () => { - expect(cep).to.be.a('function') + expect(cepPromise).to.be.a('function') }) }) @@ -33,15 +33,15 @@ describe('cep-promise (unit)', () => { .get('/api/v2/ceps.json?cep=05010000') .replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json')) - const cepPromise = cep('05010000') - expect(cepPromise.then).to.be.a('function') - expect(cepPromise.catch).to.be.a('function') + const lib = cepPromise('05010000') + expect(lib.then).to.be.a('function') + expect(lib.catch).to.be.a('function') }) }) describe('when invoked without arguments', () => { it('should reject with "validation_error"', () => { - return cep() + return cepPromise() .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError) @@ -60,7 +60,7 @@ describe('cep-promise (unit)', () => { describe('when invoked with an Array', () => { it('should reject with "validation_error"', () => { - return cep([1, 2, 3]) + return cepPromise([1, 2, 3]) .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError) @@ -79,7 +79,7 @@ describe('cep-promise (unit)', () => { describe('when invoked with an Object', () => { it('should reject with "validation_error"', () => { - return cep({ nintendo: true, ps: false, xbox: false }) + return cepPromise({ nintendo: true, ps: false, xbox: false }) .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError) @@ -98,7 +98,7 @@ describe('cep-promise (unit)', () => { describe('when invoked with an Function', () => { it('should reject with "validation_error"', () => { - return cep(function zelda () { return 'link' }) + return cepPromise(function zelda () { return 'link' }) .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError) @@ -128,7 +128,7 @@ describe('cep-promise (unit)', () => { .get('/api/v2/ceps.json?cep=05010000') .replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json')) - return expect(cep('05010000')).to.eventually.deep.equal({ + return expect(cepPromise('05010000')).to.eventually.deep.equal({ cep: '05010000', state: 'SP', city: 'São Paulo', @@ -150,7 +150,7 @@ describe('cep-promise (unit)', () => { .get('/api/v2/ceps.json?cep=05010000') .replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json')) - return expect(cep(5010000)).to.eventually.deep.equal({ + return expect(cepPromise(5010000)).to.eventually.deep.equal({ cep: '05010000', state: 'SP', city: 'São Paulo', @@ -172,7 +172,7 @@ describe('cep-promise (unit)', () => { .get('/api/v2/ceps.json?cep=05010000') .replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-99999999-error.json')) - return expect(cep('5010000')).to.eventually.deep.equal({ + return expect(cepPromise('5010000')).to.eventually.deep.equal({ cep: '05010000', state: 'SP', city: 'São Paulo', @@ -193,8 +193,8 @@ describe('cep-promise (unit)', () => { nock('http://www.cepaberto.com') .get('/api/v2/ceps.json?cep=05010000') .replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-99999999-error.json')) - - return expect(cep('5010000')).to.eventually.deep.equal({ + + return expect(cepPromise('5010000')).to.eventually.deep.equal({ cep: '05010000', state: 'SP', city: 'São Paulo', @@ -215,8 +215,8 @@ describe('cep-promise (unit)', () => { nock('http://www.cepaberto.com') .get('/api/v2/ceps.json?cep=05010000') .replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json')) - - return expect(cep('5010000')).to.eventually.deep.equal({ + + return expect(cepPromise('5010000')).to.eventually.deep.equal({ cep: '05010000', state: 'SP', city: 'São Paulo', @@ -238,7 +238,7 @@ describe('cep-promise (unit)', () => { .get('/api/v2/ceps.json?cep=05010000') .replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json')) - return expect(cep('5010000')).to.eventually.deep.equal({ + return expect(cepPromise('5010000')).to.eventually.deep.equal({ cep: '05010000', state: 'SP', city: 'São Paulo', @@ -260,7 +260,7 @@ describe('cep-promise (unit)', () => { .get('/api/v2/ceps.json?cep=05010000') .replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json')) - return expect(cep('5010000')).to.eventually.deep.equal({ + return expect(cepPromise('5010000')).to.eventually.deep.equal({ cep: '05010000', state: 'SP', city: 'São Paulo', @@ -282,7 +282,7 @@ describe('cep-promise (unit)', () => { .get('/api/v2/ceps.json?cep=99999999') .replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-99999999-error.json')) - return cep('99999999') + return cepPromise('99999999') .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError) @@ -307,7 +307,7 @@ describe('cep-promise (unit)', () => { describe('when invoked with an invalid "123456789" CEP', () => { it('should reject with "validation_error"', () => { - return cep('123456789') + return cepPromise('123456789') .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError) @@ -336,7 +336,7 @@ describe('cep-promise (unit)', () => { .get('/api/v2/ceps.json?cep=05010000') .reply(400, '

Bad Request (400)

') - return cep('05010000') + return cepPromise('05010000') .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError) @@ -371,7 +371,7 @@ describe('cep-promise (unit)', () => { .get('/api/v2/ceps.json?cep=05010000') .reply(400, '

Bad Request (400)

') - return cep('05010000') + return cepPromise('05010000') .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError) @@ -406,7 +406,7 @@ describe('cep-promise (unit)', () => { .get('/api/v2/ceps.json?cep=05010000') .replyWithError('getaddrinfo ENOTFOUND apps.correios.com.br apps.correios.com.br:443') - return cep('05010000') + return cepPromise('05010000') .catch((error) => { return expect(error) .to.be.an.instanceOf(CepPromiseError)