Skip to content

Commit

Permalink
feat: atualizar conforme changelog 20231213 e 20240131 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas authored Dec 15, 2023
2 parents 14d9177 + a7ca92b commit 9010ae1
Show file tree
Hide file tree
Showing 41 changed files with 784 additions and 50 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"exceptions": "Error"
},
"cSpell.words": [
"agrupadores",
"aliquota",
"Amazônia",
"borderô",
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Disponível para:
- [ ] PHP (em breve)
- [ ] C# (em breve)

Atualizado com a versão `v291` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-01-31)).

**Atenção**: a versão 5.0.0+ do `bling-erp-api` utiliza a API v3 do Bling. Caso
deseje utilizar a API v2 do Bling,
[utilize a versão 4.0.0](https://github.com/AlexandreBellas/bling-erp-api/tree/v4.0.0).
Expand Down Expand Up @@ -79,6 +81,7 @@ Todas as entidades do Bling atualmente são permitidas para interação. São el
- [x] Logísticas (`.logisticas`)
- [x] Logísticas - Etiquetas (`.logisticasEtiquetas`)
- [x] Logísticas - Objetos (`.logisticasObjetos`)
- [x] Logísticas - Remessas (`.logisticasRemessas`)
- [x] Logísticas - Serviços (`.logisticasServicos`)
- [x] Naturezas de Operações (`.naturezasDeOperacoes`)
- [x] Notas Fiscais de Consumidor Eletrônicas (`.nfces`)
Expand Down
7 changes: 7 additions & 0 deletions src/bling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Homologacao } from './entities/homologacao'
import { Logisticas } from './entities/logisticas'
import { LogisticasEtiquetas } from './entities/logisticasEtiquetas'
import { LogisticasObjetos } from './entities/logisticasObjetos'
import { LogisticasRemessas } from './entities/logisticasRemessas'
import { LogisticasServicos } from './entities/logisticasServicos'
import { NaturezasDeOperacoes } from './entities/naturezasDeOperacoes'
import { Nfces } from './entities/nfces'
Expand Down Expand Up @@ -147,6 +148,12 @@ describe('Bling main module', () => {
)
})

it('should retrieve logísticas - remessas entity', () => {
expect(createBling(chance.word()).logisticasRemessas).toBeInstanceOf(
LogisticasRemessas
)
})

