Skip to content

Commit ad22067

Browse files
committed
Chore: Change code samples following the Runkit pattern
1 parent 69aa725 commit ad22067

File tree

4 files changed

+37
-36
lines changed

4 files changed

+37
-36
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ Teste e aprenda <a href="https://npm.runkit.com/cep-promise" target="_blank">aqu
4848
Por ser multifornecedor, a biblioteca irá resolver a Promise com o fornecedor que **mais rápido** lhe responder.
4949

5050
``` js
51-
import cep from 'cep-promise'
51+
import cepPromise from 'cep-promise'
5252

53-
cep('05010000')
53+
cepPromise('05010000')
5454
.then(console.log)
5555

5656
// {
@@ -68,10 +68,10 @@ cep('05010000')
6868
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:
6969

7070
``` js
71-
import cep from 'cep-promise'
71+
import cepPromise from 'cep-promise'
7272

7373
// enviando sem ter um zero à esquerda do CEP "05010000"
74-
cep(5010000)
74+
cepPromise(5010000)
7575
.then(console.log)
7676

7777
// {
@@ -88,9 +88,9 @@ cep(5010000)
8888
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.
8989

9090
``` js
91-
import cep from 'cep-promise'
91+
import cepPromise from 'cep-promise'
9292

93-
cep('99999999')
93+
cepPromise('99999999')
9494
.catch(console.log)
9595

9696
// {
@@ -116,9 +116,9 @@ cep('99999999')
116116
Neste caso será retornado um `"validation_error"` e a biblioteca irá rejeitar imediatamente a Promise, sem chegar a consultar nenhum fornecedor.
117117

118118
``` js
119-
import cep from 'cep-promise'
119+
import cepPromise from 'cep-promise'
120120

121-
cep('123456789123456789')
121+
cepPromise('123456789123456789')
122122
.catch(console.log)
123123

