Skip to content

Commit

Permalink
Merge pull request #267 from BrasilAPI/fix-correios-alt
Browse files Browse the repository at this point in the history
Atualiza o provedor correios-alt
  • Loading branch information
lucianopf authored Feb 21, 2024
2 parents 73133eb + 320fcfe commit e5ef7ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
8 changes: 5 additions & 3 deletions src/services/correios-alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ export default function fetchCorreiosAltAPIService(
cepWithLeftPad,
configurations
) {
const url = 'https://buscacepinter.correios.com.br/app/cep/carrega-cep.php'
const url = 'https://buscacepinter.correios.com.br/app/endereco/carrega-cep-endereco.php'
const options = {
method: 'POST',
mode: 'cors',
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Referer': 'https://buscacepinter.correios.com.br/app/endereco/index.php',
'Referrer-Policy': 'strict-origin-when-cross-origin'
},
body: `cep=${cepWithLeftPad}`,
body: `endereco=${cepWithLeftPad}&tipoCEP=ALL`,
timeout: configurations.timeout || 30000
}

Expand Down
28 changes: 14 additions & 14 deletions test/unit/cep-promise-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -264,7 +264,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-99999999-error.json')
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -366,7 +366,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-99999999-error.json')
Expand Down Expand Up @@ -416,7 +416,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-99999999-error.json')
Expand Down Expand Up @@ -465,7 +465,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-99999999-error.json')
Expand Down Expand Up @@ -514,7 +514,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -562,7 +562,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -611,7 +611,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-99999999-error.json')
Expand Down Expand Up @@ -697,7 +697,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.reply(400, '<h2>Bad Request (400)</h2>')

nock('https://viacep.com.br')
Expand Down Expand Up @@ -757,7 +757,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.reply(200, {erro:true})

nock('https://viacep.com.br')
Expand Down Expand Up @@ -816,7 +816,7 @@ describe('[unit] cep-promise for node', () => {
)

nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.reply(200, {erro:true})

nock('https://viacep.com.br')
Expand Down
14 changes: 7 additions & 7 deletions test/unit/cep-promise-providers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('when invoked with providers parameter', () => {
)

const correiosAltMock = nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('when invoked with providers parameter', () => {
)

const correiosAltMock = nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('when invoked with providers parameter', () => {
)

const correiosAltMock = nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('when invoked with providers parameter', () => {
)

const correiosAltMock = nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -326,7 +326,7 @@ describe('when invoked with providers parameter', () => {
)

const correiosAltMock = nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -383,7 +383,7 @@ describe('when invoked with providers parameter', () => {
)

const correiosAltMock = nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down Expand Up @@ -432,7 +432,7 @@ describe('when invoked with providers parameter', () => {
)

const correiosAltMock = nock('https://buscacepinter.correios.com.br')
.post('/app/cep/carrega-cep.php')
.post('/app/endereco/carrega-cep-endereco.php')
.replyWithFile(
200,
path.join(__dirname, '/fixtures/correios-alt-cep-05010000-found.json')
Expand Down

0 comments on commit e5ef7ba

Please sign in to comment.