From b2efd58c40a2b697cbdc515b7f1ef5534795b23d Mon Sep 17 00:00:00 2001 From: moisses89 <7888669+moisses89@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:56:42 +0200 Subject: [PATCH] Remove mock reset --- src/routes/events/events.service.spec.ts | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/routes/events/events.service.spec.ts b/src/routes/events/events.service.spec.ts index d788f0a..1bb90d0 100644 --- a/src/routes/events/events.service.spec.ts +++ b/src/routes/events/events.service.spec.ts @@ -6,36 +6,37 @@ import { TxServiceEventType } from './event.dto'; describe('EventsService', () => { let eventsService: EventsService; + let webhookService: WebhookService; const queueProvider = { /* eslint-disable @typescript-eslint/no-unused-vars */ subscribeToEvents: async (_: (_: string) => Promise) => 'exampleTag', }; - const webhookService = { - postEveryWebhook: async (_: object) => ({ - data: {}, - status: 200, - statusText: 'OK', - }), - }; + /* eslint-enable @typescript-eslint/no-unused-vars */ beforeEach(async () => { + const webhookServiceMock = { + postEveryWebhook: async (_: object) => ({ + data: {}, + status: 200, + statusText: 'OK', + }), + }; const module = await Test.createTestingModule({ providers: [EventsService, QueueProvider, WebhookService], }) .overrideProvider(QueueProvider) .useValue(queueProvider) .overrideProvider(WebhookService) - .useValue(webhookService) + .useValue(webhookServiceMock) .compile(); eventsService = module.get(EventsService); + webhookService = module.get(WebhookService); }); - afterEach(async () => { - jest.clearAllMocks() - }) + describe('listenToEvents', () => { it('should return consumer tag', async () => { @@ -66,23 +67,24 @@ describe('EventsService', () => { const messageCreated = { chainId: '1', type: 'MESSAGE_CREATED' as TxServiceEventType, - messageHash: '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad', + messageHash: + '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad', address: '0x0275FC2adfF11270F3EcC4D2F7Aa0a9784601Ca6', }; const messageConfirmation = { chainId: '1', type: 'MESSAGE_CONFIRMATION' as TxServiceEventType, - messageHash: '0xc9b14f03293f5febf968b2a3dde3e5d373f978ea9e9403881c5abfa68322bea9', + messageHash: + '0xc9b14f03293f5febf968b2a3dde3e5d373f978ea9e9403881c5abfa68322bea9', address: '0x0275FC2adfF11270F3EcC4D2F7Aa0a9784601Ca6', }; - + await eventsService.processEvent(JSON.stringify(messageCreated)); expect(postEveryWebhook).toBeCalledTimes(1); expect(postEveryWebhook).toBeCalledWith(messageCreated); await eventsService.processEvent(JSON.stringify(messageConfirmation)); expect(postEveryWebhook).toBeCalledTimes(2); expect(postEveryWebhook).toBeCalledWith(messageConfirmation); - }); }); });