-
-
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
76034db
commit b70d510
Showing
23 changed files
with
302 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"*.spec.php": "test-ts" | ||
}, | ||
"cSpell.words": [ | ||
"agrupador", | ||
"agrupadores", | ||
"aliquota", | ||
"Amazônia", | ||
|
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,18 @@ | ||
export default { | ||
data: { | ||
id: 12345678, | ||
descricao: 'Loja de teste', | ||
tipo: 'Shopee', | ||
situacao: 1 as const, | ||
filiais: [ | ||
{ | ||
cnpj: '12.345.678/9012-34', | ||
unidadeNegocio: 'Empresa Teste', | ||
deposito: { | ||
id: 12345678 | ||
}, | ||
padrao: true | ||
} | ||
] | ||
} | ||
} |
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 default { | ||
data: [ | ||
{ | ||
id: 12345678, | ||
descricao: 'Loja de teste', | ||
tipo: 'Shopee', | ||
situacao: 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,9 @@ | ||
export default { | ||
data: [ | ||
{ | ||
nome: 'Loja Integrada', | ||
tipo: 'LojaIntegrada', | ||
agrupador: 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,79 @@ | ||
import { Chance } from 'chance' | ||
import { CanaisDeVenda } from '../' | ||
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository' | ||
import findResponse from './find-response' | ||
import getResponse from './get-response' | ||
import getTypesResponse from './get-types-response' | ||
import { IFindResponse } from '../interfaces/find.interface' | ||
import { IGetResponse } from '../interfaces/get.interface' | ||
import { IGetTypesResponse } from '../interfaces/get-types.interface' | ||
|
||
const chance = Chance() | ||
|
||
describe('Canais de Venda entity', () => { | ||
let repository: InMemoryBlingRepository | ||
let entity: CanaisDeVenda | ||
|
||
beforeEach(() => { | ||
repository = new InMemoryBlingRepository() | ||
entity = new CanaisDeVenda(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: 'canais-venda', | ||
params: { | ||
pagina: undefined, | ||
limite: undefined, | ||
tipos: undefined, | ||
situacao: undefined, | ||
agrupador: 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 idCanalVenda = chance.natural() | ||
repository.setResponse(findResponse) | ||
|
||
const response = await entity.find({ idCanalVenda }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'canais-venda', | ||
id: String(idCanalVenda) | ||
}) | ||
expect(response).toBe(findResponse) | ||
const typingResponseTest: IFindResponse = findResponse | ||
expect(typingResponseTest).toBe(findResponse) | ||
}) | ||
|
||
it('should get types successfully', async () => { | ||
const spy = jest.spyOn(repository, 'index') | ||
repository.setResponse(getTypesResponse) | ||
|
||
const response = await entity.getTypes() | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'canais-venda/tipos', | ||
params: { | ||
agrupador: undefined | ||
} | ||
}) | ||
expect(response).toBe(getTypesResponse) | ||
const typingResponseTest: IGetTypesResponse = getTypesResponse | ||
expect(typingResponseTest).toBe(getTypesResponse) | ||
}) | ||
}) |
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,70 @@ | ||
import { Entity } from '../@shared/entity' | ||
import { IFindParams, IFindResponse } from './interfaces/find.interface' | ||
import { | ||
IGetTypesParams, | ||
IGetTypesResponse | ||
} from './interfaces/get-types.interface' | ||
import { IGetParams, IGetResponse } from './interfaces/get.interface' | ||
|
||
/** | ||
* Entidade para interação com Canais de Venda. | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Canais%20de%20Venda | ||
*/ | ||
export class CanaisDeVenda extends Entity { | ||
/** | ||
* Obtém canais de venda. | ||
* | ||
* @param {IGetParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IGetResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Canais%20de%20Venda/get_canais_venda | ||
*/ | ||
public async get(params?: IGetParams): Promise<IGetResponse> { | ||
return await this.repository.index({ | ||
endpoint: 'canais-venda', | ||
params: { | ||
pagina: params?.pagina, | ||
limite: params?.limite, | ||
tipos: params?.tipos, | ||
situacao: params?.situacao, | ||
agrupador: params?.agrupador | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Obtém um canal de venda. | ||
* | ||
* @param {IFindParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IFindResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Canais%20de%20Venda/get_canais_venda__idCanalVenda_ | ||
*/ | ||
public async find(params: IFindParams): Promise<IFindResponse> { | ||
return await this.repository.show({ | ||
endpoint: 'canais-venda', | ||
id: String(params.idCanalVenda) | ||
}) | ||
} | ||
|
||
/** | ||
* Obtém os tipos de canais de venda. | ||
* | ||
* @param {IGetTypesParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IGetTypesResponse>} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Canais%20de%20Venda/get_canais_venda_tipos | ||
*/ | ||
public async getTypes(params?: IGetTypesParams): Promise<IGetTypesResponse> { | ||
return await this.repository.index({ | ||
endpoint: 'canais-venda/tipos', | ||
params: { agrupador: params?.agrupador } | ||
}) | ||
} | ||
} |
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 @@ | ||
import { ISituacao } from '../types/situacao.type' | ||
|
||
export interface IFindParams { | ||
idCanalVenda: number | ||
} | ||
|
||
export interface IFindResponse { | ||
data: { | ||
id: number | ||
descricao: string | ||
tipo: string | ||
situacao: ISituacao | ||
filiais: { | ||
cnpj: string | ||
unidadeNegocio: string | ||
deposito: { id: number } | ||
padrao: boolean | ||
}[] | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/entities/canaisDeVenda/interfaces/get-types.interface.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,13 @@ | ||
import { IAgrupador } from '../types/agrupador.type' | ||
|
||
export interface IGetTypesParams { | ||
agrupador?: IAgrupador | ||
} | ||
|
||
export interface IGetTypesResponse { | ||
data: { | ||
nome: string | ||
tipo: string | ||
agrupador: IAgrupador | ||
}[] | ||
} |
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,19 @@ | ||
import { IAgrupador } from '../types/agrupador.type' | ||
import { ISituacao } from '../types/situacao.type' | ||
|
||
export interface IGetParams { | ||
pagina?: number | ||
limite?: number | ||
tipos?: string[] | ||
situacao?: ISituacao | ||
agrupador?: IAgrupador | ||
} | ||
|
||
export interface IGetResponse { | ||
data: { | ||
id: number | ||
descricao: string | ||
tipo: 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 ao agrupador de um canal de venda. | ||
* | ||
* - `1`: Loja virtual | ||
* - `2`: Hub | ||
* - `3`: Marketplace | ||
* - `4`: API | ||
*/ | ||
export type IAgrupador = 1 | 2 | 3 | 4 |
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,7 @@ | ||
/** | ||
* Tipagem referente à situação de um canal de venda. | ||
* | ||
* - `1`: Habilitado | ||
* - `2`: Desabilitado | ||
*/ | ||
export type ISituacao = 1 | 2 |
Oops, something went wrong.