Skip to content

Commit

Permalink
feat: atualizar para v305
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Oct 4, 2024
1 parent 05f310b commit e787b4b
Show file tree
Hide file tree
Showing 19 changed files with 481 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Pacote de integração com a [API v3 do ERP Bling](https://developer.bling.com.br)
para Javascript/TypeScript. O mais completo existente.

Atualizado com a versão `v304` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-07-04)).
Atualizado com a versão `v305` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-07-04)).

**Atenção**: a versão 5.0.0+ do `bling-erp-api` para Javascript/TypeScript
utiliza a API v3 do Bling. Caso deseja utilizar a API v2 do Bling,
Expand Down Expand Up @@ -44,7 +44,7 @@ projeto de demonstração](https://github.com/AlexandreBellas/bling-erp-api-js/t

## Entidades disponíveis

Quase todas as entidades do Bling atualmente são permitidas para interação. São elas:
Todas as entidades do Bling atualmente são permitidas para interação. São elas:

- [x] Borderos (`.borderos`)
- [x] Campos customizados (`.camposCustomizados`)
Expand All @@ -62,7 +62,7 @@ Quase todas as entidades do Bling atualmente são permitidas para interação. S
- [x] Empresas (`.empresas`)
- [x] Estoques (`.estoques`)
- [x] Formas de Pagamento (`.formasDePagamento`)
- [ ] Grupos de Produtos (`.gruposDeProdutos`)
- [x] Grupos de Produtos (`.gruposDeProdutos`)
- [x] Homologação (`.homologacao`)
- [x] Logísticas (`.logisticas`)
- [x] Logísticas - Etiquetas (`.logisticasEtiquetas`)
Expand Down
7 changes: 7 additions & 0 deletions src/bling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { Vendedores } from './entities/vendedores'
import { CanaisDeVenda } from './entities/canaisDeVenda'
import { OrdensDeProducao } from './entities/ordensDeProducao'
import { PropostasComerciais } from './entities/propostasComerciais'
import { GruposDeProdutos } from './entities/gruposDeProdutos'

const chance = Chance()

Expand Down Expand Up @@ -266,4 +267,10 @@ describe('Bling main module', () => {
PropostasComerciais
)
})

it('should retrieve grupos de produtos entity', () => {
expect(createBling(chance.word()).gruposDeProdutos).toBeInstanceOf(
GruposDeProdutos
)
})
})
10 changes: 10 additions & 0 deletions src/bling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Depositos } from './entities/depositos'
import { Empresas } from './entities/empresas'
import { Estoques } from './entities/estoques'
import { FormasDePagamento } from './entities/formasDePagamento'
import { GruposDeProdutos } from './entities/gruposDeProdutos'
import { Homologacao } from './entities/homologacao'
import { Logisticas } from './entities/logisticas'
import { LogisticasEtiquetas } from './entities/logisticasEtiquetas'
Expand Down Expand Up @@ -452,4 +453,13 @@ export default class Bling {
public get propostasComerciais(): PropostasComerciais {
return this.getModule(PropostasComerciais)
}

/**
* Obtém a instância de interação com grupos de produtos.
*
* @return {GruposDeProdutos}
*/
public get gruposDeProdutos(): GruposDeProdutos {
return this.getModule(GruposDeProdutos)
}
}
8 changes: 5 additions & 3 deletions src/entities/contasReceber/interfaces/get.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ export interface IGetParams {
limite?: number
situacoes?: ISituacao[]
/**
* `E`: filtrar por data de emissão
* `V`: filtrar por data de vencimento
* - `E`: filtrar por data de emissão
* - `V`: filtrar por data de vencimento
* - `R`: Data de recebimento
*/
tipoFiltroData?: 'E' | 'V'
tipoFiltroData?: 'E' | 'V' | 'R'
dataInicial?: Date | string
dataFinal?: Date | string
idsCategorias?: number[]
idPortador?: number
idContato?: number
idVendedor?: number
idFormaPagamento?: number
boletoGerado?: number
Expand Down
10 changes: 8 additions & 2 deletions src/entities/formasDePagamento/types/tipo-pagamento.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
* - `2`: Cheque
* - `3`: Cartão de Crédito
* - `4`: Cartão de Débito
* - `5`: Crédito Loja
* - `5`: Cartão da Loja (Private Label)
* - `10`: Vale Alimentação
* - `11`: Vale Refeição
* - `12`: Vale Presente
* - `13`: Vale Combustível
* - `14`: Duplicata Mercantil
* - `15`: Boleto Bancário
* - `16`: Depósito Bancário
* - `17`: Pagamento Instantâneo (PIX)
* - `17`: Pagamento Instantâneo (PIX) - Dinâmico
* - `18`: Transferência Bancária, Carteira Digital
* - `19`: Programa de Fidelidade, Cashback, Crédito Virtual
* - `20`: Pagamento Instantâneo (PIX) – Estático
* - `21`: Crédito em loja
* - `22`: Pagamento Eletrônico não Informado - falha de hardware do sistema emissor
* - `90`: Sem pagamento
* - `99`: Outros
*/
Expand All @@ -33,5 +36,8 @@ export type ITipoPagamento =
| 17
| 18
| 19
| 20
| 21
| 22
| 90
| 99
12 changes: 12 additions & 0 deletions src/entities/gruposDeProdutos/__tests__/create-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
data: {
id: 12345678
}
}

