From a7ca92b356d6b542b59bd97cc633d3ff966c314d Mon Sep 17 00:00:00 2001 From: Alexandre Batistella Bellas Date: Fri, 15 Dec 2023 19:01:35 -0300 Subject: [PATCH] feat: atualizar logisticas - etiquetas conforme v291 --- .../logisticasEtiquetas/__tests__/index.spec.ts | 7 ++++--- src/entities/logisticasEtiquetas/index.ts | 13 +++++++------ .../logisticasEtiquetas/interfaces/get.interface.ts | 5 +---- .../naturezasDeOperacoes/__tests__/get-response.ts | 4 ++-- .../naturezasDeOperacoes/__tests__/index.spec.ts | 9 +++++++++ 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/entities/logisticasEtiquetas/__tests__/index.spec.ts b/src/entities/logisticasEtiquetas/__tests__/index.spec.ts index cb3154c..9abc517 100644 --- a/src/entities/logisticasEtiquetas/__tests__/index.spec.ts +++ b/src/entities/logisticasEtiquetas/__tests__/index.spec.ts @@ -1,6 +1,7 @@ import { Chance } from 'chance' import { LogisticasEtiquetas } from '..' import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository' +import { IFormato } from '../types/formato.type' import getResponse from './get-response' const chance = Chance() @@ -21,17 +22,17 @@ describe('Logísticas - Etiquetas entity', () => { it('should get successfully', async () => { const spy = jest.spyOn(repository, 'index') repository.setResponse(getResponse) + const formato = chance.pickone(['PDF', 'ZPL']) as IFormato const idsVendas: number[] = [] for (let i = 0; i < chance.natural({ min: 1, max: 5 }) + 1; i++) { idsVendas.push(chance.natural()) } - const response = await entity.get({ idsVendas }) + const response = await entity.get({ formato, idsVendas }) expect(spy).toHaveBeenCalledWith({ endpoint: 'logisticas/etiquetas', - body: { idsVendas }, - params: { formato: undefined } + params: { formato, idsVendas } }) expect(response).toBe(getResponse) }) diff --git a/src/entities/logisticasEtiquetas/index.ts b/src/entities/logisticasEtiquetas/index.ts index 7f1e0f2..b7bd330 100644 --- a/src/entities/logisticasEtiquetas/index.ts +++ b/src/entities/logisticasEtiquetas/index.ts @@ -1,5 +1,5 @@ import { Entity } from '../@shared/entity' -import { IGetBody, IGetParams, IGetResponse } from './interfaces/get.interface' +import { IGetParams, IGetResponse } from './interfaces/get.interface' /** * Entidade para interação com logísticas - etiquetas. @@ -10,19 +10,20 @@ export class LogisticasEtiquetas extends Entity { /** * Obtém etiquetas das vendas. * - * @param {IGetParams & IGetBody} params Parâmetros da busca. + * @param {IGetParams} params Parâmetros da busca. * * @returns {Promise} * @throws {BlingApiException|BlingInternalException} * * @see https://developer.bling.com.br/referencia#/Log%C3%ADsticas%20-%20Etiquetas/get_logisticas_etiquetas */ - public async get(params: IGetParams & IGetBody): Promise { - const { formato, ...body } = params + public async get(params: IGetParams): Promise { return await this.repository.index({ endpoint: 'logisticas/etiquetas', - body, - params: { formato } + params: { + formato: params.formato, + idsVendas: params.idsVendas + } }) } } diff --git a/src/entities/logisticasEtiquetas/interfaces/get.interface.ts b/src/entities/logisticasEtiquetas/interfaces/get.interface.ts index 900c9e7..b160c63 100644 --- a/src/entities/logisticasEtiquetas/interfaces/get.interface.ts +++ b/src/entities/logisticasEtiquetas/interfaces/get.interface.ts @@ -1,10 +1,7 @@ import { IFormato } from '../types/formato.type' export interface IGetParams { - formato?: IFormato -} - -export interface IGetBody { + formato: IFormato idsVendas: number[] } diff --git a/src/entities/naturezasDeOperacoes/__tests__/get-response.ts b/src/entities/naturezasDeOperacoes/__tests__/get-response.ts index 0926f91..8b475de 100644 --- a/src/entities/naturezasDeOperacoes/__tests__/get-response.ts +++ b/src/entities/naturezasDeOperacoes/__tests__/get-response.ts @@ -2,8 +2,8 @@ export default { data: [ { id: 12345678, - situacao: 1, - padrao: 1, + situacao: 1 as const, + padrao: 1 as const, descricao: 'Compra de Mercadoria' } ] diff --git a/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts b/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts index 52bdeab..478d472 100644 --- a/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts +++ b/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts @@ -1,6 +1,8 @@ import { Chance } from 'chance' import { NaturezasDeOperacoes } from '..' import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository' +import { ICalculateItemTaxResponse } from '../interfaces/calculate-item-tax.interface' +import { IGetResponse } from '../interfaces/get.interface' import calculateItemTaxResponse, { calculateItemTaxRequestBody } from './calculate-item-tax-response' @@ -37,6 +39,9 @@ describe('Naturezas de Operação entity', () => { } }) expect(response).toBe(getResponse) + + const typingResponseTest: IGetResponse = getResponse + expect(typingResponseTest).toBe(getResponse) }) it('should calculate item tax successfully', async () => { @@ -54,5 +59,9 @@ describe('Naturezas de Operação entity', () => { body: calculateItemTaxRequestBody }) expect(response).toBe(calculateItemTaxResponse) + + const typingResponseTest: ICalculateItemTaxResponse = + calculateItemTaxResponse + expect(typingResponseTest).toBe(calculateItemTaxResponse) }) })