Files
TREK/server/tests/helpers/factories/notifications.ts
T
Maurice 724c88c201 style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts
and shared/src with the workspaces' .prettierrc; nothing but layout and
import order changes, and every file keeps the same set of imports. shared
is formatted throughout and its format baseline is empty. The server
baseline keeps the 35 files that Prettier would grow past their lint:size
limit (they need a split first, which is not a formatting change), and the
generated entity files stay as their generator writes them.
2026-10-10 21:23:37 +02:00

42 lines
1.5 KiB
TypeScript

import { NotificationChannelPreferences } from '../../../src/db/entities/NotificationChannelPreferences.entity';
import { Notifications } from '../../../src/db/entities/Notifications.entity';
import type { FactoryOrm } from './context';
import { createRow, upsertRow } from './rows';
import { setAppSetting } from './settings';
import type { EntityData, EntityDTO } from '@mikro-orm/core';
export type NotificationRow = EntityDTO<Notifications>;
/** An unread in-app notification of the simple kind for `recipientId`. */
export function makeNotification(
orm: FactoryOrm,
recipientId: number,
overrides: EntityData<Notifications> = {},
): Promise<NotificationRow> {
return createRow(orm, Notifications, {
recipient: recipientId,
type: 'simple',
scope: 'user',
target: recipientId,
title_key: 'notifications.test.title',
text_key: 'notifications.test.text',
is_read: 0,
...overrides,
});
}
/** Sets the instance's active notification channels ('email', 'webhook', 'email,webhook', 'none'). */
export function setNotificationChannels(orm: FactoryOrm, channels: string): Promise<void> {
return setAppSetting(orm, 'notification_channels', channels);
}
/** Turns one event on one channel off for the user. */
export async function disableNotificationPref(
orm: FactoryOrm,
userId: number,
eventType: string,
channel: string,
): Promise<void> {
await upsertRow(orm, NotificationChannelPreferences, { user: userId, event_type: eventType, channel, enabled: 0 });
}