-
-
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.
- Loading branch information
1 parent
24e5cb6
commit 00eb294
Showing
30 changed files
with
825 additions
and
38 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export default { | ||
data: { | ||
nome: 'Empresa Teste LTDA', | ||
cnpj: '12.345.657/8910-11', | ||
email: 'empresa@email.com' | ||
id: "436c56a5679921f5f13a3d6433561773", | ||
nome: "Empresa Teste LTDA", | ||
cnpj: "12.345.657/8910-11", | ||
email: "empresa@email.com", | ||
dataContrato: "2024-12-31" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export interface IMeResponse { | ||
data: { | ||
id: string | ||
nome: string | ||
cnpj: string | ||
email: string | ||
dataContrato: string | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/entities/ordensDeProducao/__tests__/change-situation-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,8 @@ | ||
export default null | ||
|
||
export const changeSituationRequest = { | ||
idSituacao: 12345678, | ||
quantidade: 1, | ||
observacoes: "Observação", | ||
considerarPerdas: true | ||
} |
30 changes: 30 additions & 0 deletions
30
src/entities/ordensDeProducao/__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,30 @@ | ||
export default { | ||
data: { | ||
id: 12345678 | ||
} | ||
} | ||
|
||
export const createRequestBody = { | ||
dataPrevisaoInicio: "2021-01-01", | ||
dataPrevisaoFinal: "2021-01-01", | ||
dataInicio: "2021-01-01", | ||
dataFim: "2021-01-01", | ||
numero: 12345678, | ||
responsavel: "Responsável pela ordem de produção", | ||
deposito: { | ||
idDestino: 12345678, | ||
idOrigem: 12345678 | ||
}, | ||
situacao: { | ||
id: 12345678 | ||
}, | ||
itens: [ | ||
{ | ||
produto: { | ||
id: 12345678 | ||
}, | ||
quantidade: 1 | ||
} | ||
], | ||
observacoes: "Observações" | ||
} |
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 |
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,38 @@ | ||
export default { | ||
id: 12345678, | ||
dataPrevisaoInicio: "2021-01-01", | ||
dataPrevisaoFinal: "2021-01-01", | ||
dataInicio: "2021-01-01", | ||
dataFim: "2021-01-01", | ||
numero: 12345678, | ||
responsavel: "Responsável pela ordem de produção", | ||
deposito: { | ||
idDestino: 12345678, | ||
idOrigem: 12345678 | ||
}, | ||
situacao: { | ||
id: 12345678, | ||
valor: 1, | ||
nome: "Em aberto" | ||
}, | ||
vendas: [ | ||
{ | ||
numero: 12345678, | ||
contato: { | ||
id: 12345678, | ||
nome: "João da Silva" | ||
} | ||
} | ||
], | ||
itens: [ | ||
{ | ||
produto: { | ||
id: 12345678, | ||
nome: "Nome do produto", | ||
codigo: "Código do produto" | ||
}, | ||
quantidade: 1 | ||
} | ||
], | ||
observacoes: "Observações" | ||
} |
21 changes: 21 additions & 0 deletions
21
src/entities/ordensDeProducao/__tests__/generate-over-demand-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,21 @@ | ||
export default { | ||
data: [ | ||
{ | ||
id: 12345678, | ||
itens: [ | ||
{ | ||
produto: { | ||
id: 12345678, | ||
nome: "Nome do produto", | ||
codigo: "Código do produto" | ||
}, | ||
quantidade: 1 | ||
} | ||
], | ||
deposito: { | ||
idDestino: 12345678, | ||
idOrigem: 12345678 | ||
} | ||
} | ||
] | ||
} |
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,22 @@ | ||
export default { | ||
data: [ | ||
{ | ||
id: 12345678, | ||
dataPrevisaoInicio: "2021-01-01", | ||
dataPrevisaoFinal: "2021-01-01", | ||
dataInicio: "2021-01-01", | ||
dataFim: "2021-01-01", | ||
numero: 12345678, | ||
responsavel: "Responsável pela ordem de produção", | ||
deposito: { | ||
idDestino: 12345678, | ||
idOrigem: 12345678 | ||
}, | ||
situacao: { | ||
id: 12345678, | ||
valor: 1, | ||
nome: "Em aberto" | ||
} | ||
} | ||
] | ||
} |
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,160 @@ | ||
import { Chance } from 'chance' | ||
import { OrdensDeProducao } 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 changeSituationResponse, { | ||
changeSituationRequest | ||
} from './change-situation-response' | ||
import createResponse, { createRequestBody } from './create-response' | ||
import deleteResponse from './delete-response' | ||
import findResponse from './find-response' | ||
import getResponse from './get-response' | ||
import updateResponse, { updateRequestBody } from './update-response' | ||
import generateOverDemandResponse from './generate-over-demand-response' | ||
import { IGenerateOverDemandResponse } from '../interfaces/generate-over-demand.interface' | ||
|
||
const chance = Chance() | ||
|
||
describe('OrdensDeProducao entity', () => { | ||
let repository: InMemoryBlingRepository | ||
let entity: OrdensDeProducao | ||
|
||
beforeEach(() => { | ||
repository = new InMemoryBlingRepository() | ||
entity = new OrdensDeProducao(repository) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('should delete successfully', async () => { | ||
const idOrdemProducao = chance.natural() | ||
const spy = jest.spyOn(repository, 'destroy') | ||
repository.setResponse(deleteResponse) | ||
|
||
const response = await entity.delete({ idOrdemProducao }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
id: String(idOrdemProducao) | ||
}) | ||
expect(response).toBe(deleteResponse) | ||
|
||
const typingResponseTest: null = deleteResponse | ||
expect(typingResponseTest).toBe(deleteResponse) | ||
}) | ||
|
||
it('should get successfully', async () => { | ||
const spy = jest.spyOn(repository, 'index') | ||
repository.setResponse(getResponse) | ||
|
||
const response = await entity.get() | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
params: { | ||
limite: undefined, | ||
pagina: undefined, | ||
idsSituacoes: undefined | ||
} | ||
}) | ||
expect(response).toBe(getResponse) | ||
|
||
const typingResponseTest: IGetResponse = getResponse | ||
expect(typingResponseTest).toBe(getResponse) | ||
}) | ||
|
||
it('should find successfully', async () => { | ||
const spy = jest.spyOn(repository, 'show') | ||
const idOrdemProducao = chance.natural() | ||
repository.setResponse(findResponse) | ||
|
||
const response = await entity.find({ idOrdemProducao }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
id: String(idOrdemProducao) | ||
}) | ||
expect(response).toBe(findResponse) | ||
|
||
const typingResponseTest: IFindResponse = findResponse | ||
expect(typingResponseTest).toBe(findResponse) | ||
}) | ||
|
||
it('should create successfully', async () => { | ||
const spy = jest.spyOn(repository, 'store') | ||
repository.setResponse(createResponse) | ||
|
||
const response = await entity.create(createRequestBody) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
body: createRequestBody | ||
}) | ||
expect(response).toBe(createResponse) | ||
|
||
const typingResponseTest: ICreateResponse = createResponse | ||
expect(typingResponseTest).toBe(createResponse) | ||
}) | ||
|
||
it('should generate over demand successfully', async () => { | ||
const spy = jest.spyOn(repository, 'store') | ||
repository.setResponse(generateOverDemandResponse) | ||
|
||
const response = await entity.generateOverDemand() | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao/gerar-sob-demanda', | ||
body: {} | ||
}) | ||
expect(response).toBe(generateOverDemandResponse) | ||
|
||
const typingResponseTest: IGenerateOverDemandResponse = generateOverDemandResponse | ||
expect(typingResponseTest).toBe(generateOverDemandResponse) | ||
}) | ||
|
||
it('should update successfully', async () => { | ||
const spy = jest.spyOn(repository, 'replace') | ||
const idOrdemProducao = chance.natural() | ||
repository.setResponse(updateResponse) | ||
|
||
const response = await entity.update({ | ||
idOrdemProducao, | ||
...updateRequestBody | ||
}) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
id: String(idOrdemProducao), | ||
body: updateRequestBody | ||
}) | ||
expect(response).toBe(updateResponse) | ||
|
||
const typingResponseTest: null = updateResponse | ||
expect(typingResponseTest).toBe(updateResponse) | ||
}) | ||
|
||
it('should change situation successfully', async () => { | ||
const spy = jest.spyOn(repository, 'update') | ||
const idOrdemProducao = chance.natural() | ||
repository.setResponse(changeSituationResponse) | ||
|
||
const response = await entity.changeSituation({ | ||
idOrdemProducao, | ||
...changeSituationRequest | ||
}) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
id: `${idOrdemProducao}/situacoes`, | ||
body: changeSituationRequest | ||
}) | ||
expect(response).toBe(changeSituationResponse) | ||
|
||
const typingResponseTest: null = changeSituationResponse | ||
expect(typingResponseTest).toBe(changeSituationResponse) | ||
}) | ||
}) |
Oops, something went wrong.