Use hardcover-api service with pagination

Replace the old hardcover sync usage with a new hardcover-api.service implementation that adds types, a reusable extractBooks helper, and paginated GraphQL queries (limit/offset) to fully fetch status and list books. Update API route import to use the new service. Fix ManageShelfModal to initialize rssUrl/listId as empty strings. Update tests to mock the new service and add encryption format helper mocking.
This commit is contained in:
kikootwo
2026-03-04 10:28:52 -05:00
parent 338331d006
commit 7f706e806f
5 changed files with 145 additions and 81 deletions
@@ -16,8 +16,11 @@ const jobQueueMock = vi.hoisted(() => ({
const encryptionMock = vi.hoisted(() => ({
encrypt: vi.fn((s: string) => `enc:${s}`),
decrypt: vi.fn((s: string) => s.replace('enc:', '')),
isEncryptedFormat: vi.fn((s: string) => s.startsWith('enc:')),
}));
const fetchHardcoverListMock = vi.hoisted(() => vi.fn());
vi.mock('@/lib/middleware/auth', () => ({
requireAuth: requireAuthMock,
}));
@@ -34,6 +37,10 @@ vi.mock('@/lib/services/encryption.service', () => ({
getEncryptionService: () => encryptionMock,
}));
vi.mock('@/lib/services/hardcover-api.service', () => ({
fetchHardcoverList: fetchHardcoverListMock,
}));
const SHELF = {
id: 'hc-shelf-1',
userId: 'user-1',
@@ -106,6 +113,10 @@ describe('PATCH /api/user/hardcover-shelves/[id]', () => {
vi.clearAllMocks();
authRequest = { user: { id: 'user-1', role: 'user' } };
requireAuthMock.mockImplementation((_req: any, handler: any) => handler(authRequest));
encryptionMock.isEncryptedFormat.mockImplementation((s: string) => s.startsWith('enc:'));
encryptionMock.encrypt.mockImplementation((s: string) => `enc:${s}`);
encryptionMock.decrypt.mockImplementation((s: string) => s.replace('enc:', ''));
fetchHardcoverListMock.mockResolvedValue({ listName: 'Test List', books: [] });
});
it('returns 404 when list does not exist', async () => {
+1 -1
View File
@@ -35,7 +35,7 @@ vi.mock('@/lib/services/encryption.service', () => ({
getEncryptionService: () => encryptionMock,
}));
vi.mock('@/lib/services/hardcover-sync.service', () => ({
vi.mock('@/lib/services/hardcover-api.service', () => ({
fetchHardcoverList: fetchHardcoverListMock,
}));