Skip to content

Commit

Permalink
feat: adicionar empresas
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Nov 25, 2023
1 parent 3a5a351 commit b64195a
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ As entidades atualmente permitidas para interação são:
- [x] Contatos - Tipos (`.contatosTipos`)
- [x] Contratos (`.contratos`)
- [x] Depósitos (`.depositos`)
- [ ] Empresas (`.empresas`)
- [x] Empresas (`.empresas`)
- [ ] Estoques (`.estoques`)
- [ ] Formas de pagamento (`.formasDePagamento`)
- [ ] Homologação (`.homologacao`)
Expand Down
5 changes: 5 additions & 0 deletions src/bling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Contatos } from './entities/contatos'
import { ContatosTipos } from './entities/contatosTipos'
import { Contratos } from './entities/contratos'
import { Depositos } from './entities/depositos'
import { Empresas } from './entities/empresas'

const chance = Chance()

Expand Down Expand Up @@ -87,4 +88,8 @@ describe('Bling main module', () => {
it('should retrieve depósitos entity', () => {
expect(createBling(chance.word()).depositos).toBeInstanceOf(Depositos)
})

it('should retrieve empresas entity', () => {
expect(createBling(chance.word()).empresas).toBeInstanceOf(Empresas)
})
})
10 changes: 10 additions & 0 deletions src/bling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Contatos } from './entities/contatos'
import { ContatosTipos } from './entities/contatosTipos'
import { Contratos } from './entities/contratos'
import { Depositos } from './entities/depositos'
import { Empresas } from './entities/empresas'
import { Newable } from './helpers/types/newable.type'
import { getRepository } from './providers/ioc'
import { IBlingRepository } from './repositories/bling.repository.interface'
Expand Down Expand Up @@ -162,4 +163,13 @@ export default class Bling {
public get depositos(): Depositos {
return this.getModule(Depositos)
}

/**
* Obtém a instância de interação com empresas.
*
* @return {Empresas}
*/
public get empresas(): Empresas {
return this.getModule(Empresas)
}
}
29 changes: 29 additions & 0 deletions src/entities/empresas/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Empresas } from '..'
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
import meResponse from './me-response'

describe('Empresas entity', () => {
let repository: InMemoryBlingRepository
let entity: Empresas

beforeEach(() => {
repository = new InMemoryBlingRepository()
entity = new Empresas(repository)
})

afterEach(() => {
jest.restoreAllMocks()
})

it('should get successfully', async () => {
const spy = jest.spyOn(repository, 'index')
repository.setResponse(meResponse)

const response = await entity.me()

expect(spy).toHaveBeenCalledWith({
endpoint: 'empresas/me/dados-basicos'
})
expect(response).toBe(meResponse)
})
})
7 changes: 7 additions & 0 deletions src/entities/empresas/__tests__/me-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
data: {
nome: 'Empresa Teste LTDA',
cnpj: '12.345.657/8910-11',
email: '[email protected]'
}
}
21 changes: 21 additions & 0 deletions src/entities/empresas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Entity } from '../@shared/entity'
import { IMeResponse } from './interfaces/me.interface'

/**
* Entidade para interação com empresas.
*/
export class Empresas extends Entity {
/**
* Obtém dados básicos da empresa.
*
* @returns {Promise<IMeResponse>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Empresas/get_empresas_me_dados_basicos
*/
public async me(): Promise<IMeResponse> {
return await this.repository.index({
endpoint: 'empresas/me/dados-basicos'
})
}
}
7 changes: 7 additions & 0 deletions src/entities/empresas/interfaces/me.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface IMeResponse {
data: {
nome: string
cnpj: string
email: string
}
}

0 comments on commit b64195a

Please sign in to comment.