Skip to content

Commit 1a36f10

Browse files
feat: atualizar para v300 (#28)
2 parents afb116c + 80c9c98 commit 1a36f10

33 files changed

+512
-30
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"*.spec.php": "test-ts"
88
},
99
"cSpell.words": [
10+
"agrupador",
1011
"agrupadores",
1112
"aliquota",
1213
"Amazônia",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Pacote de integração com a [API v3 do ERP Bling](https://developer.bling.com.br)
1111
para Javascript/TypeScript. O mais completo existente.
1212

13-
Atualizado com a versão `v296` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-02-28)).
13+
Atualizado com a versão `v300` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-02-28)).
1414

1515
**Atenção**: a versão 5.0.0+ do `bling-erp-api` para Javascript/TypeScript
1616
utiliza a API v3 do Bling. Caso deseja utilizar a API v2 do Bling,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bling-erp-api",
3-
"version": "5.6.0",
3+
"version": "5.7.0",
44
"description": "Pacote de integração com a API do Bling ERP",
55
"main": "lib/bling.js",
66
"directories": {

src/bling.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { SituacoesModulos } from './entities/situacoesModulos'
4040
import { SituacoesTransicoes } from './entities/situacoesTransicoes'
4141
import { Usuarios } from './entities/usuarios'
4242
import { Vendedores } from './entities/vendedores'
43+
import { CanaisDeVenda } from './entities/canaisDeVenda'
4344

4445
const chance = Chance()
4546

@@ -245,4 +246,10 @@ describe('Bling main module', () => {
245246
it('should retrieve vendedores entity', () => {
246247
expect(createBling(chance.word()).vendedores).toBeInstanceOf(Vendedores)
247248
})
249+
250+
it('should retrieve canais de venda entity', () => {
251+
expect(createBling(chance.word()).canaisDeVenda).toBeInstanceOf(
252+
CanaisDeVenda
253+
)
254+
})
248255
})

src/bling.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Entity } from './entities/@shared/entity'
44
import { Borderos } from './entities/borderos'
55
import { CamposCustomizados } from './entities/camposCustomizados'
6+
import { CanaisDeVenda } from './entities/canaisDeVenda'
67
import { CategoriasLojas } from './entities/categoriasLojas'
78
import { CategoriasProdutos } from './entities/categoriasProdutos'
89
import { CategoriasReceitasDespesas } from './entities/categoriasReceitasDespesas'
@@ -352,7 +353,6 @@ export default class Bling {
352353
}
353354