export const createRequestBody = {
nome: "Grupo 1",
grupoProdutoPai: {
id: 123456
}
}
30 changes: 30 additions & 0 deletions src/entities/gruposDeProdutos/__tests__/delete-many-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default {
data: {
alertas: [
{
error: {
type: "VALIDATION_ERROR",
message: "Não foi possível salvar a venda",
description: "A venda não pode ser salva, pois ocorreram problemas em sua validação.",
fields: [
{
code: 49,
msg: "Uma ou mais parcelas da venda possuem erros de validação",
element: "parcelas",
namespace: "VENDAS",
collection: [
{
index: 1,
code: 12,
msg: "Id da forma de pagamento inválido.",
element: "formaPagamento",
namespace: "VENDAS"
}
]
}
]
}
}
]
}
}
1 change: 1 addition & 0 deletions src/entities/gruposDeProdutos/__tests__/delete-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null
10 changes: 10 additions & 0 deletions src/entities/gruposDeProdutos/__tests__/find-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
data: {
id: 123456,
nome: "Grupo 1",
grupoProdutoPai: {
id: 123456,
nome: "Grupo 1"
}
}
}
12 changes: 12 additions & 0 deletions src/entities/gruposDeProdutos/__tests__/get-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
data: [
{
id: 123456,
nome: "Grupo 1",
grupoProdutoPai: {
id: 123456,
nome: "Grupo 1"
}
}
]
}
142 changes: 142 additions & 0 deletions src/entities/gruposDeProdutos/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { Chance } from 'chance'
import { GruposDeProdutos } from '..'
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
import { ICreateResponse } from '../interfaces/create.interface'
import { IDeleteManyResponse } from '../interfaces/delete-many.interface'
import { IFindResponse } from '../interfaces/find.interface'
import { IGetResponse } from '../interfaces/get.interface'
import createResponse, { createRequestBody } from './create-response'
import deleteManyResponse from './delete-many-response'
import deleteResponse from './delete-response'
import findResponse from './find-response'
import getResponse from './get-response'
import updateResponse, { updateRequestBody } from './update-response'

const chance = Chance()

describe('GruposDeProdutos entity', () => {
let repository: InMemoryBlingRepository
let entity: GruposDeProdutos

beforeEach(() => {
repository = new InMemoryBlingRepository()
entity = new GruposDeProdutos(repository)
})

afterEach(() => {
jest.restoreAllMocks()
})

it('should delete many successfully', async () => {
const idsGruposProdutos: number[] = []
for (let i = 0; i < chance.natural({ min: 1, max: 5 }); i++) {
idsGruposProdutos.push(chance.natural())
}
const spy = jest.spyOn(repository, 'destroy')
repository.setResponse(deleteManyResponse)

const response = await entity.deleteMany({ idsGruposProdutos })

expect(spy).toHaveBeenCalledWith({
endpoint: 'grupos-produtos',
id: '',
params: { idsGruposProdutos }
})
expect(response).toBe(deleteManyResponse)

const typingResponseTest: IDeleteManyResponse = deleteManyResponse
expect(typingResponseTest).toBe(deleteManyResponse)
})

it('should delete successfully', async () => {
const idGrupoProduto = chance.natural()
const spy = jest.spyOn(repository, 'destroy')
repository.setResponse(deleteResponse)

const response = await entity.delete({ idGrupoProduto })

expect(spy).toHaveBeenCalledWith({
endpoint: 'grupos-produtos',
id: String(idGrupoProduto)
})
expect(response).toBe(deleteResponse)

const typingResponseTest: null = deleteResponse
expect(typingResponseTest).toBe(deleteResponse)
})

it('should get successfully', async () => {
const spy = jest.spyOn(repository, 'index')
repository.setResponse(getResponse)

const response = await entity.get()

expect(spy).toHaveBeenCalledWith({
endpoint: 'grupos-produtos',
params: {
nome: undefined,
nomePai: undefined,
pagina: undefined,
limite: undefined
}
})
expect(response).toBe(getResponse)

const typingResponseTest: IGetResponse = getResponse
expect(typingResponseTest).toBe(getResponse)
})

it('should find successfully', async () => {
const spy = jest.spyOn(repository, 'show')
const idGrupoProduto = chance.natural()
repository.setResponse(findResponse)

const response = await entity.find({ idGrupoProduto })

expect(spy).toHaveBeenCalledWith({
endpoint: 'grupos-produtos',
id: String(idGrupoProduto)
})
expect(response).toBe(findResponse)

const typingResponseTest: IFindResponse = findResponse
expect(typingResponseTest).toBe(findResponse)
})

it('should create successfully', async () => {
const spy = jest.spyOn(repository, 'store')
repository.setResponse(createResponse)

const response = await entity.create(createRequestBody)

expect(spy).toHaveBeenCalledWith({
endpoint: 'grupos-produtos',
body: createRequestBody
})
expect(response).toBe(createResponse)

const typingResponseTest: ICreateResponse = createResponse
expect(typingResponseTest).toBe(createResponse)
})

it('should update successfully', async () => {
const spy = jest.spyOn(repository, 'replace')
const idGrupoProduto = chance.natural()
repository.setResponse(updateResponse)

const response = await entity.update({
idGrupoProduto,
...updateRequestBody
})

expect(spy).toHaveBeenCalledWith({
endpoint: 'grupos-produtos',
id: String(idGrupoProduto),
body: updateRequestBody
})
expect(response).toBe(updateResponse)

const typingResponseTest: null = updateResponse
expect(typingResponseTest).toBe(updateResponse)
})
})
8 changes: 8 additions & 0 deletions src/entities/gruposDeProdutos/__tests__/update-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default null

export const updateRequestBody = {
nome: "Grupo 1",
grupoProdutoPai: {
id: 123456
}
}
Loading

0 comments on commit e787b4b

Please sign in to comment.