From a28bfabbec8319b10789908bc47c2dbbb689cb42 Mon Sep 17 00:00:00 2001 From: Pooya Raki Date: Mon, 4 Nov 2024 13:06:59 +0100 Subject: [PATCH] chore: refactor notification tests --- ...upsert-subscriptions.dto.entity.builder.ts | 4 ++-- ...tifications.repository.integration.spec.ts | 20 ++++++++++++------- .../v1/notifications.controller.spec.ts | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/domain/notifications/v2/entities/__tests__/upsert-subscriptions.dto.entity.builder.ts b/src/domain/notifications/v2/entities/__tests__/upsert-subscriptions.dto.entity.builder.ts index 4c34391083..9951f4fa01 100644 --- a/src/domain/notifications/v2/entities/__tests__/upsert-subscriptions.dto.entity.builder.ts +++ b/src/domain/notifications/v2/entities/__tests__/upsert-subscriptions.dto.entity.builder.ts @@ -4,14 +4,14 @@ import { Builder } from '@/__tests__/builder'; import { getAddress } from 'viem'; import type { UpsertSubscriptionsDto } from '@/domain/notifications/v2/entities/upsert-subscriptions.dto.entity'; import { DeviceType } from '@/domain/notifications/v2/entities/device-type.entity'; -import type { Uuid } from '@/domain/notifications/v2/entities/uuid.entity'; import { NotificationType } from '@/domain/notifications/v2/entities/notification-type.entity'; +import type { UUID } from 'crypto'; export function upsertSubscriptionsDtoBuilder(): IBuilder { return new Builder() .with('cloudMessagingToken', faker.string.alphanumeric({ length: 10 })) .with('deviceType', faker.helpers.arrayElement(Object.values(DeviceType))) - .with('deviceUuid', faker.string.uuid() as Uuid) + .with('deviceUuid', faker.string.uuid() as UUID) .with( 'safes', Array.from( diff --git a/src/domain/notifications/v2/notifications.repository.integration.spec.ts b/src/domain/notifications/v2/notifications.repository.integration.spec.ts index 19f83ff360..03f5d6c277 100644 --- a/src/domain/notifications/v2/notifications.repository.integration.spec.ts +++ b/src/domain/notifications/v2/notifications.repository.integration.spec.ts @@ -96,14 +96,16 @@ describe('NotificationsRepositoryV2', () => { * * @async * @function createDatabaseConnection - * @returns {Promise} Resolves when migrations are complete. + * @returns {Promise} Returns an instance of PostgresDatabaseService */ - async function createDatabaseConnection(): Promise { - postgresDatabaseService = new PostgresDatabaseService( + async function createDatabaseConnection(): Promise { + const databaseService = new PostgresDatabaseService( mockLoggingService, dataSource, ); - await postgresDatabaseService.initializeDatabaseConnection(); + await databaseService.initializeDatabaseConnection(); + + return databaseService; } /** @@ -113,11 +115,15 @@ describe('NotificationsRepositoryV2', () => { * services (logging, database, and configuration) and executes the migration * process. * + * @param {postgresDatabaseService} postgresDatabaseService The postgres database service instance + * * @async * @function migrateDatabase * @returns {Promise} Resolves when migrations are complete. */ - async function migrateDatabase(): Promise { + async function migrateDatabase( + postgresDatabaseService: PostgresDatabaseService, + ): Promise { const migrator = new DatabaseMigrator( mockLoggingService, postgresDatabaseService, @@ -168,8 +174,8 @@ describe('NotificationsRepositoryV2', () => { beforeAll(async () => { await createTestDatabase(); - await createDatabaseConnection(); - await migrateDatabase(); + postgresDatabaseService = await createDatabaseConnection(); + await migrateDatabase(postgresDatabaseService); notificationsRepositoryService = new NotificationsRepositoryV2( mockPushNotificationsApi, diff --git a/src/routes/notifications/v1/notifications.controller.spec.ts b/src/routes/notifications/v1/notifications.controller.spec.ts index bc9c55cfd5..bad4662a0e 100644 --- a/src/routes/notifications/v1/notifications.controller.spec.ts +++ b/src/routes/notifications/v1/notifications.controller.spec.ts @@ -133,13 +133,13 @@ describe('Notifications Controller (Unit)', () => { // @TODO Remove NotificationModuleV2 after all clients have migrated and compatibility is no longer needed. // We call V2 as many times as we have a registration with at least one safe - const safedRegistrationsWithSafe = + const safeRegistrationsWithSafe = registerDeviceDto.safeRegistrations.filter( (safeRegistration) => safeRegistration.safes.length > 0, ); expect(notificationServiceV2.upsertSubscriptions).toHaveBeenCalledTimes( - safedRegistrationsWithSafe.length, + safeRegistrationsWithSafe.length, ); for (const [