Skip to content

Commit

Permalink
Merge pull request #256 from stone-ton/master
Browse files Browse the repository at this point in the history
Alteração no endereço público da apicep.com
  • Loading branch information
murilohns authored Feb 7, 2023
2 parents 52d3bc7 + 455e93b commit c4502e6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 58 deletions.
5 changes: 3 additions & 2 deletions src/services/widenet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import fetch from 'node-fetch'
import ServiceError from '../errors/service.js'

export default function fetchWideNetService(cepWithLeftPad, configurations) {
const url = `https://ws.apicep.com/busca-cep/api/cep/${cepWithLeftPad}.json`
const cepWithDash = `${cepWithLeftPad.slice(0, 5)}-${cepWithLeftPad.slice(5)}`
const url = `https://cdn.apicep.com/file/apicep/${cepWithDash}.json`
const options = {
method: 'GET',
mode: 'cors',
headers: {
'content-type': 'application/json;charset=utf-8'
accept: 'application/json'
},
timeout: configurations.timeout || 30000
}
Expand Down
32 changes: 16 additions & 16 deletions test/unit/cep-promise-browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('[unit] cep-promise for browser', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -151,8 +151,8 @@ describe('[unit] cep-promise for browser', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -187,8 +187,8 @@ describe('[unit] cep-promise for browser', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -223,8 +223,8 @@ describe('[unit] cep-promise for browser', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-99999999-error.json')
Expand Down Expand Up @@ -259,8 +259,8 @@ describe('[unit] cep-promise for browser', () => {
path.join(__dirname, '/fixtures/viacep-cep-99999999-error.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -294,8 +294,8 @@ describe('[unit] cep-promise for browser', () => {
path.join(__dirname, '/fixtures/viacep-cep-99999999-error.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-99999999-error.json')
Expand Down Expand Up @@ -329,8 +329,8 @@ describe('[unit] cep-promise for browser', () => {
path.join(__dirname, '/fixtures/viacep-cep-99999999-error.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/99999999.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/99999-999.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-99999999-error.json')
Expand Down Expand Up @@ -391,8 +391,8 @@ describe('[unit] cep-promise for browser', () => {
.get('/ws/05010000/json/')
.reply(400, '<h2>Bad Request (400)</h2>')

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.reply(400, '<h2>Bad Request (400)</h2>')

nock('https://brasilapi.com.br/')
Expand Down
54 changes: 27 additions & 27 deletions test/unit/cep-promise-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ describe('[unit] cep-promise for node', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -177,8 +177,8 @@ describe('[unit] cep-promise for node', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -227,8 +227,8 @@ describe('[unit] cep-promise for node', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -278,7 +278,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://cep.widenet.host')
.get('/busca-cep/api/cep/05010000.json')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-99999999-error.json')
Expand Down Expand Up @@ -328,8 +328,8 @@ describe('[unit] cep-promise for node', () => {
path.join(__dirname, '/fixtures/viacep-cep-99999999-error.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-99999999-error.json')
Expand Down Expand Up @@ -379,8 +379,8 @@ describe('[unit] cep-promise for node', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-99999999-error.json')
Expand Down Expand Up @@ -429,8 +429,8 @@ describe('[unit] cep-promise for node', () => {
path.join(__dirname, '/fixtures/viacep-cep-99999999-error.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -478,8 +478,8 @@ describe('[unit] cep-promise for node', () => {
path.join(__dirname, '/fixtures/viacep-cep-99999999-error.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-99999999-error.json')
Expand Down Expand Up @@ -527,8 +527,8 @@ describe('[unit] cep-promise for node', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -575,8 +575,8 @@ describe('[unit] cep-promise for node', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -624,8 +624,8 @@ describe('[unit] cep-promise for node', () => {
path.join(__dirname, '/fixtures/viacep-cep-99999999-error.json')
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/99999999.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/99999-999.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-99999999-error.json')
Expand Down Expand Up @@ -704,8 +704,8 @@ describe('[unit] cep-promise for node', () => {
.get('/ws/05010000/json/')
.reply(400, '<h2>Bad Request (400)</h2>')

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.reply(400, '<h2>Bad Request (400)</h2>')

nock('https://brasilapi.com.br/')
Expand Down Expand Up @@ -764,8 +764,8 @@ describe('[unit] cep-promise for node', () => {
.get('/ws/05010000/json/')
.reply(400, '<h2>Bad Request (400)</h2>')

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.reply(400, '<h2>Bad Request (400)</h2>')

nock('https://brasilapi.com.br/')
Expand Down Expand Up @@ -825,8 +825,8 @@ describe('[unit] cep-promise for node', () => {
'getaddrinfo ENOTFOUND apps.correios.com.br apps.correios.com.br:443'
)

nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithError(
'getaddrinfo ENOTFOUND apps.correios.com.br apps.correios.com.br:443'
)
Expand Down
26 changes: 13 additions & 13 deletions test/unit/cep-promise-providers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ describe('when invoked with providers parameter', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

const wideNetMock = nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
const wideNetMock = nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -192,8 +192,8 @@ describe('when invoked with providers parameter', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

const wideNetMock = nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
const wideNetMock = nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -241,8 +241,8 @@ describe('when invoked with providers parameter', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

const wideNetMock = nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
const wideNetMock = nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('when invoked with providers parameter', () => {
)

const wideNetMock = nock('https://cep.widenet.host')
.get('/busca-cep/api/cep/05010000.json')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -339,8 +339,8 @@ describe('when invoked with providers parameter', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

const wideNetMock = nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
const wideNetMock = nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -396,8 +396,8 @@ describe('when invoked with providers parameter', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

const wideNetMock = nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
const wideNetMock = nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down Expand Up @@ -445,8 +445,8 @@ describe('when invoked with providers parameter', () => {
path.join(__dirname, '/fixtures/viacep-cep-05010000-found.json')
)

const wideNetMock = nock('https://ws.apicep.com')
.get('/busca-cep/api/cep/05010000.json')
const wideNetMock = nock('https://cdn.apicep.com')
.get('/file/apicep/05010-000.json')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/widenet-cep-05010000-found.json')
Expand Down

0 comments on commit c4502e6

Please sign in to comment.