Add reported-issues, Goodreads sync & notifs

Introduce user-reported-issues and Goodreads shelf sync features and wire them into notifications. Adds Prisma migrations and schema changes (ReportedIssue, GoodreadsShelf, GoodreadsBookMapping), API endpoints for reporting (POST /audiobooks/[asin]/report-issue) and admin management (list, resolve/dismiss, replace), and an admin UI section to view/dismiss/replace reported issues. Adds a new notification event (issue_reported) with updates to notification schemas, docs and provider handling, plus a notification-events constants file. Refactors request creation to use createRequestForUser service, adds a Goodreads sync processor/service/hooks/UI modals, a scrape-resilience util, and related tests and minor integration updates.
This commit is contained in:
kikootwo
2026-02-11 16:49:55 -05:00
parent b013538b63
commit 20c8fb0898
69 changed files with 4167 additions and 766 deletions
+89 -4
View File
@@ -18,6 +18,7 @@ prismaMock.notificationBackend = {
const encryptionMock = vi.hoisted(() => ({
encrypt: vi.fn((value: string) => `enc:${value}`),
decrypt: vi.fn((value: string) => value.replace('enc:', '')),
isEncryptedFormat: vi.fn((value: string) => typeof value === 'string' && value.startsWith('enc:')),
}));
const fetchMock = vi.hoisted(() => vi.fn());
@@ -196,10 +197,9 @@ describe('NotificationService', () => {
const { NotificationService } = await import('@/lib/services/notification');
const service = new NotificationService();
// Use iv:authTag:data format to pass isEncrypted() check
await service.sendToBackend(
'pushover',
{ userKey: 'iv:tag:user123', appToken: 'iv:tag:app456', priority: 1 },
{ userKey: 'enc:user123', appToken: 'enc:app456', priority: 1 },
{
event: 'request_approved',
requestId: 'req-1',
@@ -210,8 +210,8 @@ describe('NotificationService', () => {
}
);
expect(encryptionMock.decrypt).toHaveBeenCalledWith('iv:tag:user123');
expect(encryptionMock.decrypt).toHaveBeenCalledWith('iv:tag:app456');
expect(encryptionMock.decrypt).toHaveBeenCalledWith('enc:user123');
expect(encryptionMock.decrypt).toHaveBeenCalledWith('enc:app456');
expect(fetchMock).toHaveBeenCalled();
});
@@ -519,6 +519,91 @@ describe('NotificationService', () => {
});
});
describe('reEncryptUnprotectedBackends', () => {
it('re-encrypts plaintext sensitive fields stored due to isEncrypted bug', async () => {
// Simulate a backend with a Telegram URL stored as plaintext (the bug)
prismaMock.notificationBackend.findMany.mockResolvedValue([
{
id: 'backend-1',
type: 'apprise',
name: 'Telegram via Apprise',
config: {
serverUrl: 'http://apprise:8000',
urls: 'tgram://1234567890:PLPe1Hh-VhbRC3MoT5QngwkPHoMTD/-100181291455/',
},
events: ['request_available'],
enabled: true,
createdAt: new Date(),
updatedAt: new Date(),
},
]);
prismaMock.notificationBackend.update.mockResolvedValue({} as any);
// Mock isEncryptedFormat to return false for the plaintext URL
encryptionMock.isEncryptedFormat.mockImplementation(
(value: string) => typeof value === 'string' && value.startsWith('enc:')
);
const { NotificationService } = await import('@/lib/services/notification');
const service = new NotificationService();
const fixed = await service.reEncryptUnprotectedBackends();
expect(fixed).toBe(1);
expect(encryptionMock.encrypt).toHaveBeenCalledWith(
'tgram://1234567890:PLPe1Hh-VhbRC3MoT5QngwkPHoMTD/-100181291455/'
);
expect(prismaMock.notificationBackend.update).toHaveBeenCalledWith({
where: { id: 'backend-1' },
data: {
config: {
serverUrl: 'http://apprise:8000',
urls: 'enc:tgram://1234567890:PLPe1Hh-VhbRC3MoT5QngwkPHoMTD/-100181291455/',
},
},
});
});
it('skips backends with already-encrypted fields', async () => {
prismaMock.notificationBackend.findMany.mockResolvedValue([
{
id: 'backend-1',
type: 'discord',
name: 'Discord',
config: { webhookUrl: 'enc:https://discord.com/webhook', username: 'Bot' },
events: ['request_available'],
enabled: true,
createdAt: new Date(),
updatedAt: new Date(),
},
]);
encryptionMock.isEncryptedFormat.mockImplementation(
(value: string) => typeof value === 'string' && value.startsWith('enc:')
);
const { NotificationService } = await import('@/lib/services/notification');
const service = new NotificationService();
const fixed = await service.reEncryptUnprotectedBackends();
expect(fixed).toBe(0);
expect(prismaMock.notificationBackend.update).not.toHaveBeenCalled();
});
it('returns 0 when no backends exist', async () => {
prismaMock.notificationBackend.findMany.mockResolvedValue([]);
const { NotificationService } = await import('@/lib/services/notification');
const service = new NotificationService();
const fixed = await service.reEncryptUnprotectedBackends();
expect(fixed).toBe(0);
});
});
describe('maskConfig', () => {
it('masks sensitive Discord config values', async () => {
const { NotificationService } = await import('@/lib/services/notification');