Skip to content

Commit

Permalink
Add notifications routes
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Jul 25, 2024
1 parent 8088fcd commit 0f116c8
Show file tree
Hide file tree
Showing 19 changed files with 1,417 additions and 142 deletions.
28 changes: 14 additions & 14 deletions migrations/__tests__/00005_notifications.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestDbFactory } from '@/__tests__/db.factory';
import { PostgresDatabaseMigrator } from '@/datasources/db/postgres-database.migrator';
import { DeviceType } from '@/domain/notifications/entities-v2/device-type.entity';
import { Uuid } from '@/domain/notifications/entities-v2/uuid.entity';
import { UUID } from 'crypto';
import { faker } from '@faker-js/faker';
import postgres from 'postgres';
import { getAddress } from 'viem';
Expand All @@ -10,7 +10,7 @@ type PushNotificationDevicesRow = {
id: number;
account_id: number;
device_type: 'ANDROID' | 'IOS' | 'WEB';
device_uuid: Uuid;
device_uuid: UUID;
cloud_messaging_token: string;
created_at: Date;
updated_at: Date;
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('Migration 00005_notifications', () => {

it('should upsert the updated_at timestamp in push_notification_devices', async () => {
const deviceType = faker.helpers.arrayElement(Object.values(DeviceType));
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
const afterMigration = await migrator.test({
migration: '00005_notifications',
Expand All @@ -191,7 +191,7 @@ describe('Migration 00005_notifications', () => {
},
]);

const newDeviceUuid = faker.string.uuid() as Uuid;
const newDeviceUuid = faker.string.uuid() as UUID;
// Update device with new device_uuid
const afterUpdate = await sql<
[PushNotificationDevicesRow]
Expand All @@ -216,7 +216,7 @@ describe('Migration 00005_notifications', () => {

it('should only allow an ANDROID, IOS, or WEB as device_type in push_notification_devices', async () => {
const deviceType = faker.lorem.word() as DeviceType;
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
await migrator.test({
migration: '00005_notifications',
Expand All @@ -233,7 +233,7 @@ describe('Migration 00005_notifications', () => {

it('should not allow a duplicate device_uuid in push_notification_devices', async () => {
const deviceType = faker.helpers.arrayElement(Object.values(DeviceType));
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
await migrator.test({
migration: '00005_notifications',
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('Migration 00005_notifications', () => {
const safeAddress = getAddress(faker.finance.ethereumAddress());
const chainId = faker.string.numeric();
const deviceType = faker.helpers.arrayElement(Object.values(DeviceType));
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
const afterMigration = await migrator.test({
migration: '00005_notifications',
Expand Down Expand Up @@ -317,7 +317,7 @@ describe('Migration 00005_notifications', () => {
const safeAddress = getAddress(faker.finance.ethereumAddress());
const chainId = faker.string.numeric();
const deviceType = faker.helpers.arrayElement(Object.values(DeviceType));
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
const afterMigration = await migrator.test({
migration: '00005_notifications',
Expand Down Expand Up @@ -358,7 +358,7 @@ describe('Migration 00005_notifications', () => {
const safeAddress = getAddress(faker.finance.ethereumAddress());
const chainId = faker.string.numeric();
const deviceType = faker.helpers.arrayElement(Object.values(DeviceType));
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
const afterMigration = await migrator.test({
migration: '00005_notifications',
Expand Down Expand Up @@ -398,7 +398,7 @@ describe('Migration 00005_notifications', () => {
const safeAddress = getAddress(faker.finance.ethereumAddress());
const chainId = faker.string.numeric();
const deviceType = faker.helpers.arrayElement(Object.values(DeviceType));
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
const afterMigration = await migrator.test({
migration: '00005_notifications',
Expand Down Expand Up @@ -437,7 +437,7 @@ describe('Migration 00005_notifications', () => {
const safeAddress = getAddress(faker.finance.ethereumAddress());
const chainId = faker.string.numeric();
const deviceType = faker.helpers.arrayElement(Object.values(DeviceType));
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
const afterMigration = await migrator.test({
migration: '00005_notifications',
Expand Down Expand Up @@ -505,7 +505,7 @@ describe('Migration 00005_notifications', () => {
const safeAddress = getAddress(faker.finance.ethereumAddress());
const chainId = faker.string.numeric();
const deviceType = faker.helpers.arrayElement(Object.values(DeviceType));
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
const afterMigration = await migrator.test({
migration: '00005_notifications',
Expand Down Expand Up @@ -550,7 +550,7 @@ describe('Migration 00005_notifications', () => {
const safeAddress = getAddress(faker.finance.ethereumAddress());
const chainId = faker.string.numeric();
const deviceType = faker.helpers.arrayElement(Object.values(DeviceType));
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
const afterMigration = await migrator.test({
migration: '00005_notifications',
Expand Down Expand Up @@ -596,7 +596,7 @@ describe('Migration 00005_notifications', () => {
const safeAddress = getAddress(faker.finance.ethereumAddress());
const chainId = faker.string.numeric();
const deviceType = faker.helpers.arrayElement(Object.values(DeviceType));
const deviceUuid = faker.string.uuid() as Uuid;
const deviceUuid = faker.string.uuid() as UUID;
const cloudMessagingToken = faker.string.alphanumeric();
const afterMigration = await migrator.test({
migration: '00005_notifications',
Expand Down
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { AuthModule } from '@/routes/auth/auth.module';
import { TransactionsViewControllerModule } from '@/routes/transactions/transactions-view.controller';
import { DelegatesV2Module } from '@/routes/delegates/v2/delegates.v2.module';
import { AccountsModule } from '@/routes/accounts/accounts.module';
import { NotificationsModuleV2 } from '@/routes/accounts/notifications/notifications.module.v2';

@Module({})
export class AppModule implements NestModule {
Expand Down Expand Up @@ -87,7 +88,7 @@ export class AppModule implements NestModule {
EstimationsModule,
HealthModule,
...(isPushNotificationsEnabled
? [HooksModuleWithNotifications]
? [HooksModuleWithNotifications, NotificationsModuleV2]
: [HooksModule]),
MessagesModule,
NotificationsModule,
Expand Down
Loading

0 comments on commit 0f116c8

Please sign in to comment.