Skip to content

Commit

Permalink
feat: atualizar para v310
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Oct 5, 2024
1 parent 53e9d7f commit f42fc57
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 19 deletions.
2 changes: 1 addition & 1 deletion 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 `v307` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-08-21)).
Atualizado com a versão `v310` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-10-02)).

**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
4 changes: 2 additions & 2 deletions src/entities/contasReceber/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('Contas a receber entity', () => {
})

expect(spy).toHaveBeenCalledWith({
endpoint: 'contas/receber/view/bankslips',
endpoint: 'contas/receber/boletos',
params: {
idOrigem,
situations: undefined
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('Contas a receber entity', () => {
const response = await entity.cancelBankSlips(cancelBankSlipRequest)

expect(spy).toHaveBeenCalledWith({
endpoint: 'contas/receber/cancel/bankslips',
endpoint: 'contas/receber/boletos/cancelar',
body: cancelBankSlipRequest
})
expect(response).toBe(cancelBankSlipsResponse)
Expand Down
12 changes: 8 additions & 4 deletions src/entities/contatos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,20 @@ export class Contatos extends Entity {
pesquisa: params?.pesquisa,
criterio: params?.criterio,
dataInclusaoInicial: this.prepareStringOrDateParam(
params?.dataInclusaoInicial
params?.dataInclusaoInicial,
true
),
dataInclusaoFinal: this.prepareStringOrDateParam(
params?.dataInclusaoFinal
params?.dataInclusaoFinal,
true
),
dataAlteracaoInicial: this.prepareStringOrDateParam(
params?.dataAlteracaoInicial
params?.dataAlteracaoInicial,
true
),
dataAlteracaoFinal: this.prepareStringOrDateParam(
params?.dataAlteracaoFinal
params?.dataAlteracaoFinal,
true
),
idTipoContato: params?.idTipoContato,
idVendedor: params?.idVendedor,
Expand Down
2 changes: 1 addition & 1 deletion src/entities/naturezasDeOperacoes/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Naturezas de Operação entity', () => {
})

expect(spy).toHaveBeenCalledWith({
endpoint: `naturezas-operacoes/${idNaturezaOperacao}/calcular-imposto-item`,
endpoint: `naturezas-operacoes/${idNaturezaOperacao}/obter-tributacao`,
body: obtainTaxRequestBody
})
expect(response).toBe(obtainTaxResponse)
Expand Down
5 changes: 5 additions & 0 deletions src/entities/nfses/__tests__/cancel-response.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export default null

export const cancelRequest = {
codigoMotivo: 1 as const,
justificativa: "Cancelamento de NFS-e"
}
2 changes: 1 addition & 1 deletion src/entities/nfses/__tests__/get-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
numero: '123',
numeroRPS: '32',
serie: '1',
situacao: 0,
situacao: 0 as const,
dataEmissao: '2023-01-12',
valor: 100,
contato: {
Expand Down
35 changes: 32 additions & 3 deletions src/entities/nfses/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Chance } from 'chance'
import { Nfses } from '..'
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
import cancelResponse from './cancel-response'
import cancelResponse, { cancelRequest } from './cancel-response'
import createResponse, { createRequestBody } from './create-response'
import deleteResponse from './delete-response'
import findResponse from './find-response'
Expand All @@ -11,6 +11,11 @@ import sendResponse from './send-response'
import updateConfigurationsResponse, {
updateConfigurationsRequestBody
} from './update-configurations-response'
import { IGetResponse } from '../interfaces/get.interface'
import { IFindResponse } from '../interfaces/find.interface'
import { IGetConfigurationsResponse } from '../interfaces/get-configurations.interface'
import { ICreateResponse } from '../interfaces/create.interface'
import { ISendResponse } from '../interfaces/send.interface'

const chance = Chance()

Expand Down Expand Up @@ -39,6 +44,9 @@ describe('NFS-es entity', () => {
id: String(idNotaServico)
})
expect(response).toBe(deleteResponse)

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

it('should get successfully', async () => {
Expand All @@ -59,6 +67,9 @@ describe('NFS-es entity', () => {
}
})
expect(response).toBe(getResponse)

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

it('should find successfully', async () => {
Expand All @@ -73,6 +84,9 @@ describe('NFS-es entity', () => {
id: String(idNotaServico)
})
expect(response).toBe(findResponse)

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

it('should get configurations successfully', async () => {
Expand All @@ -85,6 +99,9 @@ describe('NFS-es entity', () => {
endpoint: 'nfse/configuracoes'
})
expect(response).toBe(getConfigurationsResponse)

const typingResponseTest: IGetConfigurationsResponse = getConfigurationsResponse
expect(typingResponseTest).toBe(getConfigurationsResponse)
})

it('should create successfully', async () => {
Expand All @@ -98,6 +115,9 @@ describe('NFS-es entity', () => {
body: createRequestBody
})
expect(response).toBe(createResponse)

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

it('should send successfully', async () => {
Expand All @@ -112,20 +132,26 @@ describe('NFS-es entity', () => {
body: {}
})
expect(response).toBe(sendResponse)

const typingResponseTest: ISendResponse = sendResponse
expect(typingResponseTest).toBe(sendResponse)
})

it('should cancel successfully', async () => {
const spy = jest.spyOn(repository, 'store')
const idNotaServico = chance.natural()
repository.setResponse(cancelResponse)

const response = await entity.cancel({ idNotaServico })
const response = await entity.cancel({ idNotaServico, ...cancelRequest })

expect(spy).toHaveBeenCalledWith({
endpoint: `nfse/${idNotaServico}/cancelar`,
body: {}
body: cancelRequest
})
expect(response).toBe(cancelResponse)

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

it('should update configurations successfully', async () => {
Expand All @@ -142,5 +168,8 @@ describe('NFS-es entity', () => {
body: updateConfigurationsRequestBody
})
expect(response).toBe(updateConfigurationsResponse)

const typingResponseTest: null = updateConfigurationsResponse
expect(typingResponseTest).toBe(updateConfigurationsResponse)
})
})
11 changes: 6 additions & 5 deletions src/entities/nfses/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Entity } from '../@shared/entity'
import { ISendResponse } from '../nfces/interfaces/send.interface'
import { ICancelParams } from './interfaces/cancel.interface'
import { ICancelBody, ICancelParams } from './interfaces/cancel.interface'
import { ICreateBody, ICreateResponse } from './interfaces/create.interface'
import { IDeleteParams } from './interfaces/delete.interface'
import { IFindParams, IFindResponse } from './interfaces/find.interface'
Expand Down Expand Up @@ -127,17 +127,18 @@ export class Nfses extends Entity {
/**
* Cancela uma nota de serviço.
*
* @param {ICancelParams} params Os parâmetros de envio.
* @param {ICancelParams & ICancelBody} params Os parâmetros de envio.
*
* @returns {Promise<null>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Notas%20Fiscais%20de%20Servi%C3%A7o%20Eletr%C3%B4nicas/post_nfse__idNotaServico__cancelar
*/
public async cancel(params: ICancelParams): Promise<null> {
public async cancel(params: ICancelParams & ICancelBody): Promise<null> {
const { idNotaServico, ...body } = params
return await this.repository.store({
endpoint: `nfse/${params.idNotaServico}/cancelar`,
body: {}
endpoint: `nfse/${idNotaServico}/cancelar`,
body
})
}

Expand Down
7 changes: 7 additions & 0 deletions src/entities/nfses/interfaces/cancel.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { ICancelarCodigoMotivo } from "../types/cancelar-codigo-motivo.type"

export interface ICancelParams {
/**
* ID da nota de serviço
*/
idNotaServico: number
}

export interface ICancelBody {
codigoMotivo?: ICancelarCodigoMotivo
justificativa?: string
}
9 changes: 9 additions & 0 deletions src/entities/nfses/types/cancelar-codigo-motivo.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* - `1`: Erro na Emissão
* - `2`: Serviço não Prestado
* - `9`: Outros
*/
export type ICancelarCodigoMotivo =
| 1
| 2
| 9
6 changes: 4 additions & 2 deletions src/entities/pedidosVendas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ export class PedidosVendas extends Entity {
dataInicial: this.prepareStringOrDateParam(params?.dataInicial),
dataFinal: this.prepareStringOrDateParam(params?.dataFinal),
dataAlteracaoInicial: this.prepareStringOrDateParam(
params?.dataAlteracaoInicial
params?.dataAlteracaoInicial,
true
),
dataAlteracaoFinal: this.prepareStringOrDateParam(
params?.dataAlteracaoFinal
params?.dataAlteracaoFinal,
true
),
dataPrevistaInicial: this.prepareStringOrDateParam(
params?.dataPrevistaInicial
Expand Down

0 comments on commit f42fc57

Please sign in to comment.