Skip to content

Commit

Permalink
feat: atualizar logisticas - etiquetas conforme v291
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Dec 15, 2023
1 parent 92b627c commit a7ca92b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/entities/logisticasEtiquetas/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)
})
Expand Down
13 changes: 7 additions & 6 deletions src/entities/logisticasEtiquetas/index.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<IGetResponse>}
* @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<IGetResponse> {
const { formato, ...body } = params
public async get(params: IGetParams): Promise<IGetResponse> {
return await this.repository.index({
endpoint: 'logisticas/etiquetas',
body,
params: { formato }
params: {
formato: params.formato,
idsVendas: params.idsVendas
}
})
}
}
5 changes: 1 addition & 4 deletions src/entities/logisticasEtiquetas/interfaces/get.interface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { IFormato } from '../types/formato.type'

export interface IGetParams {
formato?: IFormato
}

export interface IGetBody {
formato: IFormato
idsVendas: number[]
}

Expand Down
4 changes: 2 additions & 2 deletions src/entities/naturezasDeOperacoes/__tests__/get-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
]
Expand Down
9 changes: 9 additions & 0 deletions src/entities/naturezasDeOperacoes/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 () => {
Expand All @@ -54,5 +59,9 @@ describe('Naturezas de Operação entity', () => {
body: calculateItemTaxRequestBody
})
expect(response).toBe(calculateItemTaxResponse)

const typingResponseTest: ICalculateItemTaxResponse =
calculateItemTaxResponse
expect(typingResponseTest).toBe(calculateItemTaxResponse)
})
})

0 comments on commit a7ca92b

Please sign in to comment.