diff --git a/README.md b/README.md index a8d367d..f3bba77 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,16 @@ Some parameters are common to every event: } ``` +### Message created/confirmed +```json +{ +"address": "", +"type": "MESSAGE_CREATED" | "MESSAGE_CONFIRMATION", +"messageHash": "<0x-prefixed-hex-string>", +"chainId": "" +} +``` + # Developer documentation ## Installation diff --git a/src/routes/events/event.dto.ts b/src/routes/events/event.dto.ts index 77382cc..24b60c4 100644 --- a/src/routes/events/event.dto.ts +++ b/src/routes/events/event.dto.ts @@ -8,7 +8,9 @@ export type TxServiceEventType = | 'SAFE_CREATED' | 'MODULE_TRANSACTION' | 'OUTGOING_ETHER' - | 'OUTGOING_TOKEN'; + | 'OUTGOING_TOKEN' + | 'MESSAGE_CREATED' + | 'MESSAGE_CONFIRMATION'; export interface TxServiceEvent { chainId: string; diff --git a/src/routes/events/events.service.spec.ts b/src/routes/events/events.service.spec.ts index e93f23f..1bb90d0 100644 --- a/src/routes/events/events.service.spec.ts +++ b/src/routes/events/events.service.spec.ts @@ -6,33 +6,38 @@ 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); }); + + describe('listenToEvents', () => { it('should return consumer tag', async () => { const expected = 'exampleTag'; @@ -55,4 +60,31 @@ describe('EventsService', () => { expect(postEveryWebhook).toBeCalledWith(msg); }); }); + + describe('processMessageEvents', () => { + it('should post webhooks', async () => { + const postEveryWebhook = jest.spyOn(webhookService, 'postEveryWebhook'); + const messageCreated = { + chainId: '1', + type: 'MESSAGE_CREATED' as TxServiceEventType, + messageHash: + '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad', + address: '0x0275FC2adfF11270F3EcC4D2F7Aa0a9784601Ca6', + }; + const messageConfirmation = { + chainId: '1', + type: 'MESSAGE_CONFIRMATION' as TxServiceEventType, + 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); + }); + }); });