Skip to content

Commit

Permalink
feat: atualizar para v303
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Sep 29, 2024
1 parent 24e5cb6 commit 00eb294
Show file tree
Hide file tree
Showing 30 changed files with 825 additions and 38 deletions.
4 changes: 2 additions & 2 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 `v301` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-05-22)).
Atualizado com a versão `v303` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-06-19)).

**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 @@ -74,7 +74,7 @@ Quase todas as entidades do Bling atualmente são permitidas para interação. S
- [x] Notas Fiscais de Serviço Eletrônicas (`.nfses`)
- [x] Notas Fiscais Eletrônicas (`.nfes`)
- [x] Notificações (`.notificacoes`)
- [ ] Ordens de Produção (`.ordensDeProducao`)
- [x] Ordens de Produção (`.ordensDeProducao`)
- [x] Pedidos - Compras (`.pedidosCompras`)
- [x] Pedidos - Vendas (`.pedidosVendas`)
- [x] Produtos (`.produtos`)
Expand Down
7 changes: 7 additions & 0 deletions src/bling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { SituacoesTransicoes } from './entities/situacoesTransicoes'
import { Usuarios } from './entities/usuarios'
import { Vendedores } from './entities/vendedores'
import { CanaisDeVenda } from './entities/canaisDeVenda'
import { OrdensDeProducao } from './entities/ordensDeProducao'

const chance = Chance()

Expand Down Expand Up @@ -252,4 +253,10 @@ describe('Bling main module', () => {
CanaisDeVenda
)
})

it('should retrieve ordens de produção entity', () => {
expect(createBling(chance.word()).ordensDeProducao).toBeInstanceOf(
OrdensDeProducao
)
})
})
10 changes: 10 additions & 0 deletions src/bling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Nfces } from './entities/nfces'
import { Nfes } from './entities/nfes'
import { Nfses } from './entities/nfses'
import { Notificacoes } from './entities/notificacoes'
import { OrdensDeProducao } from './entities/ordensDeProducao'
import { PedidosCompras } from './entities/pedidosCompras'
import { PedidosVendas } from './entities/pedidosVendas'
import { Produtos } from './entities/produtos'
Expand Down Expand Up @@ -432,4 +433,13 @@ export default class Bling {
public get canaisDeVenda(): CanaisDeVenda {
return this.getModule(CanaisDeVenda)
}

/**
* Obtém a instância de interação com ordens de produção.
*
* @return {OrdensDeProducao}
*/
public get ordensDeProducao(): OrdensDeProducao {
return this.getModule(OrdensDeProducao)
}
}
4 changes: 4 additions & 0 deletions src/entities/empresas/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Empresas } from '..'
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
import { IMeResponse } from '../interfaces/me.interface'
import meResponse from './me-response'

