-
-
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
ad0a324
commit ee1bfc4
Showing
10 changed files
with
248 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,20 @@ | ||
export default { | ||
data: { | ||
id: 12345678, | ||
descontoLimite: 10.12, | ||
loja: { | ||
id: 12345678 | ||
}, | ||
contato: { | ||
id: 12345678, | ||
nome: 'Vendedor', | ||
situacao: 'A' | ||
}, | ||
comissoes: [ | ||
{ | ||
descontoMaximo: 10, | ||
aliquota: 2 | ||
} | ||
] | ||
} | ||
} |
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,14 @@ | ||
export default { | ||
data: { | ||
id: 12345678, | ||
descontoLimite: 10.12, | ||
loja: { | ||
id: 12345678 | ||
}, | ||
contato: { | ||
id: 12345678, | ||
nome: 'Vendedor', | ||
situacao: 'A' | ||
} | ||
} | ||
} |
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,57 @@ | ||
import { Chance } from 'chance' | ||
import { Vendedores } from '..' | ||
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository' | ||
import findResponse from './find-response' | ||
import getResponse from './get-response' | ||
|
||
const chance = Chance() | ||
|
||
describe('Vendedores entity', () => { | ||
let repository: InMemoryBlingRepository | ||
let entity: Vendedores | ||
|
||
beforeEach(() => { | ||
repository = new InMemoryBlingRepository() | ||
entity = new Vendedores(repository) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('should get successfully', async () => { | ||
const spy = jest.spyOn(repository, 'index') | ||
repository.setResponse(getResponse) | ||
|
||
const response = await entity.get() | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'vendedores', | ||
params: { | ||
limite: undefined, | ||
pagina: undefined, | ||
nomeContato: undefined, | ||
situacaoContato: undefined, | ||
idContato: undefined, | ||
idLoja: undefined, | ||
dataAlteracaoInicial: undefined, | ||
dataAlteracaoFinal: undefined | ||
} | ||
}) | ||
expect(response).toBe(getResponse) | ||
}) | ||
|
||
it('should find successfully', async () => { | ||
const spy = jest.spyOn(repository, 'show') | ||
const idVendedor = chance.natural() | ||
repository.setResponse(findResponse) | ||
|
||
const response = await entity.find({ idVendedor }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'vendedores', | ||
id: String(idVendedor) | ||
}) | ||
expect(response).toBe(findResponse) | ||
}) | ||
}) |
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,57 @@ | ||
import { Entity } from '../@shared/entity' | ||
import { IFindParams, IFindResponse } from './interfaces/find.interface' | ||
import { IGetParams, IGetResponse } from './interfaces/get.interface' | ||
|
||
/** | ||
* Entidade para interação com vendedores. | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Vendedores | ||
*/ | ||
export class Vendedores extends Entity { | ||
/** | ||
* Obtém vendedores. | ||
* | ||
* @param {IGetParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IGetResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Vendedores/get_vendedores | ||
*/ | ||
public async get(params?: IGetParams): Promise<IGetResponse> { | ||
return await this.repository.index({ | ||
endpoint: 'vendedores', | ||
params: { | ||
pagina: params?.pagina, | ||
limite: params?.limite, | ||
nomeContato: params?.nomeContato, | ||
situacaoContato: params?.situacaoContato, | ||
idContato: params?.idContato, | ||
idLoja: params?.idLoja, | ||
dataAlteracaoInicial: this.prepareStringOrDateParam( | ||
params?.dataAlteracaoInicial | ||
), | ||
dataAlteracaoFinal: this.prepareStringOrDateParam( | ||
params?.dataAlteracaoFinal | ||
) | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Obtém um vendedor. | ||
* | ||
* @param {IFindParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IFindResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Vendedores/get_vendedores__idVendedor_ | ||
*/ | ||
public async find(params: IFindParams): Promise<IFindResponse> { | ||
return await this.repository.show({ | ||
endpoint: 'vendedores', | ||
id: String(params.idVendedor) | ||
}) | ||
} | ||
} |
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,25 @@ | ||
import { ISituacao } from '../types/situacao.type' | ||
|
||
export interface IFindParams { | ||
/** | ||
* ID do vendedor | ||
*/ | ||
idVendedor: number | ||
} | ||
|
||
export interface IFindResponse { | ||
data: { | ||
id?: number | ||
descontoLimite?: number | ||
loja?: { id: number } | ||
contato: { | ||
id: number | ||
nome: string | ||
situacao: ISituacao | ||
} | ||
comissoes: { | ||
descontoMaximo: number | ||
aliquota: 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,49 @@ | ||
import { ISituacao } from '../types/situacao.type' | ||
|
||
export interface IGetParams { | ||
/** | ||
* N° da página da listagem | ||
*/ | ||
pagina?: number | ||
/** | ||
* Quantidade de registros que devem ser exibidos por página | ||
*/ | ||
limite?: number | ||
/** | ||
* Nome do contato do vendedor | ||
*/ | ||
nomeContato?: string | ||
/** | ||
* Situação do contato do vendedor | ||
*/ | ||
situacaoContato?: ISituacao | ||
/** | ||
* ID do contato do vendedor | ||
*/ | ||
idContato?: number | ||
/** | ||
* ID da loja vinculada ao vendedor | ||
*/ | ||
idLoja?: number | ||
/** | ||
* Data de alteração inicial | ||
*/ | ||
dataAlteracaoInicial?: Date | string | ||
/** | ||
* Data de alteração final | ||
*/ | ||
dataAlteracaoFinal?: Date | string | ||
} | ||
|
||
export interface IGetResponse { | ||
data: { | ||
id?: number | ||
descontoLimite?: number | ||
loja?: { id: number } | ||
contato: { | ||
id: number | ||
nome: string | ||
situacao: ISituacao | ||
} | ||
} | ||
} |
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,9 @@ | ||
/** | ||
* Tipagem referente à situação do vendedor. | ||
* | ||
* - `A`: Ativo | ||
* - `I`: Inativo | ||
* - `S`: Sem movimento | ||
* - `E`: Excluído | ||
*/ | ||
export type ISituacao = 'A' | 'I' | 'S' | 'E' |