354355
/**
355-
*
356356
* Obtém a instância de interação com produtos - fornecedores.
357357
*
358358
* @return {ProdutosFornecedores}
@@ -362,7 +362,6 @@ export default class Bling {
362362
}
363363

364364
/**
365-
*
366365
* Obtém a instância de interação com produtos - fornecedores.
367366
*
368367
* @return {ProdutosLojas}
@@ -372,7 +371,6 @@ export default class Bling {
372371
}
373372

374373
/**
375-
*
376374
* Obtém a instância de interação com produtos - variações.
377375
*
378376
* @return {ProdutosVariacoes}
@@ -382,7 +380,6 @@ export default class Bling {
382380
}
383381

384382
/**
385-
*
386383
* Obtém a instância de interação com situações.
387384
*
388385
* @return {Situacoes}
@@ -392,7 +389,6 @@ export default class Bling {
392389
}
393390

394391
/**
395-
*
396392
* Obtém a instância de interação com situações - módulos.
397393
*
398394
* @return {SituacoesModulos}
@@ -402,7 +398,6 @@ export default class Bling {
402398
}
403399

404400
/**
405-
*
406401
* Obtém a instância de interação com situações - transições.
407402
*
408403
* @return {SituacoesTransicoes}
@@ -412,7 +407,6 @@ export default class Bling {
412407
}
413408

414409
/**
415-
*
416410
* Obtém a instância de interação com usuários.
417411
*
418412
* @return {Usuarios}
@@ -422,12 +416,20 @@ export default class Bling {
422416
}
423417

424418
/**
425-
*
426419
* Obtém a instância de interação com vendedores.
427420
*
428421
* @return {Vendedores}
429422
*/
430423
public get vendedores(): Vendedores {
431424
return this.getModule(Vendedores)
432425
}
426+
427+
/**
428+
* Obtém a instância de interação com canais de venda.
429+
*
430+
* @return {CanaisDeVenda}
431+
*/
432+
public get canaisDeVenda(): CanaisDeVenda {
433+
return this.getModule(CanaisDeVenda)
434+
}
433435
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default {
2+
data: {
3+
id: 12345678,
4+
descricao: 'Loja de teste',
5+
tipo: 'Shopee',
6+
situacao: 1 as const,
7+
filiais: [
8+
{
9+
cnpj: '12.345.678/9012-34',
10+
unidadeNegocio: 'Empresa Teste',
11+
deposito: {
12+
id: 12345678
13+
},
14+
padrao: true
15+
}
16+
]
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
data: [
3+
{
4+
id: 12345678,
5+
descricao: 'Loja de teste',
6+
tipo: 'Shopee',
7+
situacao: 1 as const
8+
}
9+
]
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
data: [
3+
{
4+
nome: 'Loja Integrada',
5+
tipo: 'LojaIntegrada',
6+
agrupador: 1 as const
7+
}
8+
]
9+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { Chance } from 'chance'
2+
import { CanaisDeVenda } from '../'
3+
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
4+
import findResponse from './find-response'
5+
import getResponse from './get-response'
6+
import getTypesResponse from './get-types-response'
7+
import { IFindResponse } from '../interfaces/find.interface'
8+
import { IGetResponse } from '../interfaces/get.interface'
9+
import { IGetTypesResponse } from '../interfaces/get-types.interface'
10+
11+
const chance = Chance()
12+
13+
describe('Canais de Venda entity', () => {
14+
let repository: InMemoryBlingRepository
15+
let entity: CanaisDeVenda
16+
17+
beforeEach(() => {
18+
repository = new InMemoryBlingRepository()
19+
entity = new CanaisDeVenda(repository)
20+
})
21+
22+
afterEach(() => {
23+
jest.restoreAllMocks()
24+
})
25+
26+
it('should get successfully', async () => {
27+
const spy = jest.spyOn(repository, 'index')
28+
repository.setResponse(getResponse)
29+
30+
const response = await entity.get()
31+
32+
expect(spy).toHaveBeenCalledWith({
33+
endpoint: 'canais-venda',
34+
params: {
35+
pagina: undefined,
36+
limite: undefined,
37+
tipos: undefined,
38+
situacao: undefined,
39+
agrupador: undefined
40+
}
41+
})
42+
expect(response).toBe(getResponse)
43+
const typingResponseTest: IGetResponse = getResponse
44+
expect(typingResponseTest).toBe(getResponse)
45+
})
46+
47+
it('should find successfully', async () => {
48+
const spy = jest.spyOn(repository, 'show')
49+
const idCanalVenda = chance.natural()
50+
repository.setResponse(findResponse)
51+
52+
const response = await entity.find({ idCanalVenda })
53+
54+
expect(spy).toHaveBeenCalledWith({
55+
endpoint: 'canais-venda',
56+
id: String(idCanalVenda)
57+
})
58+
expect(response).toBe(findResponse)
59+
const typingResponseTest: IFindResponse = findResponse
60+
expect(typingResponseTest).toBe(findResponse)
61+
})
62+
63+
it('should get types successfully', async () => {
64+
const spy = jest.spyOn(repository, 'index')
65+
repository.setResponse(getTypesResponse)
66+
67+
const response = await entity.getTypes()
68+
69+
expect(spy).toHaveBeenCalledWith({
70+
endpoint: 'canais-venda/tipos',
71+
params: {
72+
agrupador: undefined
73+
}
74+
})
75+
expect(response).toBe(getTypesResponse)
76+
const typingResponseTest: IGetTypesResponse = getTypesResponse
77+
expect(typingResponseTest).toBe(getTypesResponse)
78+
})
79+
})
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Entity } from '../@shared/entity'
2+
import { IFindParams, IFindResponse } from './interfaces/find.interface'
3+
import {
4+
IGetTypesParams,
5+
IGetTypesResponse
6+
} from './interfaces/get-types.interface'
7+
import { IGetParams, IGetResponse } from './interfaces/get.interface'
8+
9+
/**
10+
* Entidade para interação com Canais de Venda.
11+
*
12+
* @see https://developer.bling.com.br/referencia#/Canais%20de%20Venda
13+
*/
14+
export class CanaisDeVenda extends Entity {
15+
/**
16+
* Obtém canais de venda.
17+
*
18+
* @param {IGetParams} params Parâmetros da busca.
19+
*
20+
* @returns {Promise<IGetResponse>}
21+
* @throws {BlingApiException|BlingInternalException}
22+
*
23+
* @see https://developer.bling.com.br/referencia#/Canais%20de%20Venda/get_canais_venda
24+
*/
25+
public async get(params?: IGetParams): Promise<IGetResponse> {
26+
return await this.repository.index({
27+
endpoint: 'canais-venda',
28+
params: {
29+
pagina: params?.pagina,
30+
limite: params?.limite,
31+
tipos: params?.tipos,
32+
situacao: params?.situacao,
33+
agrupador: params?.agrupador
34+
}
35+
})
36+
}
37+
38+
/**
39+
* Obtém um canal de venda.
40+
*
41+
* @param {IFindParams} params Parâmetros da busca.
42+
*
43+
* @returns {Promise<IFindResponse>}
44+
* @throws {BlingApiException|BlingInternalException}
45+
*
46+
* @see https://developer.bling.com.br/referencia#/Canais%20de%20Venda/get_canais_venda__idCanalVenda_
47+
*/
48+
public async find(params: IFindParams): Promise<IFindResponse> {
49+
return await this.repository.show({
50+
endpoint: 'canais-venda',
51+
id: String(params.idCanalVenda)
52+
})
53+
}
54+
55+
/**
56+
* Obtém os tipos de canais de venda.
57+
*
58+
* @param {IGetTypesParams} params Parâmetros da busca.
59+
*
60+
* @returns {Promise<IGetTypesResponse>}
61+
*
62+
* @see https://developer.bling.com.br/referencia#/Canais%20de%20Venda/get_canais_venda_tipos
63+
*/
64+
public async getTypes(params?: IGetTypesParams): Promise<IGetTypesResponse> {
65+
return await this.repository.index({
66+
endpoint: 'canais-venda/tipos',
67+
params: { agrupador: params?.agrupador }
68+
})
69+
}
70+
}

0 commit comments

Comments
 (0)