describe('Empresas entity', () => {
Expand All @@ -25,5 +26,8 @@ describe('Empresas entity', () => {
endpoint: 'empresas/me/dados-basicos'
})
expect(response).toBe(meResponse)

const typingResponseTest: IMeResponse = meResponse
expect(typingResponseTest).toBe(meResponse)
})
})
8 changes: 5 additions & 3 deletions src/entities/empresas/__tests__/me-response.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export default {
data: {
nome: 'Empresa Teste LTDA',
cnpj: '12.345.657/8910-11',
email: 'empresa@email.com'
id: "436c56a5679921f5f13a3d6433561773",
nome: "Empresa Teste LTDA",
cnpj: "12.345.657/8910-11",
email: "empresa@email.com",
dataContrato: "2024-12-31"
}
}
2 changes: 2 additions & 0 deletions src/entities/empresas/interfaces/me.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export interface IMeResponse {
data: {
id: string
nome: string
cnpj: string
email: string
dataContrato: string
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default null

export const changeSituationRequest = {
idSituacao: 12345678,
quantidade: 1,
observacoes: "Observação",
considerarPerdas: true
}
30 changes: 30 additions & 0 deletions src/entities/ordensDeProducao/__tests__/create-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default {
data: {
id: 12345678
}
}

export const createRequestBody = {
dataPrevisaoInicio: "2021-01-01",
dataPrevisaoFinal: "2021-01-01",
dataInicio: "2021-01-01",
dataFim: "2021-01-01",
numero: 12345678,
responsavel: "Responsável pela ordem de produção",
deposito: {
idDestino: 12345678,
idOrigem: 12345678
},
situacao: {
id: 12345678
},
itens: [
{
produto: {
id: 12345678
},
quantidade: 1
}
],
observacoes: "Observações"
}
1 change: 1 addition & 0 deletions src/entities/ordensDeProducao/__tests__/delete-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null
38 changes: 38 additions & 0 deletions src/entities/ordensDeProducao/__tests__/find-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export default {
id: 12345678,
dataPrevisaoInicio: "2021-01-01",
dataPrevisaoFinal: "2021-01-01",
dataInicio: "2021-01-01",
dataFim: "2021-01-01",
numero: 12345678,
responsavel: "Responsável pela ordem de produção",
deposito: {
idDestino: 12345678,
idOrigem: 12345678
},
situacao: {
id: 12345678,
valor: 1,
nome: "Em aberto"
},
vendas: [
{
numero: 12345678,
contato: {
id: 12345678,
nome: "João da Silva"
}
}
],
itens: [
{
produto: {
id: 12345678,
nome: "Nome do produto",
codigo: "Código do produto"
},
quantidade: 1
}
],
observacoes: "Observações"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default {
data: [
{
id: 12345678,
itens: [
{
produto: {
id: 12345678,
nome: "Nome do produto",
codigo: "Código do produto"
},
quantidade: 1
}
],
deposito: {
idDestino: 12345678,
idOrigem: 12345678
}
}
]
}
22 changes: 22 additions & 0 deletions src/entities/ordensDeProducao/__tests__/get-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {
data: [
{
id: 12345678,
dataPrevisaoInicio: "2021-01-01",
dataPrevisaoFinal: "2021-01-01",
dataInicio: "2021-01-01",
dataFim: "2021-01-01",
numero: 12345678,
responsavel: "Responsável pela ordem de produção",
deposito: {
idDestino: 12345678,
idOrigem: 12345678
},
situacao: {
id: 12345678,
valor: 1,
nome: "Em aberto"
}
}
]
}
160 changes: 160 additions & 0 deletions src/entities/ordensDeProducao/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { Chance } from 'chance'
import { OrdensDeProducao } from '..'
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
import { ICreateResponse } from '../interfaces/create.interface'
import { IFindResponse } from '../interfaces/find.interface'
import { IGetResponse } from '../interfaces/get.interface'
import changeSituationResponse, {
changeSituationRequest
} from './change-situation-response'
import createResponse, { createRequestBody } from './create-response'
import deleteResponse from './delete-response'
import findResponse from './find-response'
import getResponse from './get-response'
import updateResponse, { updateRequestBody } from './update-response'
import generateOverDemandResponse from './generate-over-demand-response'
import { IGenerateOverDemandResponse } from '../interfaces/generate-over-demand.interface'

const chance = Chance()

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

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

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

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

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

expect(spy).toHaveBeenCalledWith({
endpoint: 'ordens-producao',
id: String(idOrdemProducao)
})
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: 'ordens-producao',
params: {
limite: undefined,
pagina: undefined,
idsSituacoes: 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 idOrdemProducao = chance.natural()
repository.setResponse(findResponse)

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

expect(spy).toHaveBeenCalledWith({
endpoint: 'ordens-producao',
id: String(idOrdemProducao)
})
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: 'ordens-producao',
body: createRequestBody
})
expect(response).toBe(createResponse)

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

it('should generate over demand successfully', async () => {
const spy = jest.spyOn(repository, 'store')
repository.setResponse(generateOverDemandResponse)

const response = await entity.generateOverDemand()

expect(spy).toHaveBeenCalledWith({
endpoint: 'ordens-producao/gerar-sob-demanda',
body: {}
})
expect(response).toBe(generateOverDemandResponse)

const typingResponseTest: IGenerateOverDemandResponse = generateOverDemandResponse
expect(typingResponseTest).toBe(generateOverDemandResponse)
})

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

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

expect(spy).toHaveBeenCalledWith({
endpoint: 'ordens-producao',
id: String(idOrdemProducao),
body: updateRequestBody
})
expect(response).toBe(updateResponse)

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

it('should change situation successfully', async () => {
const spy = jest.spyOn(repository, 'update')
const idOrdemProducao = chance.natural()
repository.setResponse(changeSituationResponse)

const response = await entity.changeSituation({
idOrdemProducao,
...changeSituationRequest
})

expect(spy).toHaveBeenCalledWith({
endpoint: 'ordens-producao',
id: `${idOrdemProducao}/situacoes`,
body: changeSituationRequest
})
expect(response).toBe(changeSituationResponse)

const typingResponseTest: null = changeSituationResponse
expect(typingResponseTest).toBe(changeSituationResponse)
})
})
Loading

0 comments on commit 00eb294

Please sign in to comment.