Skip to content

Commit f42fc57

Browse files
feat: atualizar para v310
1 parent 53e9d7f commit f42fc57

File tree

11 files changed

+76
-19
lines changed

11 files changed

+76
-19
lines changed

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 `v307` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-08-21)).
13+
Atualizado com a versão `v310` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-10-02)).
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,

src/entities/contasReceber/__tests__/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('Contas a receber entity', () => {
101101
})
102102

103103
expect(spy).toHaveBeenCalledWith({
104-
endpoint: 'contas/receber/view/bankslips',
104+
endpoint: 'contas/receber/boletos',
105105
params: {
106106
idOrigem,
107107
situations: undefined
@@ -153,7 +153,7 @@ describe('Contas a receber entity', () => {
153153
const response = await entity.cancelBankSlips(cancelBankSlipRequest)
154154

155155
expect(spy).toHaveBeenCalledWith({
156-
endpoint: 'contas/receber/cancel/bankslips',
156+
endpoint: 'contas/receber/boletos/cancelar',
157157
body: cancelBankSlipRequest
158158
})
159159
expect(response).toBe(cancelBankSlipsResponse)

src/entities/contatos/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,20 @@ export class Contatos extends Entity {
7878
pesquisa: params?.pesquisa,
7979
criterio: params?.criterio,
8080
dataInclusaoInicial: this.prepareStringOrDateParam(
81-
params?.dataInclusaoInicial
81+
params?.dataInclusaoInicial,
82+
true
8283
),
8384
dataInclusaoFinal: this.prepareStringOrDateParam(
84-
params?.dataInclusaoFinal
85+
params?.dataInclusaoFinal,
86+
true
8587
),
8688
dataAlteracaoInicial: this.prepareStringOrDateParam(
87-
params?.dataAlteracaoInicial
89+
params?.dataAlteracaoInicial,
90+
true
8891
),
8992
dataAlteracaoFinal: this.prepareStringOrDateParam(
90-
params?.dataAlteracaoFinal
93+
params?.dataAlteracaoFinal,
94+
true
9195
),
9296
idTipoContato: params?.idTipoContato,
9397
idVendedor: params?.idVendedor,

src/entities/naturezasDeOperacoes/__tests__/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('Naturezas de Operação entity', () => {
5555
})
5656

5757
expect(spy).toHaveBeenCalledWith({
58-
endpoint: `naturezas-operacoes/${idNaturezaOperacao}/calcular-imposto-item`,
58+
endpoint: `naturezas-operacoes/${idNaturezaOperacao}/obter-tributacao`,
5959
body: obtainTaxRequestBody
6060
})
6161
expect(response).toBe(obtainTaxResponse)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
export default null
2+
3+
export const cancelRequest = {
4+
codigoMotivo: 1 as const,
5+
justificativa: "Cancelamento de NFS-e"
6+
}

src/entities/nfses/__tests__/get-response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
numero: '123',
66
numeroRPS: '32',
77
serie: '1',
8-
situacao: 0,
8+
situacao: 0 as const,
99
dataEmissao: '2023-01-12',
1010
valor: 100,
1111
contato: {

src/entities/nfses/__tests__/index.spec.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Chance } from 'chance'
22
import { Nfses } from '..'
33
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
4-
import cancelResponse from './cancel-response'
4+
import cancelResponse, { cancelRequest } from './cancel-response'
55
import createResponse, { createRequestBody } from './create-response'
66
import deleteResponse from './delete-response'
77
import findResponse from './find-response'
@@ -11,6 +11,11 @@ import sendResponse from './send-response'
1111
import updateConfigurationsResponse, {
1212
updateConfigurationsRequestBody
1313
} from './update-configurations-response'
14+
import { IGetResponse } from '../interfaces/get.interface'
15+
import { IFindResponse } from '../interfaces/find.interface'
16+
import { IGetConfigurationsResponse } from '../interfaces/get-configurations.interface'
17+
import { ICreateResponse } from '../interfaces/create.interface'
18+
import { ISendResponse } from '../interfaces/send.interface'
1419

1520
const chance = Chance()
1621

@@ -39,6 +44,9 @@ describe('NFS-es entity', () => {
3944
id: String(idNotaServico)
4045
})
4146
expect(response).toBe(deleteResponse)
47+
48+
const typingResponseTest: null = deleteResponse
49+
expect(typingResponseTest).toBe(deleteResponse)
4250
})
4351

4452
it('should get successfully', async () => {
@@ -59,6 +67,9 @@ describe('NFS-es entity', () => {
5967
}
6068
})
6169
expect(response).toBe(getResponse)
70+
71+
const typingResponseTest: IGetResponse = getResponse
72+
expect(typingResponseTest).toBe(getResponse)
6273
})
6374

6475
it('should find successfully', async () => {
@@ -73,6 +84,9 @@ describe('NFS-es entity', () => {
7384
id: String(idNotaServico)
7485
})
7586
expect(response).toBe(findResponse)
87+
88+
const typingResponseTest: IFindResponse = findResponse
89+
expect(typingResponseTest).toBe(findResponse)
7690
})
7791

7892
it('should get configurations successfully', async () => {
@@ -85,6 +99,9 @@ describe('NFS-es entity', () => {
8599
endpoint: 'nfse/configuracoes'
86100
})
87101
expect(response).toBe(getConfigurationsResponse)
102+
103+
const typingResponseTest: IGetConfigurationsResponse = getConfigurationsResponse
104+
expect(typingResponseTest).toBe(getConfigurationsResponse)
88105
})
89106

90107
it('should create successfully', async () => {
@@ -98,6 +115,9 @@ describe('NFS-es entity', () => {
98115
body: createRequestBody
99116
})
100117
expect(response).toBe(createResponse)
118+
119+
const typingResponseTest: ICreateResponse = createResponse
120+
expect(typingResponseTest).toBe(createResponse)
101121
})
102122

103123
it('should send successfully', async () => {
@@ -112,20 +132,26 @@ describe('NFS-es entity', () => {
112132
body: {}
113133
})
114134
expect(response).toBe(sendResponse)
135+
136+
const typingResponseTest: ISendResponse = sendResponse
137+
expect(typingResponseTest).toBe(sendResponse)
115138
})
116139

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

122-
const response = await entity.cancel({ idNotaServico })
145+
const response = await entity.cancel({ idNotaServico, ...cancelRequest })
123146

124147
expect(spy).toHaveBeenCalledWith({
125148
endpoint: `nfse/${idNotaServico}/cancelar`,
126-
body: {}
149+
body: cancelRequest
127150
})
128151
expect(response).toBe(cancelResponse)
152+
153+
const typingResponseTest: null = cancelResponse
154+
expect(typingResponseTest).toBe(cancelResponse)
129155
})
130156

131157
it('should update configurations successfully', async () => {
@@ -142,5 +168,8 @@ describe('NFS-es entity', () => {
142168
body: updateConfigurationsRequestBody
143169
})
144170
expect(response).toBe(updateConfigurationsResponse)
171+
172+
const typingResponseTest: null = updateConfigurationsResponse
173+
expect(typingResponseTest).toBe(updateConfigurationsResponse)
145174
})
146175
})