it('should retrieve logísticas - serviços entity', () => {
expect(createBling(chance.word()).logisticasServicos).toBeInstanceOf(
LogisticasServicos
Expand Down
10 changes: 10 additions & 0 deletions src/bling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Homologacao } from './entities/homologacao'
import { Logisticas } from './entities/logisticas'
import { LogisticasEtiquetas } from './entities/logisticasEtiquetas'
import { LogisticasObjetos } from './entities/logisticasObjetos'
import { LogisticasRemessas } from './entities/logisticasRemessas'
import { LogisticasServicos } from './entities/logisticasServicos'
import { NaturezasDeOperacoes } from './entities/naturezasDeOperacoes'
import { Nfces } from './entities/nfces'
Expand Down Expand Up @@ -251,6 +252,15 @@ export default class Bling {
return this.getModule(LogisticasObjetos)
}

/**
* Obtém a instância de interação com logísticas - remessas.
*
* @return {LogisticasRemessas}
*/
public get logisticasRemessas(): LogisticasRemessas {
return this.getModule(LogisticasRemessas)
}

/**
* Obtém a instância de interação com logísticas - serviços.
*
Expand Down
14 changes: 7 additions & 7 deletions src/entities/contatos/__tests__/find-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ export default {
id: 12345678,
nome: 'Contato',
codigo: 'ASD001',
situacao: 'A',
situacao: 'A' as const,
numeroDocumento: '12345678910',
telefone: '(54) 3333-4444',
celular: '(54) 99999-8888',
fantasia: 'Nome fantasia',
tipo: 'J',
indicadorIe: 1,
tipo: 'J' as const,
indicadorIe: 1 as const,
ie: '123.456.789.101',
rg: '1234567890',
orgaoEmissor: '1234567890',
Expand All @@ -20,7 +20,7 @@ export default {
cep: '95702-000',
bairro: 'Imigrante',
municipio: 'Bento Gonçalves',
uf: 'RS',
uf: 'RS' as const,
numero: '914',
complemento: 'Sede 101'
},
Expand All @@ -29,7 +29,7 @@ export default {
cep: '95702-000',
bairro: 'Imigrante',
municipio: 'Bento Gonçalves',
uf: 'RS',
uf: 'RS' as const,
numero: '914',
complemento: 'Sede 101'
}
Expand All @@ -39,11 +39,11 @@ export default {
},
dadosAdicionais: {
dataNascimento: '1990-08-24',
sexo: 'M',
sexo: 'M' as const,
naturalidade: 'Brasileira'
},
financeiro: {
limiteCredito: 0,
limiteCredito: 0 as const,
condicaoPagamento: '30',
categoria: {
id: 12345678
Expand Down
2 changes: 1 addition & 1 deletion src/entities/contatos/__tests__/get-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
id: 12345678,
nome: 'Contato',
codigo: 'ASD001',
situacao: 'A',
situacao: 'A' as const,
numeroDocumento: '123.456.789-10',
telefone: '(54) 3333-4444',
celular: '(54) 99999-8888'
Expand Down
37 changes: 36 additions & 1 deletion src/entities/contatos/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Chance } from 'chance'
import { Contatos } from '..'
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
import { ICreateResponse } from '../interfaces/create.interface'
import { IFindTypesResponse } from '../interfaces/find-types.interface'
import { IFindResponse } from '../interfaces/find.interface'
import { IGetResponse } from '../interfaces/get.interface'
import changeSituationManyResponse, {
changeSituationManyRequest
} from './change-situation-many-response'
Expand Down Expand Up @@ -46,6 +50,9 @@ describe('Contatos entity', () => {
params: { idsContatos }
})
expect(response).toBe(deleteManyResponse)

const typingResponseTest: null = deleteManyResponse
expect(typingResponseTest).toBe(deleteManyResponse)
})

it('should delete successfully', async () => {
Expand All @@ -60,6 +67,9 @@ describe('Contatos entity', () => {
id: String(idContato)
})
expect(response).toBe(deleteResponse)

const typingResponseTest: null = deleteResponse
expect(typingResponseTest).toBe(deleteResponse)
})

it('should get successfully', async () => {
Expand All @@ -75,6 +85,10 @@ describe('Contatos entity', () => {
pagina: undefined,
pesquisa: undefined,
criterio: undefined,
dataInclusaoInicial: undefined,
dataInclusaoFinal: undefined,
dataAlteracaoInicial: undefined,
dataAlteracaoFinal: undefined,
idTipoContato: undefined,
idVendedor: undefined,
uf: undefined,
Expand All @@ -84,6 +98,9 @@ describe('Contatos entity', () => {
}
})
expect(response).toBe(getResponse)

const typingResponseTest: IGetResponse = getResponse
expect(typingResponseTest).toBe(getResponse)
})

it('should find successfully', async () => {
Expand All @@ -98,6 +115,9 @@ describe('Contatos entity', () => {
id: String(idContato)
})
expect(response).toBe(findResponse)

const typingResponseTest: IFindResponse = findResponse
expect(typingResponseTest).toBe(findResponse)
})

it('should find types successfully', async () => {
Expand All @@ -112,6 +132,9 @@ describe('Contatos entity', () => {
id: `${idContato}/tipos`
})
expect(response).toBe(findTypesResponse)

const typingResponseTest: IFindTypesResponse = findTypesResponse
expect(typingResponseTest).toBe(findTypesResponse)
})

it('should change situation successfully', async () => {
Expand All @@ -130,6 +153,9 @@ describe('Contatos entity', () => {
body: changeSituationRequest
})
expect(response).toBe(changeSituationResponse)

const typingResponseTest: null = changeSituationResponse
expect(typingResponseTest).toBe(changeSituationResponse)
})

it('should change situation many successfully', async () => {
Expand All @@ -144,7 +170,10 @@ describe('Contatos entity', () => {
endpoint: 'contatos/situacoes',
body: changeSituationManyRequest
})
expect(response).toBe(changeSituationResponse)
expect(response).toBe(changeSituationManyResponse)

const typingResponseTest: null = changeSituationManyResponse
expect(typingResponseTest).toBe(changeSituationManyResponse)
})

it('should create successfully', async () => {
Expand All @@ -158,6 +187,9 @@ describe('Contatos entity', () => {
body: createRequestBody
})
expect(response).toBe(createResponse)

const typingResponseTest: ICreateResponse = createResponse
expect(typingResponseTest).toBe(createResponse)
})

it('should update successfully', async () => {
Expand All @@ -176,5 +208,8 @@ describe('Contatos entity', () => {
body: updateRequestBody
})
expect(response).toBe(updateResponse)

const typingResponseTest: null = updateResponse
expect(typingResponseTest).toBe(updateResponse)
})
})
12 changes: 12 additions & 0 deletions src/entities/contatos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ export class Contatos extends Entity {
limite: params?.limite,
pesquisa: params?.pesquisa,
criterio: params?.criterio,
dataInclusaoInicial: this.prepareStringOrDateParam(
params?.dataInclusaoInicial
),
dataInclusaoFinal: this.prepareStringOrDateParam(
params?.dataInclusaoFinal
),
dataAlteracaoInicial: this.prepareStringOrDateParam(
params?.dataAlteracaoInicial
),
dataAlteracaoFinal: this.prepareStringOrDateParam(
params?.dataAlteracaoFinal
),
idTipoContato: params?.idTipoContato,
idVendedor: params?.idVendedor,
uf: params?.uf,
Expand Down
16 changes: 16 additions & 0 deletions src/entities/contatos/interfaces/get.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ export interface IGetParams {
* Criterio de listagem
*/
criterio?: ICriterio
/**
* Data de inclusão inicial
*/
dataInclusaoInicial?: Date | string
/**
* Data de inclusão final
*/
dataInclusaoFinal?: Date | string
/**
* Data de alteração inicial
*/
dataAlteracaoInicial?: Date | string
/**
* Data de alteração final
*/
dataAlteracaoFinal?: Date | string
/**
* ID do tipo do contato
*/
Expand Down
7 changes: 4 additions & 3 deletions src/entities/logisticasEtiquetas/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Chance } from 'chance'
import { LogisticasEtiquetas } from '..'
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
import { IFormato } from '../types/formato.type'
import getResponse from './get-response'

const chance = Chance()
Expand All @@ -21,17 +22,17 @@ describe('Logísticas - Etiquetas entity', () => {
it('should get successfully', async () => {
const spy = jest.spyOn(repository, 'index')
repository.setResponse(getResponse)
const formato = chance.pickone(['PDF', 'ZPL']) as IFormato
const idsVendas: number[] = []
for (let i = 0; i < chance.natural({ min: 1, max: 5 }) + 1; i++) {
idsVendas.push(chance.natural())
}

const response = await entity.get({ idsVendas })
const response = await entity.get({ formato, idsVendas })

expect(spy).toHaveBeenCalledWith({
endpoint: 'logisticas/etiquetas',
body: { idsVendas },
params: { formato: undefined }
params: { formato, idsVendas }
})
expect(response).toBe(getResponse)
})
Expand Down
13 changes: 7 additions & 6 deletions src/entities/logisticasEtiquetas/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity } from '../@shared/entity'
import { IGetBody, IGetParams, IGetResponse } from './interfaces/get.interface'
import { IGetParams, IGetResponse } from './interfaces/get.interface'

/**
* Entidade para interação com logísticas - etiquetas.
Expand All @@ -10,19 +10,20 @@ export class LogisticasEtiquetas extends Entity {
/**
* Obtém etiquetas das vendas.
*
* @param {IGetParams & IGetBody} params Parâmetros da busca.
* @param {IGetParams} params Parâmetros da busca.
*
* @returns {Promise<IGetResponse>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Log%C3%ADsticas%20-%20Etiquetas/get_logisticas_etiquetas
*/
public async get(params: IGetParams & IGetBody): Promise<IGetResponse> {
const { formato, ...body } = params
public async get(params: IGetParams): Promise<IGetResponse> {
return await this.repository.index({
endpoint: 'logisticas/etiquetas',
body,
params: { formato }
params: {
formato: params.formato,
idsVendas: params.idsVendas
}
})
}
}
5 changes: 1 addition & 4 deletions src/entities/logisticasEtiquetas/interfaces/get.interface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { IFormato } from '../types/formato.type'

export interface IGetParams {
formato?: IFormato
}

export interface IGetBody {
formato: IFormato
idsVendas: number[]
}

Expand Down
15 changes: 15 additions & 0 deletions src/entities/logisticasRemessas/__tests__/create-response.ts
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']
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null
Loading

0 comments on commit 9010ae1

Please sign in to comment.