fix(reader): add fetchFreshBookDetail method to ensure up-to-date reading position across devices (#358)

* fix(reader): add fetchFreshBookDetail method to ensure up-to-date reading position across devices

* test(audiobook): enhance tests to verify queryClient interactions for progress updates

* fix(audiobook): include audiobookProgress and fileProgress in progress payload
This commit is contained in:
brios
2026-04-22 17:27:06 -04:00
committed by Zach Yale
parent cf7999044f
commit 4527d43e84
9 changed files with 76 additions and 23 deletions
@@ -1,6 +1,7 @@
import {provideHttpClient} from '@angular/common/http';
import {HttpTestingController, provideHttpClientTesting} from '@angular/common/http/testing';
import {TestBed} from '@angular/core/testing';
import {QueryClient} from '@tanstack/angular-query-experimental';
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import {AuthService} from '../../../shared/service/auth.service';
@@ -10,20 +11,22 @@ import {AudiobookService} from './audiobook.service';
describe('AudiobookService', () => {
let service: AudiobookService;
let httpTestingController: HttpTestingController;
let queryClient: QueryClient;
let getInternalAccessToken: ReturnType<typeof vi.fn>;
beforeEach(() => {
getInternalAccessToken = vi.fn(() => 'token 123');
queryClient = new QueryClient();
vi.spyOn(queryClient, 'setQueryData');
vi.spyOn(queryClient, 'invalidateQueries').mockResolvedValue();
TestBed.configureTestingModule({
providers: [
provideHttpClient(),
provideHttpClientTesting(),
AudiobookService,
{
provide: AuthService,
useValue: {getInternalAccessToken},
},
{provide: AuthService, useValue: {getInternalAccessToken}},
{provide: QueryClient, useValue: queryClient},
],
});
@@ -33,6 +36,7 @@ describe('AudiobookService', () => {
afterEach(() => {
httpTestingController.verify();
queryClient.clear();
TestBed.resetTestingModule();
vi.restoreAllMocks();
});
@@ -85,9 +89,10 @@ describe('AudiobookService', () => {
request.flush(null);
expect(completed).toBe(true);
expect(queryClient.setQueryData).toHaveBeenCalledWith(['books'], expect.any(Function));
});
it('maps audiobook progress into a file progress payload when a book file id is present', () => {
it('includes both audiobookProgress and fileProgress in the payload when a book file id is present', () => {
const progress: AudiobookProgress = {
positionMs: 75_000,
trackIndex: 5,
@@ -100,6 +105,7 @@ describe('AudiobookService', () => {
expect(request.request.method).toBe('POST');
expect(request.request.body).toEqual({
bookId: 12,
audiobookProgress: progress,
fileProgress: {
bookFileId: 99,
positionData: '75000',
@@ -108,5 +114,7 @@ describe('AudiobookService', () => {
},
});
request.flush(null);
expect(queryClient.setQueryData).toHaveBeenCalledWith(['books'], expect.any(Function));
});
});