Skip to content

Commit 57ce5c4

Browse files
lucianopffilipedeschamps
authored andcommitted
(refactor) String as Template Strings - ES6 (BrasilAPI#67)
* Refactor code so strings that has variables now are used as template strings as described in es6 * debugging build error * changing tests description
1 parent 65cdbbd commit 57ce5c4

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/cep-promise.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function (cepRawValue) {
3030
message: 'Erro ao inicializar a instância do CepPromise.',
3131
type: 'validation_error',
3232
errors: [{
33-
message: 'Você deve chamar o construtor utilizando uma String ou Number.',
33+
message: 'Você deve chamar o construtor utilizando uma String ou um Number.',
3434
service: 'cep_validation'
3535
}]
3636
})
@@ -50,10 +50,10 @@ export default function (cepRawValue) {
5050
}
5151

5252
throw new CepPromiseError({
53-
message: 'CEP deve conter exatamente 8 caracteres.',
53+
message: `CEP deve conter exatamente ${CEP_SIZE} caracteres.`,
5454
type: 'validation_error',
5555
errors: [{
56-
message: 'CEP informado possui mais do que 8 caracteres.',
56+
message: `CEP informado possui mais do que ${CEP_SIZE} caracteres.`,
5757
service: 'cep_validation'
5858
}]
5959
})

src/services/correios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function fetchCorreiosService (cepWithLeftPad) {
1313
const url = 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente'
1414
const options = {
1515
method: 'POST',
16-
body: '<?xml version="1.0"?>\n<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">\n <soapenv:Header />\n <soapenv:Body>\n <cli:consultaCEP>\n <cep>' + cepWithLeftPad + '</cep>\n </cli:consultaCEP>\n </soapenv:Body>\n</soapenv:Envelope>',
16+
body: `<?xml version="1.0"?>\n<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">\n <soapenv:Header />\n <soapenv:Body>\n <cli:consultaCEP>\n <cep>${cepWithLeftPad}</cep>\n </cli:consultaCEP>\n </soapenv:Body>\n</soapenv:Envelope>`,
1717
mode: 'no-cors',
1818
headers: {
1919
'Content-Type': 'text/xml; charset=utf-8',

src/services/viacep.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ServiceError from '../errors/service.js'
66
function fetchViaCepService (cepWithLeftPad) {
77

88
return new Promise((resolve, reject) => {
9-
const url = 'https://viacep.com.br/ws/' + cepWithLeftPad + '/json/'
9+
const url = `https://viacep.com.br/ws/${cepWithLeftPad}/json/`
1010
const options = {
1111
method: 'GET',
1212
mode: 'cors',

test/unit/cep-promise.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('cep-promise (unit)', () => {
4646
message: 'Erro ao inicializar a instância do CepPromise.',
4747
type: 'validation_error',
4848
errors: [{
49-
message: 'Você deve chamar o construtor utilizando uma String ou Number.',
49+
message: 'Você deve chamar o construtor utilizando uma String ou um Number.',
5050
service: 'cep_validation'
5151
}]
5252
})
@@ -64,7 +64,7 @@ describe('cep-promise (unit)', () => {
6464
message: 'Erro ao inicializar a instância do CepPromise.',
6565
type: 'validation_error',
6666
errors: [{
67-
message: 'Você deve chamar o construtor utilizando uma String ou Number.',
67+
message: 'Você deve chamar o construtor utilizando uma String ou um Number.',
6868
service: 'cep_validation'
6969
}]
7070
})
@@ -82,7 +82,7 @@ describe('cep-promise (unit)', () => {
8282
message: 'Erro ao inicializar a instância do CepPromise.',
8383
type: 'validation_error',
8484
errors: [{
85-
message: 'Você deve chamar o construtor utilizando uma String ou Number.',
85+
message: 'Você deve chamar o construtor utilizando uma String ou um Number.',
8686
service: 'cep_validation'
8787
}]
8888
})
@@ -100,7 +100,7 @@ describe('cep-promise (unit)', () => {
100100
message: 'Erro ao inicializar a instância do CepPromise.',
101101
type: 'validation_error',
102102
errors: [{
103-
message: 'Você deve chamar o construtor utilizando uma String ou Number.',
103+
message: 'Você deve chamar o construtor utilizando uma String ou um Number.',
104104
service: 'cep_validation'
105105
}]
106106
})

0 commit comments

Comments
 (0)