Skip to content

Commit

Permalink
Remove mock reset
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Aug 30, 2023
1 parent af1057c commit 557981b
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/routes/events/events.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>) =>
'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) => ({

Check warning on line 20 in src/routes/events/events.service.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'_' is defined but never used
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>(EventsService);
webhookService = module.get<WebhookService>(WebhookService);
});

afterEach(async () => {
jest.clearAllMocks()
})


describe('listenToEvents', () => {
it('should return consumer tag', async () => {
Expand Down Expand Up @@ -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);

});
});
});

0 comments on commit 557981b

Please sign in to comment.