refactor(frontend): rename booklore-ui to frontend
- Frontend path: - rename the tracked Angular app tree from `booklore-ui/` to `frontend/` - preserve file contents during the move so this commit stays focused on the path change itself - Frontend docs: - update the moved frontend README and contribution guide where they refer to the renamed folder - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import {beforeEach, describe, expect, it, vi} from 'vitest';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {of, Subject} from 'rxjs';
|
||||
import {IMessage} from '@stomp/rx-stomp';
|
||||
import {provideTanStackQuery, QueryClient} from '@tanstack/angular-query-experimental';
|
||||
|
||||
import {LibraryHealthService} from './library-health.service';
|
||||
import {RxStompService} from '../../../shared/websocket/rx-stomp.service';
|
||||
|
||||
describe('LibraryHealthService', () => {
|
||||
let service: LibraryHealthService;
|
||||
let queryClient: QueryClient;
|
||||
let httpGetSpy: ReturnType<typeof vi.fn>;
|
||||
let wsSubject: Subject<IMessage>;
|
||||
|
||||
beforeEach(() => {
|
||||
httpGetSpy = vi.fn().mockReturnValue(of({}));
|
||||
wsSubject = new Subject<IMessage>();
|
||||
queryClient = new QueryClient();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
provideTanStackQuery(queryClient),
|
||||
LibraryHealthService,
|
||||
{provide: HttpClient, useValue: {get: httpGetSpy}},
|
||||
{provide: RxStompService, useValue: {watch: vi.fn(() => wsSubject.asObservable())}},
|
||||
]
|
||||
});
|
||||
|
||||
service = TestBed.inject(LibraryHealthService);
|
||||
});
|
||||
|
||||
async function initializeService(): Promise<void> {
|
||||
const fetchQuerySpy = vi.spyOn(queryClient, 'fetchQuery');
|
||||
service.initialize();
|
||||
await fetchQuerySpy.mock.results[0]?.value;
|
||||
}
|
||||
|
||||
it('fetches initial health on initialize', async () => {
|
||||
httpGetSpy.mockReturnValue(of({1: true, 2: false}));
|
||||
|
||||
await initializeService();
|
||||
|
||||
expect(httpGetSpy).toHaveBeenCalledOnce();
|
||||
expect(service.health()).toEqual({1: true, 2: false});
|
||||
});
|
||||
|
||||
it('reports unhealthy for a library with false health', async () => {
|
||||
httpGetSpy.mockReturnValue(of({1: true, 2: false}));
|
||||
|
||||
await initializeService();
|
||||
|
||||
expect(service.isUnhealthy(2)).toBe(true);
|
||||
});
|
||||
|
||||
it('reports healthy for a library with true health', async () => {
|
||||
httpGetSpy.mockReturnValue(of({1: true}));
|
||||
|
||||
await initializeService();
|
||||
|
||||
expect(service.isUnhealthy(1)).toBe(false);
|
||||
});
|
||||
|
||||
it('reports false for an unknown library', async () => {
|
||||
httpGetSpy.mockReturnValue(of({}));
|
||||
|
||||
await initializeService();
|
||||
|
||||
expect(service.isUnhealthy(99)).toBe(false);
|
||||
});
|
||||
|
||||
it('updates state from websocket messages', async () => {
|
||||
httpGetSpy.mockReturnValue(of({1: true}));
|
||||
|
||||
await initializeService();
|
||||
wsSubject.next({body: JSON.stringify({libraryHealth: {1: false}})} as IMessage);
|
||||
|
||||
expect(service.isUnhealthy(1)).toBe(true);
|
||||
expect(service.health()).toEqual({1: false});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user