This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(143): Publica msg pagamento confirmado
- Loading branch information
1 parent
7b8f037
commit 56aeb7c
Showing
23 changed files
with
212 additions
and
162 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
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
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 was deleted.
Oops, something went wrong.
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,5 @@ | ||
export interface IFilaPagamentoConfirmadoAdapter { | ||
publicarPagamentoConfirmado(idPedido: string): Promise<void>; | ||
} | ||
|
||
export const IFilaPagamentoConfirmadoAdapter = Symbol('IFilaPagamentoConfirmadoAdapter'); |
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
61 changes: 61 additions & 0 deletions
61
src/infrastructure/adapters/filas/pagamento_confirmado/pag_confirmado.adapter.spec.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,61 @@ | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { FilaPagamentoConfirmadoAdapter } from './pag_confirmado.adapter'; | ||
import { pedidoDTOMock } from 'src/mocks/pedido.mock'; | ||
import { SqsService } from '@ssut/nestjs-sqs'; | ||
import { Logger } from '@nestjs/common'; | ||
|
||
describe('FilaPagamentoConfirmadoAdapter', () => { | ||
let filaPagamentoConfirmadoAdapter: FilaPagamentoConfirmadoAdapter; | ||
let configService: ConfigService; | ||
let sqsService: SqsService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
Logger, | ||
FilaPagamentoConfirmadoAdapter, | ||
{ | ||
provide: ConfigService, | ||
useValue: { | ||
get: jest.fn(), | ||
getOrThrow: jest.fn(), | ||
}, | ||
}, | ||
{ | ||
provide: SqsService, | ||
useValue: { | ||
send: jest.fn(), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
filaPagamentoConfirmadoAdapter = module.get<FilaPagamentoConfirmadoAdapter>( | ||
FilaPagamentoConfirmadoAdapter, | ||
); | ||
configService = module.get<ConfigService>(ConfigService); | ||
sqsService = module.get<SqsService>(SqsService); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('deve publicar falha na cobrança', async () => { | ||
jest.spyOn(configService, 'getOrThrow').mockReturnValue('falha-cobranca'); | ||
jest.spyOn(sqsService, 'send'); | ||
|
||
await filaPagamentoConfirmadoAdapter.publicarPagamentoConfirmado(pedidoDTOMock.id); | ||
expect(sqsService.send).toHaveBeenCalled(); | ||
}); | ||
|
||
it('deve lançar exceção ao publicar falha na cobrança', async () => { | ||
jest.spyOn(configService, 'getOrThrow').mockReturnValue('falha-cobranca'); | ||
jest.spyOn(sqsService, 'send').mockRejectedValue(new Error('Erro')); | ||
|
||
await expect( | ||
filaPagamentoConfirmadoAdapter.publicarPagamentoConfirmado(pedidoDTOMock.id), | ||
).rejects.toThrow('Ocorreu um erro ao publicar a mensagem.'); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
src/infrastructure/adapters/filas/pagamento_confirmado/pag_confirmado.adapter.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,34 @@ | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { SqsService } from '@ssut/nestjs-sqs'; | ||
import { IFilaPagamentoConfirmadoAdapter } from 'src/domain/pedido/interfaces/pag_confirmado_adapter'; | ||
|
||
@Injectable() | ||
export class FilaPagamentoConfirmadoAdapter implements IFilaPagamentoConfirmadoAdapter { | ||
constructor( | ||
private readonly logger: Logger, | ||
private readonly configService: ConfigService, | ||
private readonly sqsService: SqsService, | ||
) { } | ||
async publicarPagamentoConfirmado(idPedido: string) { | ||
const queueName = this.configService.getOrThrow<string>( | ||
'NOME_FILA_PAGAMENTO_CONFIRMADO', | ||
); | ||
try { | ||
await this.sqsService.send(queueName, { | ||
id: 'id', | ||
body: idPedido, | ||
}); | ||
this.logger.log( | ||
`A confirmação de pagamento do pedido ${idPedido} foi publicada na fila ${queueName}`, | ||
idPedido, | ||
); | ||
} catch (error) { | ||
this.logger.error( | ||
`Ocorreu um erro ao publicar o pedido ${idPedido} na fila ${queueName}`, | ||
error, | ||
); | ||
throw new Error('Ocorreu um erro ao publicar a mensagem.'); | ||
} | ||
} | ||
} |
Oops, something went wrong.