src/entities/nfses/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Entity } from '../@shared/entity'
22
import { ISendResponse } from '../nfces/interfaces/send.interface'
3-
import { ICancelParams } from './interfaces/cancel.interface'
3+
import { ICancelBody, ICancelParams } from './interfaces/cancel.interface'
44
import { ICreateBody, ICreateResponse } from './interfaces/create.interface'
55
import { IDeleteParams } from './interfaces/delete.interface'
66
import { IFindParams, IFindResponse } from './interfaces/find.interface'
@@ -127,17 +127,18 @@ export class Nfses extends Entity {
127127
/**
128128
* Cancela uma nota de serviço.
129129
*
130-
* @param {ICancelParams} params Os parâmetros de envio.
130+
* @param {ICancelParams & ICancelBody} params Os parâmetros de envio.
131131
*
132132
* @returns {Promise<null>}
133133
* @throws {BlingApiException|BlingInternalException}
134134
*
135135
* @see https://developer.bling.com.br/referencia#/Notas%20Fiscais%20de%20Servi%C3%A7o%20Eletr%C3%B4nicas/post_nfse__idNotaServico__cancelar
136136
*/
137-
public async cancel(params: ICancelParams): Promise<null> {
137+
public async cancel(params: ICancelParams & ICancelBody): Promise<null> {
138+
const { idNotaServico, ...body } = params
138139
return await this.repository.store({
139-
endpoint: `nfse/${params.idNotaServico}/cancelar`,
140-
body: {}
140+
endpoint: `nfse/${idNotaServico}/cancelar`,
141+
body
141142
})
142143
}
143144

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import { ICancelarCodigoMotivo } from "../types/cancelar-codigo-motivo.type"
2+
13
export interface ICancelParams {
24
/**
35
* ID da nota de serviço
46
*/
57
idNotaServico: number
68
}
9+
10+
export interface ICancelBody {
11+
codigoMotivo?: ICancelarCodigoMotivo
12+
justificativa?: string
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* - `1`: Erro na Emissão
3+
* - `2`: Serviço não Prestado
4+
* - `9`: Outros
5+
*/
6+
export type ICancelarCodigoMotivo =
7+
| 1
8+
| 2
9+
| 9

0 commit comments

Comments
 (0)