From 8c7b18bcab693b2be4a78245cf339810a15edb84 Mon Sep 17 00:00:00 2001 From: Uxio Fuentefria Date: Fri, 8 Sep 2023 17:03:28 +0200 Subject: [PATCH] WIP Server side events --- src/routes/events/events.controller.spec.ts | 18 ++++++++++++++++++ src/routes/events/events.controller.ts | 13 +++++++++++++ src/routes/events/events.service.spec.ts | 2 -- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/routes/events/events.controller.spec.ts create mode 100644 src/routes/events/events.controller.ts diff --git a/src/routes/events/events.controller.spec.ts b/src/routes/events/events.controller.spec.ts new file mode 100644 index 0000000..6e45c1f --- /dev/null +++ b/src/routes/events/events.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { EventsController } from './events.controller'; + +describe('EventsController', () => { + let controller: EventsController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [EventsController], + }).compile(); + + controller = module.get(EventsController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/routes/events/events.controller.ts b/src/routes/events/events.controller.ts new file mode 100644 index 0000000..6dbb51b --- /dev/null +++ b/src/routes/events/events.controller.ts @@ -0,0 +1,13 @@ +import { Controller, Param, Sse } from '@nestjs/common'; +import { Observable } from 'rxjs'; +import { EventsService } from './events.service'; + +@Controller('events') +export class EventsController { + constructor(private eventsService: EventsService) {} + + @Sse('/sse/:safe') + sse(@Param('safe') safe: string): Observable { + return interval(1000).pipe(map((_) => ({ data: { hello: 'world' } }))); + } +} diff --git a/src/routes/events/events.service.spec.ts b/src/routes/events/events.service.spec.ts index 1bb90d0..bfd1b20 100644 --- a/src/routes/events/events.service.spec.ts +++ b/src/routes/events/events.service.spec.ts @@ -36,8 +36,6 @@ describe('EventsService', () => { webhookService = module.get(WebhookService); }); - - describe('listenToEvents', () => { it('should return consumer tag', async () => { const expected = 'exampleTag';