124124
// {
@@ -157,7 +157,7 @@ $ bower install --save cep-promise
157157
``` ts
158158
import * as cep from 'cep-promise'
159159

160-
cep('05010000')
160+
cepPromise('05010000')
161161
.then(console.log)
162162
```
163163

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"zipcode",
3535
"zip",
3636
"promise",
37-
"viacep"
37+
"viacep",
38+
"cepPromise"
3839
],
3940
"homepage": "https://github.com/filipedeschamps/cep-promise",
4041
"devDependencies": {

test/e2e/cep-promise.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import chai from 'chai'
44
import chaiAsPromised from 'chai-as-promised'
55
import chaiSubset from 'chai-subset'
66

7-
import cep from '../../src/cep-promise.js'
7+
import cepPromise from '../../src/cep-promise.js'
88
import CepPromiseError from '../../src/errors/cep-promise.js'
99

1010
chai.use(chaiAsPromised)
@@ -15,7 +15,7 @@ let expect = chai.expect
1515
describe('cep-promise (E2E)', () => {
1616
describe('when invoked with a valid "05010000" string', () => {
1717
it('should fulfill with correct address', () => {
18-
return expect(cep('05010000')).to.eventually.deep.equal({
18+
return expect(cepPromise('05010000')).to.eventually.deep.equal({
1919
cep: '05010000',
2020
state: 'SP',
2121
city: 'São Paulo',
@@ -27,7 +27,7 @@ describe('cep-promise (E2E)', () => {
2727

2828
describe('when invoked with a valid 5010000 number', () => {
2929
it('should fulfill with correct address', () => {
30-
return expect(cep(5010000)).to.eventually.deep.equal({
30+
return expect(cepPromise(5010000)).to.eventually.deep.equal({
3131
cep: '05010000',
3232
state: 'SP',
3333
city: 'São Paulo',
@@ -39,7 +39,7 @@ describe('cep-promise (E2E)', () => {
3939

4040
describe('when invoked with an inexistent "99999999" CEP', () => {
4141
it('should reject with "service_error"', () => {
42-
return cep('99999999')
42+
return cepPromise('99999999')
4343
.catch((error) => {
4444
return expect(error)
4545
.to.be.an.instanceOf(CepPromiseError)
@@ -61,7 +61,7 @@ describe('cep-promise (E2E)', () => {
6161

6262
describe('when invoked with an invalid "123456789" CEP', () => {
6363
it('should reject with "validation_error"', () => {
64-
return cep('123456789')
64+
return cepPromise('123456789')
6565
.catch((error) => {
6666
return expect(error)
6767
.to.be.an.instanceOf(CepPromiseError)

test/unit/cep-promise.spec.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import chaiSubset from 'chai-subset'
66
import nock from 'nock'
77
import path from 'path'
88

9-
import cep from '../../src/cep-promise.js'
9+
import cepPromise from '../../src/cep-promise.js'
1010
import CepPromiseError from '../../src/errors/cep-promise.js'
1111

1212
chai.use(chaiAsPromised)
@@ -17,7 +17,7 @@ let expect = chai.expect
1717
describe('cep-promise (unit)', () => {
1818
describe('when imported', () => {
1919
it('should return a Function', () => {
20-
expect(cep).to.be.a('function')
20+
expect(cepPromise).to.be.a('function')
2121
})
2222
})
2323

@@ -33,15 +33,15 @@ describe('cep-promise (unit)', () => {
3333
.get('/api/v2/ceps.json?cep=05010000')
3434
.replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json'))
3535

36-
const cepPromise = cep('05010000')
36+
const cepPromise = cepPromise('05010000')
3737
expect(cepPromise.then).to.be.a('function')
3838
expect(cepPromise.catch).to.be.a('function')
3939
})
4040
})
4141

4242
describe('when invoked without arguments', () => {
4343
it('should reject with "validation_error"', () => {
44-
return cep()
44+
return cepPromise()
4545
.catch((error) => {
4646
return expect(error)
4747
.to.be.an.instanceOf(CepPromiseError)
@@ -60,7 +60,7 @@ describe('cep-promise (unit)', () => {
6060

6161
describe('when invoked with an Array', () => {
6262
it('should reject with "validation_error"', () => {
63-
return cep([1, 2, 3])
63+
return cepPromise([1, 2, 3])
6464
.catch((error) => {
6565
return expect(error)
6666
.to.be.an.instanceOf(CepPromiseError)
@@ -79,7 +79,7 @@ describe('cep-promise (unit)', () => {
7979

8080
describe('when invoked with an Object', () => {
8181
it('should reject with "validation_error"', () => {
82-
return cep({ nintendo: true, ps: false, xbox: false })
82+
return cepPromise({ nintendo: true, ps: false, xbox: false })
8383
.catch((error) => {
8484
return expect(error)
8585
.to.be.an.instanceOf(CepPromiseError)
@@ -98,7 +98,7 @@ describe('cep-promise (unit)', () => {
9898

9999
describe('when invoked with an Function', () => {
100100
it('should reject with "validation_error"', () => {
101-
return cep(function zelda () { return 'link' })
101+
return cepPromise(function zelda () { return 'link' })
102102
.catch((error) => {
103103
return expect(error)
104104
.to.be.an.instanceOf(CepPromiseError)
@@ -128,7 +128,7 @@ describe('cep-promise (unit)', () => {
128128
.get('/api/v2/ceps.json?cep=05010000')
129129
.replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json'))
130130

131-
return expect(cep('05010000')).to.eventually.deep.equal({
131+
return expect(cepPromise('05010000')).to.eventually.deep.equal({
132132
cep: '05010000',
133133
state: 'SP',
134134
city: 'São Paulo',
@@ -150,7 +150,7 @@ describe('cep-promise (unit)', () => {
150150
.get('/api/v2/ceps.json?cep=05010000')
151151
.replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json'))
152152

153-
return expect(cep(5010000)).to.eventually.deep.equal({
153+
return expect(cepPromise(5010000)).to.eventually.deep.equal({
154154
cep: '05010000',
155155
state: 'SP',
156156
city: 'São Paulo',
@@ -172,7 +172,7 @@ describe('cep-promise (unit)', () => {
172172
.get('/api/v2/ceps.json?cep=05010000')
173173
.replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-99999999-error.json'))
174174

175-
return expect(cep('5010000')).to.eventually.deep.equal({
175+
return expect(cepPromise('5010000')).to.eventually.deep.equal({
176176
cep: '05010000',
177177
state: 'SP',
178178
city: 'São Paulo',
@@ -193,8 +193,8 @@ describe('cep-promise (unit)', () => {
193193
nock('http://www.cepaberto.com')
194194
.get('/api/v2/ceps.json?cep=05010000')
195195
.replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-99999999-error.json'))
196-
197-
return expect(cep('5010000')).to.eventually.deep.equal({
196+
197+
return expect(cepPromise('5010000')).to.eventually.deep.equal({
198198
cep: '05010000',
199199
state: 'SP',
200200
city: 'São Paulo',
@@ -215,8 +215,8 @@ describe('cep-promise (unit)', () => {
215215
nock('http://www.cepaberto.com')
216216
.get('/api/v2/ceps.json?cep=05010000')
217217
.replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json'))
218-
219-
return expect(cep('5010000')).to.eventually.deep.equal({
218+
219+
return expect(cepPromise('5010000')).to.eventually.deep.equal({
220220
cep: '05010000',
221221
state: 'SP',
222222
city: 'São Paulo',
@@ -238,7 +238,7 @@ describe('cep-promise (unit)', () => {
238238
.get('/api/v2/ceps.json?cep=05010000')
239239
.replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json'))
240240

241-
return expect(cep('5010000')).to.eventually.deep.equal({
241+
return expect(cepPromise('5010000')).to.eventually.deep.equal({
242242
cep: '05010000',
243243
state: 'SP',
244244
city: 'São Paulo',
@@ -260,7 +260,7 @@ describe('cep-promise (unit)', () => {
260260
.get('/api/v2/ceps.json?cep=05010000')
261261
.replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-05010000-found.json'))
262262

263-
return expect(cep('5010000')).to.eventually.deep.equal({
263+
return expect(cepPromise('5010000')).to.eventually.deep.equal({
264264
cep: '05010000',
265265
state: 'SP',
266266
city: 'São Paulo',
@@ -282,7 +282,7 @@ describe('cep-promise (unit)', () => {
282282
.get('/api/v2/ceps.json?cep=99999999')
283283
.replyWithFile(200, path.join(__dirname, '/fixtures/cep-aberto-99999999-error.json'))
284284

285-
return cep('99999999')
285+
return cepPromise('99999999')
286286
.catch((error) => {
287287
return expect(error)
288288
.to.be.an.instanceOf(CepPromiseError)
@@ -307,7 +307,7 @@ describe('cep-promise (unit)', () => {
307307

308308
describe('when invoked with an invalid "123456789" CEP', () => {
309309
it('should reject with "validation_error"', () => {
310-
return cep('123456789')
310+
return cepPromise('123456789')
311311
.catch((error) => {
312312
return expect(error)
313313
.to.be.an.instanceOf(CepPromiseError)
@@ -336,7 +336,7 @@ describe('cep-promise (unit)', () => {
336336
.get('/api/v2/ceps.json?cep=05010000')
337337
.reply(400, '<h2>Bad Request (400)</h2>')
338338

339-
return cep('05010000')
339+
return cepPromise('05010000')
340340
.catch((error) => {
341341
return expect(error)
342342
.to.be.an.instanceOf(CepPromiseError)
@@ -371,7 +371,7 @@ describe('cep-promise (unit)', () => {
371371
.get('/api/v2/ceps.json?cep=05010000')
372372
.reply(400, '<h2>Bad Request (400)</h2>')
373373

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

409-
return cep('05010000')
409+
return cepPromise('05010000')
410410
.catch((error) => {
411411
return expect(error)
412412
.to.be.an.instanceOf(CepPromiseError)

0 commit comments

Comments
 (0)