mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +00:00
Pass user ID to addSyncShelvesJob
Include the requesting user's ID as an additional argument when enqueueing immediate shelf sync jobs so the job has user context. Updated the route implementation and adjusted affected tests (goodreads-shelves-id, hardcover-shelves-id, and hardcover-shelves routes tests) to expect the extra 'user-1' parameter.
This commit is contained in:
@@ -156,7 +156,7 @@ export async function PATCH(
|
|||||||
if (needsResync) {
|
if (needsResync) {
|
||||||
try {
|
try {
|
||||||
const jobQueue = getJobQueueService();
|
const jobQueue = getJobQueueService();
|
||||||
await jobQueue.addSyncShelvesJob(undefined, updated.id, 'hardcover', 0);
|
await jobQueue.addSyncShelvesJob(undefined, updated.id, 'hardcover', 0, req.user.id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to trigger immediate list sync', {
|
logger.error('Failed to trigger immediate list sync', {
|
||||||
error: error instanceof Error ? error.message : String(error),
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ describe('PATCH /api/user/goodreads-shelves/[id]', () => {
|
|||||||
where: { id: 'shelf-1' },
|
where: { id: 'shelf-1' },
|
||||||
data: { rssUrl: NEW_RSS, lastSyncAt: null, bookCount: null, coverUrls: null },
|
data: { rssUrl: NEW_RSS, lastSyncAt: null, bookCount: null, coverUrls: null },
|
||||||
});
|
});
|
||||||
expect(jobQueueMock.addSyncShelvesJob).toHaveBeenCalledWith(undefined, updatedShelf.id, 'goodreads', 0);
|
expect(jobQueueMock.addSyncShelvesJob).toHaveBeenCalledWith(undefined, updatedShelf.id, 'goodreads', 0, 'user-1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('still returns 200 even when the sync job fails to enqueue', async () => {
|
it('still returns 200 even when the sync job fails to enqueue', async () => {
|
||||||
|
|||||||
@@ -195,6 +195,7 @@ describe('PATCH /api/user/hardcover-shelves/[id]', () => {
|
|||||||
SHELF.id,
|
SHELF.id,
|
||||||
'hardcover',
|
'hardcover',
|
||||||
0,
|
0,
|
||||||
|
'user-1',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -216,7 +217,7 @@ describe('PATCH /api/user/hardcover-shelves/[id]', () => {
|
|||||||
where: { id: 'hc-shelf-1' },
|
where: { id: 'hc-shelf-1' },
|
||||||
data: expect.objectContaining({ listId: 'status-3', lastSyncAt: null }),
|
data: expect.objectContaining({ listId: 'status-3', lastSyncAt: null }),
|
||||||
});
|
});
|
||||||
expect(jobQueueMock.addSyncShelvesJob).toHaveBeenCalledWith(undefined, updated.id, 'hardcover', 0);
|
expect(jobQueueMock.addSyncShelvesJob).toHaveBeenCalledWith(undefined, updated.id, 'hardcover', 0, 'user-1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('encrypts the apiToken before persisting', async () => {
|
it('encrypts the apiToken before persisting', async () => {
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ describe('POST /api/user/hardcover-shelves', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Immediate background sync must have been triggered
|
// Immediate background sync must have been triggered
|
||||||
expect(jobQueueMock.addSyncShelvesJob).toHaveBeenCalledWith(undefined, 'new-shelf', 'hardcover', 0);
|
expect(jobQueueMock.addSyncShelvesJob).toHaveBeenCalledWith(undefined, 'new-shelf', 'hardcover', 0, 'user-1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('strips Bearer prefix from apiToken before encrypting', async () => {
|
it('strips Bearer prefix from apiToken before encrypting', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user