Files
bookorbit/server/src/modules/email/email-send-log.controller.test.ts
T
neon 591dea03a2 feat(email): rebuild email settings as four quiet tabs with a send sheet
Fold six tabs into Recipients, Mail servers, Templates and History, where only problems get
colour and one star sets each default through email_preferences. Replace the send dialog with
a sheet that preselects the default recipient and follows the send. Server additions are
optional fields and routes, so released iOS builds keep working.
2026-10-12 22:18:38 +00:00

85 lines
3.0 KiB
TypeScript

import type { RequestUser } from '../../common/types/request-user';
import { EmailSendLogController } from './email-send-log.controller';
import { EmailSendLogService } from './email-send-log.service';
import type { QuerySendLogDto } from './dto/query-send-log.dto';
import { EmailSendOrchestrator } from './email-send-orchestrator.service';
import { EMPTY_CONTENT_FILTER_RULES } from '@bookorbit/types';
describe('EmailSendLogController', () => {
const user: RequestUser = {
id: 11,
username: 'sender',
name: 'Sender',
email: 'sender@example.com',
active: true,
isDefaultPassword: false,
tokenVersion: 1,
settings: {},
avatarUrl: null,
provisioningMethod: 'manual',
isSuperuser: false,
permissions: [],
contentFilters: EMPTY_CONTENT_FILTER_RULES,
};
const logService = {
findForUser: vi.fn(),
summary: vi.fn(),
findAttention: vi.fn(),
remove: vi.fn(),
} as unknown as EmailSendLogService;
const orchestrator = {
resend: vi.fn(),
} as unknown as EmailSendOrchestrator;
const controller = new EmailSendLogController(logService, orchestrator);
beforeEach(() => {
vi.clearAllMocks();
});
it('uses default pagination values when query is empty', async () => {
await controller.findForUser({} as QuerySendLogDto, user);
expect(logService.findForUser).toHaveBeenCalledWith(user, 0, 20, { bookId: undefined, status: undefined, recipientId: undefined });
});
it('forwards explicit pagination values', async () => {
await controller.findForUser({ page: 4, size: 5 }, user);
expect(logService.findForUser).toHaveBeenCalledWith(user, 4, 5, { bookId: undefined, status: undefined, recipientId: undefined });
});
it('forwards the book filter', async () => {
await controller.findForUser({ bookId: 965 }, user);
expect(logService.findForUser).toHaveBeenCalledWith(user, 0, 20, { bookId: 965, status: undefined, recipientId: undefined });
});
it('forwards the status filter', async () => {
await controller.findForUser({ status: 'failed' }, user);
expect(logService.findForUser).toHaveBeenCalledWith(user, 0, 20, { bookId: undefined, status: 'failed', recipientId: undefined });
});
it('forwards the recipient filter', async () => {
await controller.findForUser({ recipientId: 7 }, user);
expect(logService.findForUser).toHaveBeenCalledWith(user, 0, 20, { bookId: undefined, status: undefined, recipientId: 7 });
});
it("delegates summary and attention to the caller's own log", async () => {
await controller.summary(user);
await controller.attention(user);
expect(logService.summary).toHaveBeenCalledWith(user);
expect(logService.findAttention).toHaveBeenCalledWith(user);
});
it('delegates remove', async () => {
await controller.remove(88, user);
expect(logService.remove).toHaveBeenCalledWith(88, user);
});
it('delegates resend', async () => {
await controller.resend(88, user);
expect(orchestrator.resend).toHaveBeenCalledWith(88, user);
});
});