-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adicionar logisticas - remessas
- Loading branch information
1 parent
64e8275
commit 92b627c
Showing
17 changed files
with
483 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/entities/logisticasRemessas/__tests__/create-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default { | ||
data: { | ||
id: 12345678 | ||
} | ||
} | ||
|
||
export const createRequestBody = { | ||
numeroPlp: '749fdc73', | ||
situacao: -3 as const, | ||
descricao: 'Remessa_18092023', | ||
logistica: { | ||
id: 12345678 | ||
}, | ||
objetos: ['12'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default null |
56 changes: 56 additions & 0 deletions
56
src/entities/logisticasRemessas/__tests__/find-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
export default { | ||
data: { | ||
id: 12345678, | ||
numeroPlp: '749fdc73', | ||
situacao: -3 as const, | ||
descricao: 'Remessa_18092023', | ||
dataCriacao: '2023-09-18', | ||
logistica: { | ||
id: 12345678 | ||
}, | ||
objetos: [ | ||
{ | ||
id: 1235456, | ||
remessa: { | ||
id: 12345678 | ||
}, | ||
pedidoVenda: { | ||
id: 12345678 | ||
}, | ||
notaFiscal: { | ||
id: 12345678 | ||
}, | ||
servico: { | ||
id: 12345678, | ||
nome: 'SEDEX 10 A VISTA', | ||
codigo: '04790' | ||
}, | ||
rastreamento: { | ||
codigo: 'EC272330554BR', | ||
descricao: 'Criado', | ||
situacao: 1 as const, | ||
origem: 'São Paulo, SP', | ||
destino: 'São Paulo, SP', | ||
ultimaAlteracao: '2020-11-11 16:40:33', | ||
url: 'https://www.rastreamento.exemplo.com.br/EC272330554BR' | ||
}, | ||
dimensao: { | ||
peso: 1.5, | ||
altura: 1.5, | ||
largura: 1.5, | ||
comprimento: 1.5, | ||
diametro: 1.5 | ||
}, | ||
embalagem: { | ||
id: 12345678 | ||
}, | ||
dataSaida: '2022-12-01', | ||
prazoEntregaPrevisto: 15, | ||
fretePrevisto: 59.9, | ||
valorDeclarado: 55.9, | ||
avisoRecebimento: false, | ||
maoPropria: false | ||
} | ||
] | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/entities/logisticasRemessas/__tests__/get-by-logistic-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default { | ||
data: [ | ||
{ | ||
id: 12345678, | ||
numeroPlp: '749fdc73', | ||
situacao: -3 as const, | ||
descricao: 'Remessa_18092023', | ||
dataCriacao: '2023-09-18', | ||
objetos: [6423813145] | ||
} | ||
] | ||
} |
116 changes: 116 additions & 0 deletions
116
src/entities/logisticasRemessas/__tests__/index.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { Chance } from 'chance' | ||
import { LogisticasRemessas } from '..' | ||
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository' | ||
import { ICreateResponse } from '../interfaces/create.interface' | ||
import { IFindResponse } from '../interfaces/find.interface' | ||
import { IGetByLogisticResponse } from '../interfaces/get-by-logistic.interface' | ||
import { IUpdateResponse } from '../interfaces/update.interface' | ||
import createResponse, { createRequestBody } from './create-response' | ||
import deleteResponse from './delete-response' | ||
import findResponse from './find-response' | ||
import getByLogisticResponse from './get-by-logistic-response' | ||
import updateResponse, { updateRequestBody } from './update-response' | ||
|
||
const chance = Chance() | ||
|
||
describe('Logísticas - Remessas entity', () => { | ||
let repository: InMemoryBlingRepository | ||
let entity: LogisticasRemessas | ||
|
||
beforeEach(() => { | ||
repository = new InMemoryBlingRepository() | ||
entity = new LogisticasRemessas(repository) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('should delete successfully', async () => { | ||
const idRemessa = chance.natural() | ||
const spy = jest.spyOn(repository, 'destroy') | ||
repository.setResponse(deleteResponse) | ||
|
||
const response = await entity.delete({ idRemessa }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'logisticas/remessas', | ||
id: String(idRemessa) | ||
}) | ||
expect(response).toBe(deleteResponse) | ||
|
||
const typingResponseTest: null = deleteResponse | ||
expect(typingResponseTest).toBe(deleteResponse) | ||
}) | ||
|
||
it('should find successfully', async () => { | ||
const spy = jest.spyOn(repository, 'show') | ||
const idRemessa = chance.natural() | ||
repository.setResponse(findResponse) | ||
|
||
const response = await entity.find({ idRemessa }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'logisticas/remessas', | ||
id: String(idRemessa) | ||
}) | ||
expect(response).toBe(findResponse) | ||
|
||
const typingResponseTest: IFindResponse = findResponse | ||
expect(typingResponseTest).toBe(findResponse) | ||
}) | ||
|
||
it('should get by logistic successfully', async () => { | ||
const spy = jest.spyOn(repository, 'show') | ||
const idLogistica = chance.natural() | ||
repository.setResponse(getByLogisticResponse) | ||
|
||
const response = await entity.getByLogistic({ idLogistica }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'logisticas', | ||
id: `${idLogistica}/remessas` | ||
}) | ||
expect(response).toBe(getByLogisticResponse) | ||
|
||
const typingResponseTest: IGetByLogisticResponse = getByLogisticResponse | ||
expect(typingResponseTest).toBe(getByLogisticResponse) | ||
}) | ||
|
||
it('should create successfully', async () => { | ||
const spy = jest.spyOn(repository, 'store') | ||
repository.setResponse(createResponse) | ||
|
||
const response = await entity.create(createRequestBody) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'logisticas/remessas', | ||
body: createRequestBody | ||
}) | ||
expect(response).toBe(createResponse) | ||
|
||
const typingResponseTest: ICreateResponse = createResponse | ||
expect(typingResponseTest).toBe(createResponse) | ||
}) | ||
|
||
it('should update successfully', async () => { | ||
const spy = jest.spyOn(repository, 'replace') | ||
const idRemessa = chance.natural() | ||
repository.setResponse(updateResponse) | ||
|
||
const response = await entity.update({ | ||
idRemessa, | ||
...updateRequestBody | ||
}) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'logisticas/remessas', | ||
id: String(idRemessa), | ||
body: updateRequestBody | ||
}) | ||
expect(response).toBe(updateResponse) | ||
|
||
const typingResponseTest: IUpdateResponse = updateResponse | ||
expect(typingResponseTest).toBe(updateResponse) | ||
}) | ||
}) |
11 changes: 11 additions & 0 deletions
11
src/entities/logisticasRemessas/__tests__/update-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default { | ||
data: { | ||
id: 12345678 | ||
} | ||
} | ||
|
||
export const updateRequestBody = { | ||
numeroPlp: '749fdc73', | ||
situacao: -3 as const, | ||
descricao: 'Remessa_18092023' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { Entity } from '../@shared/entity' | ||
import { ICreateBody, ICreateResponse } from './interfaces/create.interface' | ||
import { IDeleteParams } from './interfaces/delete.interface' | ||
import { IFindParams, IFindResponse } from './interfaces/find.interface' | ||
import { | ||
IGetByLogisticParams, | ||
IGetByLogisticResponse | ||
} from './interfaces/get-by-logistic.interface' | ||
import { | ||
IUpdateBody, | ||
IUpdateParams, | ||
IUpdateResponse | ||
} from './interfaces/update.interface' | ||
|
||
/** | ||
* Entidade para interação com Logísticas - Remessas. | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Log%C3%ADsticas%20-%20Remessas | ||
*/ | ||
export class LogisticasRemessas extends Entity { | ||
/** | ||
* Remove uma remessa de postagem. | ||
* | ||
* @param {IDeleteParams} params Parâmetros da remoção. | ||
* | ||
* @returns {Promise<null>} Não há retorno. | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Log%C3%ADsticas%20-%20Remessas/delete_logisticas_remessas__idRemessa_ | ||
*/ | ||
public async delete(params: IDeleteParams): Promise<null> { | ||
return await this.repository.destroy({ | ||
endpoint: 'logisticas/remessas', | ||
id: String(params.idRemessa) | ||
}) | ||
} | ||
|
||
/** | ||
* Obtém uma remessa de postagem. | ||
* | ||
* @param {IFindParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IFindResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Log%C3%ADsticas%20-%20Remessas/get_logisticas_remessas__idRemessa_ | ||
*/ | ||
public async find(params: IFindParams): Promise<IFindResponse> { | ||
return await this.repository.show({ | ||
endpoint: 'logisticas/remessas', | ||
id: String(params.idRemessa) | ||
}) | ||
} | ||
|
||
/** | ||
* Obtém as remessas de postagem de uma logística. | ||
* | ||
* @param {IGetByLogisticParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IGetByLogisticResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Log%C3%ADsticas%20-%20Remessas/get_logisticas__idLogistica__remessas | ||
*/ | ||
public async getByLogistic( | ||
params: IGetByLogisticParams | ||
): Promise<IGetByLogisticResponse> { | ||
return await this.repository.show({ | ||
endpoint: 'logisticas', | ||
id: `${params.idLogistica}/remessas` | ||
}) | ||
} | ||
|
||
/** | ||
* Cria uma remessa de postagem de uma logística. | ||
* | ||
* @param {ICreateBody} body O conteúdo para a criação. | ||
* | ||
* @returns {Promise<ICreateResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Log%C3%ADsticas%20-%20Remessas/post_logisticas_remessas | ||
*/ | ||
public async create(body: ICreateBody): Promise<ICreateResponse> { | ||
return await this.repository.store({ | ||
endpoint: 'logisticas/remessas', | ||
body | ||
}) | ||
} | ||
|
||
/** | ||
* Altera uma remessa de postagem. | ||
* | ||
* @param {IUpdateParams & IUpdateBody} params Os parâmetros da atualização. | ||
* | ||
* @return {Promise<IUpdateResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Log%C3%ADsticas%20-%20Remessas/put_logisticas_remessas__idRemessa_ | ||
*/ | ||
public async update( | ||
params: IUpdateParams & IUpdateBody | ||
): Promise<IUpdateResponse> { | ||
const { idRemessa, ...body } = params | ||
|
||
return await this.repository.replace({ | ||
endpoint: 'logisticas/remessas', | ||
id: String(idRemessa), | ||
body | ||
}) | ||
} | ||
} |
Oops, something went wrong.