mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +00:00
6cf5760383
Nine fire-and-forget sends reached notifications.bridge through
import('...').then(({ send }) => ...). The laziness was working around a
module cycle that no longer exists, and it cost twice: it hid the edge from
the module graph, and it handed each send a NotificationsService built
outside the container rather than the container's own.
The sweep needed a method rather than a grep. tests/ sits outside
tsconfig's include, so a service that gains a constructor parameter does not
break its hand-wired call sites at compile time — the argument arrives as
undefined and throws inside the send. Adding tests to a throwaway tsconfig
and diffing the errors before and after named all 46 sites exactly. The same
config reports 288 pre-existing errors in the suites, almost all deliberate
partial constructions in the harnesses, which is why tests/ is not in the
build's include; that cleanup is its own piece of work and is written down
in the nest README.
notifications.instance.ts holds the out-of-container instance, apart from
notifications.bridge.ts on purpose: several suites replace the bridge
wholesale with vi.mock(..., () => ({ send })), and a sibling bridge taking
its instance from there would break under those mocks.
The suites that assert on a send now hand their spy to the injected service.
The reservations e2e overrides the provider, because its app resolves the
real one out of its own container and never saw the module mock.
48 lines
2.2 KiB
TypeScript
48 lines
2.2 KiB
TypeScript
import { DatabaseService } from '../../src/nest/database/database.service';
|
|
import { RealtimeService } from '../../src/nest/realtime/realtime.service';
|
|
import { MailerService } from '../../src/nest/notifications/mailer/mailer.service';
|
|
import { NotificationPreferencesService } from '../../src/nest/notifications/notification-preferences.service';
|
|
import { NotificationsService } from '../../src/nest/notifications/notifications.service';
|
|
import { NtfyService } from '../../src/nest/notifications/transports/ntfy.service';
|
|
import { WebhookService } from '../../src/nest/notifications/transports/webhook.service';
|
|
|
|
/**
|
|
* A NotificationsService wired the way Nest wires it.
|
|
*
|
|
* The domain takes six providers since the fold, and eight places used to build
|
|
* it by hand — every added constructor parameter was an eight-file diff. One
|
|
* helper keeps that at one.
|
|
*/
|
|
export function makeNotificationsService(dbs: DatabaseService, realtime = new RealtimeService()): NotificationsService {
|
|
const mailer = new MailerService(dbs);
|
|
return new NotificationsService(
|
|
dbs,
|
|
realtime,
|
|
mailer,
|
|
new WebhookService(dbs),
|
|
new NtfyService(dbs),
|
|
new NotificationPreferencesService(dbs, mailer),
|
|
);
|
|
}
|
|
|
|
/** The preferences half on its own, over the same connection. */
|
|
export function makeNotificationPreferencesService(dbs: DatabaseService): NotificationPreferencesService {
|
|
return new NotificationPreferencesService(dbs, new MailerService(dbs));
|
|
}
|
|
|
|
/**
|
|
* A send that records instead of delivering.
|
|
*
|
|
* For the six services that took NotificationsService as a constructor
|
|
* parameter when their fire-and-forget sends stopped being lazy imports. Most
|
|
* suites do not care that a notification went out, only that the write around
|
|
* it succeeded — but the parameter is required, and `tests/` is outside
|
|
* `tsconfig`'s `include`, so leaving it off would not fail to compile. It would
|
|
* land as `undefined` and throw inside the send.
|
|
*/
|
|
export function notificationsStub(send: NotificationSend = async () => {}): NotificationsService {
|
|
return { send } as unknown as NotificationsService;
|
|
}
|
|
|
|
type NotificationSend = (payload: Parameters<NotificationsService['send']>[0]) => Promise<void>;
|