mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
fix(dashboard): include read status in scroller cards
This commit is contained in:
@@ -61,6 +61,8 @@ function makeFindCardsResult(idsInRowOrder: number[]) {
|
||||
authorRows: [],
|
||||
fileRows: idsInRowOrder.map((id) => ({ bookId: id, id: id * 10, format: 'epub', role: 'primary' })),
|
||||
genreRows: [],
|
||||
tagRows: [],
|
||||
narratorRows: [],
|
||||
progressRows: [],
|
||||
statusRows: [],
|
||||
total: idsInRowOrder.length,
|
||||
@@ -109,13 +111,26 @@ describe('DashboardService', () => {
|
||||
const user = makeUser({ id: 5 });
|
||||
libraryService.findAccessibleLibraryIds.mockResolvedValue([100, 200]);
|
||||
dashboardRepo.findRecentlyAddedBookIds.mockResolvedValue([9, 3]);
|
||||
bookReadService.findCardsByBookIds.mockResolvedValue(makeFindCardsResult([3, 9]));
|
||||
bookReadService.findCardsByBookIds.mockResolvedValue({
|
||||
...makeFindCardsResult([3, 9]),
|
||||
statusRows: [
|
||||
{
|
||||
bookId: 9,
|
||||
status: 'reading',
|
||||
source: 'manual',
|
||||
startedAt: null,
|
||||
finishedAt: null,
|
||||
updatedAt: new Date('2026-01-03T00:00:00.000Z'),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const result = await service.getScroller(ScrollerType.RECENTLY_ADDED, user, 0);
|
||||
|
||||
expect(dashboardRepo.findRecentlyAddedBookIds).toHaveBeenCalledWith([100, 200], 1);
|
||||
expect(bookReadService.findCardsByBookIds).toHaveBeenCalledWith([9, 3], 5);
|
||||
expect(result.map((card) => card.id)).toEqual([9, 3]);
|
||||
expect(result[0]?.readStatus?.status).toBe('reading');
|
||||
});
|
||||
|
||||
it('routes continue reading requests to repository with clamped max limit', async () => {
|
||||
|
||||
@@ -22,8 +22,11 @@ export class DashboardService {
|
||||
|
||||
private async loadCardsByIds(bookIds: number[], userId: number): Promise<BookCard[]> {
|
||||
if (bookIds.length === 0) return [];
|
||||
const { rows, authorRows, fileRows, genreRows, progressRows } = await this.bookReadService.findCardsByBookIds(bookIds, userId);
|
||||
const cards = assembleBookCards(rows, authorRows, fileRows, genreRows, progressRows);
|
||||
const { rows, authorRows, fileRows, genreRows, progressRows, statusRows, narratorRows, tagRows } = await this.bookReadService.findCardsByBookIds(
|
||||
bookIds,
|
||||
userId,
|
||||
);
|
||||
const cards = assembleBookCards(rows, authorRows, fileRows, genreRows, progressRows, statusRows, narratorRows, tagRows);
|
||||
const cardsById = new Map(cards.map((card) => [card.id, card]));
|
||||
return bookIds.map((id) => cardsById.get(id)).filter((card): card is BookCard => card != null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user