Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: atualizar para v292 #22

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `v291` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-01-31)).
Atualizado com a versão `v292` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-01-31)).

**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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bling-erp-api",
"version": "5.2.0",
"version": "5.3.0",
"description": "Pacote de integração com a API do Bling ERP",
"main": "lib/bling.js",
"directories": {
Expand Down Expand Up @@ -67,4 +67,4 @@
"publishConfig": {
"access": "public"
}
}
}
84 changes: 84 additions & 0 deletions src/entities/nfces/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { Chance } from 'chance'
import { Nfces } 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 { ISendResponse } from '../interfaces/send.interface'
import { IUpdateResponse } from '../interfaces/update.interface'
import createResponse, { createRequestBody } from './create-response'
import findResponse from './find-response'
import getResponse from './get-response'
import postAccountsResponse from './post-accounts-response'
import postStockResponse from './post-stock-response'
import postStockToDepositResponse from './post-stock-to-deposit-response'
import reverseAccountsResponse from './reverse-accounts-response'
import reverseStockResponse from './reverse-stock-response'
import sendResponse from './send-response'
import updateResponse, { updateRequestBody } from './update-response'

Expand Down Expand Up @@ -41,6 +49,9 @@ describe('NFC-es entity', () => {
}
})
expect(response).toBe(getResponse)

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

