mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
89422fc77a
Introduce full authors browsing/detail feature and enhance notifications to support type-specific titles. - Add server APIs: authors search, author detail, and author books routes (audnexus integration) that require auth and enrich results with library matches. - Add frontend pages/components: /authors listing and /authors/[asin] detail pages; AuthorCard, AuthorGrid, AuthorDetailCard, SimilarAuthorsRow, and related skeletons. - Add hook and integration stubs: new useAuthors hook and audnexus-authors integration; update audible service to expose audibleBaseUrl. - Update AudiobookDetailsModal to use audibleBaseUrl and link author names to author detail pages. - Add header navigation link to Authors. - Notifications: extend docs and code to include requestType (audiobook|ebook), add getEventTitle/getEventMeta helpers, update queue signature and providers/processors/tests to pass/handle requestType so titles can be resolved per request type. - Misc: job queue, processors, provider tests and notification tests updated to reflect new behavior. This change enables browsing authors and provides type-aware notification titles without per-provider changes.
147 lines
4.2 KiB
TypeScript
147 lines
4.2 KiB
TypeScript
/**
|
|
* Component: Send Notification Processor Tests
|
|
* Documentation: documentation/backend/services/notifications.md
|
|
*/
|
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import type { NotificationEvent } from '@/lib/constants/notification-events';
|
|
|
|
const notificationServiceMock = vi.hoisted(() => ({
|
|
sendNotification: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('@/lib/services/notification', () => ({
|
|
getNotificationService: () => notificationServiceMock,
|
|
}));
|
|
|
|
describe('processSendNotification', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('calls notification service with correct payload', async () => {
|
|
const { processSendNotification } = await import('@/lib/processors/send-notification.processor');
|
|
|
|
const payload = {
|
|
event: 'request_approved' as const,
|
|
requestId: 'req-1',
|
|
title: 'Test Book',
|
|
author: 'Test Author',
|
|
userName: 'Test User',
|
|
timestamp: new Date('2024-01-01T00:00:00Z'),
|
|
jobId: 'job-1',
|
|
};
|
|
|
|
await processSendNotification(payload);
|
|
|
|
expect(notificationServiceMock.sendNotification).toHaveBeenCalledWith({
|
|
event: 'request_approved',
|
|
requestId: 'req-1',
|
|
title: 'Test Book',
|
|
author: 'Test Author',
|
|
userName: 'Test User',
|
|
timestamp: expect.any(Date),
|
|
});
|
|
});
|
|
|
|
it('includes error message if provided', async () => {
|
|
const { processSendNotification } = await import('@/lib/processors/send-notification.processor');
|
|
|
|
const payload = {
|
|
event: 'request_error' as const,
|
|
requestId: 'req-1',
|
|
title: 'Test Book',
|
|
author: 'Test Author',
|
|
userName: 'Test User',
|
|
message: 'Download failed',
|
|
timestamp: new Date('2024-01-01T00:00:00Z'),
|
|
jobId: 'job-1',
|
|
};
|
|
|
|
await processSendNotification(payload);
|
|
|
|
expect(notificationServiceMock.sendNotification).toHaveBeenCalledWith({
|
|
event: 'request_error',
|
|
requestId: 'req-1',
|
|
title: 'Test Book',
|
|
author: 'Test Author',
|
|
userName: 'Test User',
|
|
message: 'Download failed',
|
|
timestamp: expect.any(Date),
|
|
});
|
|
});
|
|
|
|
it('forwards requestType to notification service', async () => {
|
|
const { processSendNotification } = await import('@/lib/processors/send-notification.processor');
|
|
|
|
const payload = {
|
|
event: 'request_available' as const,
|
|
requestId: 'req-1',
|
|
title: 'Test Book',
|
|
author: 'Test Author',
|
|
userName: 'Test User',
|
|
requestType: 'ebook',
|
|
timestamp: new Date('2024-01-01T00:00:00Z'),
|
|
jobId: 'job-1',
|
|
};
|
|
|
|
await processSendNotification(payload);
|
|
|
|
expect(notificationServiceMock.sendNotification).toHaveBeenCalledWith({
|
|
event: 'request_available',
|
|
requestId: 'req-1',
|
|
title: 'Test Book',
|
|
author: 'Test Author',
|
|
userName: 'Test User',
|
|
requestType: 'ebook',
|
|
timestamp: expect.any(Date),
|
|
});
|
|
});
|
|
|
|
it('does not throw if notification service fails', async () => {
|
|
notificationServiceMock.sendNotification.mockRejectedValue(new Error('Service error'));
|
|
|
|
const { processSendNotification } = await import('@/lib/processors/send-notification.processor');
|
|
|
|
const payload = {
|
|
event: 'request_approved' as const,
|
|
requestId: 'req-1',
|
|
title: 'Test Book',
|
|
author: 'Test Author',
|
|
userName: 'Test User',
|
|
timestamp: new Date('2024-01-01T00:00:00Z'),
|
|
jobId: 'job-1',
|
|
};
|
|
|
|
// Should not throw
|
|
await expect(processSendNotification(payload)).resolves.toBeUndefined();
|
|
});
|
|
|
|
it('processes all event types correctly', async () => {
|
|
const { processSendNotification } = await import('@/lib/processors/send-notification.processor');
|
|
|
|
const events: NotificationEvent[] = [
|
|
'request_pending_approval',
|
|
'request_approved',
|
|
'request_available',
|
|
'request_error',
|
|
];
|
|
|
|
for (const event of events) {
|
|
const payload = {
|
|
event,
|
|
requestId: 'req-1',
|
|
title: 'Test Book',
|
|
author: 'Test Author',
|
|
userName: 'Test User',
|
|
timestamp: new Date('2024-01-01T00:00:00Z'),
|
|
jobId: 'job-1',
|
|
};
|
|
|
|
await processSendNotification(payload);
|
|
}
|
|
|
|
expect(notificationServiceMock.sendNotification).toHaveBeenCalledTimes(4);
|
|
});
|
|
});
|