All files / apps/notifications-service/src/notifications notification-sender.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 302x                         2x           2x 2x     1x     1x      
import { Injectable, Logger } from '@nestjs/common';
 
export interface Notification {
  recipient: string;
  subject: string;
  body: string;
}
 
/**
 * Abstraction over the delivery channel (email, SMS, push...). The consumer
 * depends on this token, so swapping the channel — or recording calls in
 * tests — never touches message-handling code.
 */
export abstract class NotificationSender {
  abstract send(notification: Notification): Promise<void>;
}
 
/** Stand-in channel until a real provider is integrated. */
@Injectable()
export class LoggingNotificationSender extends NotificationSender {
  private readonly logger = new Logger(LoggingNotificationSender.name);
 
  send(notification: Notification): Promise<void> {
    this.logger.log(
      `to=${notification.recipient} subject="${notification.subject}"`,
    );
    return Promise.resolve();
  }
}