-
-
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
84d29d5
commit d266eeb
Showing
13 changed files
with
325 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default { | ||
data: { | ||
id: 12345678 | ||
} | ||
} | ||
|
||
export const createRequestBody = { | ||
idModuloSistema: 6423808065, | ||
nome: 'Finalizado', | ||
idHerdado: 0, | ||
cor: '#E9DC40' | ||
} |
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,8 @@ | ||
export default { | ||
data: { | ||
id: 9, | ||
nome: 'Em aberto', | ||
idHerdado: 0, | ||
cor: '#E9DC40' | ||
} | ||
} |
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,82 @@ | ||
import { Chance } from 'chance' | ||
import { Situacoes } from '..' | ||
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository' | ||
import createResponse, { createRequestBody } from './create-response' | ||
import deleteResponse from './delete-response' | ||
import findResponse from './find-response' | ||
import updateResponse, { updateRequestBody } from './update-response' | ||
|
||
const chance = Chance() | ||
|
||
describe('Situacoes entity', () => { | ||
let repository: InMemoryBlingRepository | ||
let entity: Situacoes | ||
|
||
beforeEach(() => { | ||
repository = new InMemoryBlingRepository() | ||
entity = new Situacoes(repository) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('should delete successfully', async () => { | ||
const idSituacao = chance.natural() | ||
const spy = jest.spyOn(repository, 'destroy') | ||
repository.setResponse(deleteResponse) | ||
|
||
const response = await entity.delete({ idSituacao }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'situacoes', | ||
id: String(idSituacao) | ||
}) | ||
expect(response).toBe(deleteResponse) | ||
}) | ||
|
||
it('should find successfully', async () => { | ||
const spy = jest.spyOn(repository, 'show') | ||
const idSituacao = chance.natural() | ||
repository.setResponse(findResponse) | ||
|
||
const response = await entity.find({ idSituacao }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'situacoes', | ||
id: String(idSituacao) | ||
}) | ||
expect(response).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: 'situacoes', | ||
body: createRequestBody | ||
}) | ||
expect(response).toBe(createResponse) | ||
}) | ||
|
||
it('should update successfully', async () => { | ||
const spy = jest.spyOn(repository, 'replace') | ||
const idSituacao = chance.natural() | ||
repository.setResponse(updateResponse) | ||
|
||
const response = await entity.update({ | ||
idSituacao, | ||
...updateRequestBody | ||
}) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'situacoes', | ||
id: String(idSituacao), | ||
body: updateRequestBody | ||
}) | ||
expect(response).toBe(updateResponse) | ||
}) | ||
}) |
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,68 @@ | ||
export default { | ||
data: { | ||
id: 12345678 | ||
} | ||
} | ||
|
||
export const updateRequestBody = { | ||
descricao: 'Alugel do apartamento A102', | ||
data: '2023-02-19', | ||
numero: '25', | ||
valor: 59.99, | ||
situacao: 1 as const, | ||
contato: { | ||
id: 12345678 | ||
}, | ||
dataFim: '2024-05', | ||
tipoManutencao: 1 as const, | ||
emitirOrdemServico: false, | ||
observacoes: '', | ||
vendedor: { | ||
id: 12345678, | ||
comissao: { | ||
aliquota: 0.5, | ||
numeroParcelas: 1 | ||
} | ||
}, | ||
categoria: { | ||
id: 12345678 | ||
}, | ||
desconto: { | ||
valor: 4.99, | ||
dataFim: '2023-02' | ||
}, | ||
contaContabil: { | ||
id: 12345678 | ||
}, | ||
formaPagamento: { | ||
id: 12345678 | ||
}, | ||
notaFiscal: { | ||
mes: 2 as const, | ||
gerar: 1 as const, | ||
descontarImpostoRenda: 1 as const, | ||
texto: 'Exemplo de texto.', | ||
cfop: '5.556', | ||
iss: { | ||
descontar: false, | ||
aliquota: 2.5 | ||
}, | ||
item: { | ||
codigoServico: '14.13', | ||
produto: { | ||
id: 12345678 | ||
} | ||
} | ||
}, | ||
cobranca: { | ||
dataBase: '2023-02-22', | ||
contato: { | ||
id: 12345678 | ||
}, | ||
vencimento: { | ||
tipo: 1 as const, | ||
dia: 10, | ||
periodicidade: 1 as const | ||
} | ||
} | ||
} |
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,89 @@ | ||
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 { | ||
IUpdateBody, | ||
IUpdateParams, | ||
IUpdateResponse | ||
} from './interfaces/update.interface' | ||
|
||
/** | ||
* Entidade para interação com situações. | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Situa%C3%A7%C3%B5es | ||
*/ | ||
export class Situacoes extends Entity { | ||
/** | ||
* Remove uma situação. | ||
* | ||
* @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#/Situa%C3%A7%C3%B5es/delete_situacoes__idSituacao_ | ||
*/ | ||
public async delete(params: IDeleteParams): Promise<null> { | ||
return await this.repository.destroy({ | ||
endpoint: 'situacoes', | ||
id: String(params.idSituacao) | ||
}) | ||
} | ||
|
||
/** | ||
* Obtém uma situação. | ||
* | ||
* @param {IFindParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IFindResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Situa%C3%A7%C3%B5es/get_situacoes__idSituacao_ | ||
*/ | ||
public async find(params: IFindParams): Promise<IFindResponse> { | ||
return await this.repository.show({ | ||
endpoint: 'situacoes', | ||
id: String(params.idSituacao) | ||
}) | ||
} | ||
|
||
/** | ||
* Cria uma situação. | ||
* | ||
* @param {ICreateBody} body O conteúdo para a criação. | ||
* | ||
* @returns {Promise<ICreateResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Situa%C3%A7%C3%B5es/post_situacoes | ||
*/ | ||
public async create(body: ICreateBody): Promise<ICreateResponse> { | ||
return await this.repository.store({ | ||
endpoint: 'situacoes', | ||
body | ||
}) | ||
} | ||
|
||
/** | ||
* Altera uma situação. | ||
* | ||
* @param {IUpdateParams & IUpdateBody} params Os parâmetros da atualização. | ||
* | ||
* @return {Promise<IUpdateResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Situa%C3%A7%C3%B5es/put_situacoes__idSituacao_ | ||
*/ | ||
public async update( | ||
params: IUpdateParams & IUpdateBody | ||
): Promise<IUpdateResponse> { | ||
const { idSituacao, ...body } = params | ||
|
||
return await this.repository.replace({ | ||
endpoint: 'situacoes', | ||
id: String(idSituacao), | ||
body | ||
}) | ||
} | ||
} |
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,10 @@ | ||
export interface ICreateBody { | ||
idModuloSistema?: number | ||
nome?: string | ||
idHerdado?: number | ||
cor?: string | ||
} | ||
|
||
export interface ICreateResponse { | ||
data: { id: number } | ||
} |
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,6 @@ | ||
export interface IDeleteParams { | ||
/** | ||
* ID da situação | ||
*/ | ||
idSituacao: number | ||
} |
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 interface IFindParams { | ||
/** | ||
* ID da situação | ||
*/ | ||
idSituacao: number | ||
} | ||
|
||
export interface IFindResponse { | ||
data: { | ||
id: number | ||
nome: string | ||
idHerdado?: number | ||
cor?: string | ||
} | ||
} |
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,17 @@ | ||
export interface IUpdateParams { | ||
/** | ||
* ID da situação | ||
*/ | ||
idSituacao: number | ||
} | ||
|
||
export interface IUpdateBody { | ||
idModuloSistema?: number | ||
nome?: string | ||
idHerdado?: number | ||
cor?: string | ||
} | ||
|
||
export interface IUpdateResponse { | ||
data: { id: number } | ||
} |