it('should find successfully', async () => {
Expand All @@ -55,6 +66,9 @@ describe('NFC-es entity', () => {
id: String(idNotaFiscalConsumidor)
})
expect(response).toBe(findResponse)

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

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

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

it('should send successfully', async () => {
Expand All @@ -82,6 +99,9 @@ describe('NFC-es entity', () => {
body: {}
})
expect(response).toBe(sendResponse)

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

it('should post accounts successfully', async () => {
Expand All @@ -96,6 +116,9 @@ describe('NFC-es entity', () => {
body: {}
})
expect(response).toBe(postAccountsResponse)

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

it('should reverse accounts successfully', async () => {
Expand All @@ -110,6 +133,64 @@ describe('NFC-es entity', () => {
body: {}
})
expect(response).toBe(reverseAccountsResponse)

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

it('should post stock successfully', async () => {
const spy = jest.spyOn(repository, 'store')
const idNotaFiscalConsumidor = chance.natural()
repository.setResponse(postStockResponse)

const response = await entity.postStock({ idNotaFiscalConsumidor })

expect(spy).toHaveBeenCalledWith({
endpoint: `nfce/${idNotaFiscalConsumidor}/lancar-estoque`,
body: {}
})
expect(response).toBe(postStockResponse)

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

it('should post stock to deposit successfully', async () => {
const spy = jest.spyOn(repository, 'store')
const idNotaFiscalConsumidor = chance.natural()
const idDeposito = chance.natural()
repository.setResponse(postStockToDepositResponse)

const response = await entity.postStockToDeposit({
idNotaFiscalConsumidor,
idDeposito
})

expect(spy).toHaveBeenCalledWith({
endpoint: `nfce/${idNotaFiscalConsumidor}/lancar-estoque/${idDeposito}`,
body: {}
})
expect(response).toBe(postStockToDepositResponse)

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

it('should reverse stock successfully', async () => {
const spy = jest.spyOn(repository, 'store')
const idNotaFiscalConsumidor = chance.natural()
repository.setResponse(reverseStockResponse)

const response = await entity.reverseStock({ idNotaFiscalConsumidor })

expect(spy).toHaveBeenCalledWith({
endpoint: `nfce/${idNotaFiscalConsumidor}/estornar-estoque`,
body: {}
})
expect(response).toBe(reverseStockResponse)

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

it('should update successfully', async () => {
Expand All @@ -128,5 +209,8 @@ describe('NFC-es entity', () => {
body: updateRequestBody
})
expect(response).toBe(updateResponse)

const typingResponseTest: IUpdateResponse = updateResponse
expect(typingResponseTest).toBe(updateResponse)
})
})
1 change: 1 addition & 0 deletions src/entities/nfces/__tests__/post-stock-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null
1 change: 1 addition & 0 deletions src/entities/nfces/__tests__/reverse-stock-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null
7 changes: 6 additions & 1 deletion src/entities/nfces/__tests__/update-response.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export default {
data: {
id: 12345678
id: 12345678,
numero: '6541',
serie: '1',
contato: {
nome: 'Contato do Bling'
}
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/entities/nfces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { ICreateBody, ICreateResponse } from './interfaces/create.interface'
import { IFindParams, IFindResponse } from './interfaces/find.interface'
import { IGetParams, IGetResponse } from './interfaces/get.interface'
import { IPostAccountsParams } from './interfaces/post-accounts.interface'
import { IPostStockToDepositParams } from './interfaces/post-stock-to-deposit.interface'
import { IPostStockParams } from './interfaces/post-stock.interface'
import { IReverseAccountsParams } from './interfaces/reverse-accounts.interface'
import { IReverseStockParams } from './interfaces/reverse-stock.interface'
import { ISendParams, ISendResponse } from './interfaces/send.interface'
import {
IUpdateBody,
Expand Down Expand Up @@ -129,6 +132,59 @@ export class Nfces extends Entity {
})
}

/**
* Lança o estoque de uma nota fiscal no depósito padrão.
*
* @param {IPostStockParams} params O conteúdo para o lançamento.
*
* @returns {Promise<null>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Notas%20Fiscais%20de%20Consumidor%20Eletr%C3%B4nicas/post_nfce__idNotaFiscalConsumidor__lancar_estoque
*/
public async postStock(params: IPostStockParams): Promise<null> {
return await this.repository.store({
endpoint: `nfce/${params.idNotaFiscalConsumidor}/lancar-estoque`,
body: {}
})
}

/**
* Lança o estoque de uma nota fiscal especificando o depósito.
*
* @param {IPostStockToDepositParams} params O conteúdo para o lançamento.
*
* @returns {Promise<null>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Notas%20Fiscais%20de%20Consumidor%20Eletr%C3%B4nicas/post_nfce__idNotaFiscalConsumidor__lancar_estoque__idDeposito_
*/
public async postStockToDeposit(
params: IPostStockToDepositParams
): Promise<null> {
return await this.repository.store({
endpoint: `nfce/${params.idNotaFiscalConsumidor}/lancar-estoque/${params.idDeposito}`,
body: {}
})
}

/**
* Estorna o estoque de uma nota fiscal.
*
* @param {IReverseStockParams} params O conteúdo para o estorno.
*
* @returns {Promise<null>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Notas%20Fiscais%20de%20Consumidor%20Eletr%C3%B4nicas/post_nfce__idNotaFiscalConsumidor__estornar_estoque
*/
public async reverseStock(params: IReverseStockParams): Promise<null> {
return await this.repository.store({
endpoint: `nfce/${params.idNotaFiscalConsumidor}/estornar-estoque`,
body: {}
})
}

/**
* Altera uma nota fiscal de consumidor.
*
Expand Down
10 changes: 10 additions & 0 deletions src/entities/nfces/interfaces/post-stock-to-deposit.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface IPostStockToDepositParams {
/**
* ID da nota fiscal de consumidor
*/
idNotaFiscalConsumidor: number
/**
* ID do depósito
*/
idDeposito: number
}
6 changes: 6 additions & 0 deletions src/entities/nfces/interfaces/post-stock.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface IPostStockParams {
/**
* ID da nota fiscal de consumidor
*/
idNotaFiscalConsumidor: number
}
6 changes: 6 additions & 0 deletions src/entities/nfces/interfaces/reverse-stock.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface IReverseStockParams {
/**
* ID da nota fiscal de consumidor
*/
idNotaFiscalConsumidor: number
}
Loading