Full tests coverage

This commit is contained in:
Aerilyn Weber 2026-05-19 14:09:03 +09:00
parent 99134d8556
commit 02d782c3da
157 changed files with 1074 additions and 34670 deletions

View file

@ -53,6 +53,12 @@ describe('ApiClient', () => {
});
});
describe('baseUrl', () => {
it('returns the configured API base URL', () => {
expect(apiClient.baseUrl).toBeDefined();
});
});
describe('get', () => {
it('makes GET request to correct URL', async () => {
const spy = mockFetch({ id: '1' });
@ -130,6 +136,16 @@ describe('ApiClient', () => {
expect.objectContaining({ method: 'DELETE' }),
);
});
it('includes Authorization header in DELETE request when token is set', async () => {
const spy = mockFetch(undefined, 204);
apiClient.accessToken = 'delete-jwt';
await apiClient.delete('/stores/1');
const headers = spy.mock.calls[0][1]?.headers as Record<string, string>;
expect(headers['Authorization']).toBe('Bearer delete-jwt');
});
});
describe('error handling', () => {

View file

@ -32,6 +32,12 @@ describe('cabinet-events service', () => {
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('startDate=2026-01-01'));
});
it('getEventsByItem with no query', async () => {
mockGet.mockResolvedValue({ data: [] });
await getEventsByItem('hh1', 'ci-1');
expect(mockGet).toHaveBeenCalledWith('/households/hh1/cabinet-events/by-item/ci-1');
});
it('getEventsByItem builds URL with cabinetItemId', async () => {
mockGet.mockResolvedValue({ data: [] });
await getEventsByItem('hh1', 'ci-1', { limit: 5 });

View file

@ -69,6 +69,12 @@ describe('medicines service', () => {
expect(mockDelete).toHaveBeenCalledWith('/households/hh1/medicines/med-1');
});
it('listMedicineProducts with no query', async () => {
mockGet.mockResolvedValue({ data: [] });
await listMedicineProducts('hh1', 'med-1');
expect(mockGet).toHaveBeenCalledWith('/households/hh1/medicines/med-1/products');
});
it('listMedicineProducts builds URL with medicineId', async () => {
mockGet.mockResolvedValue({ data: [] });
await listMedicineProducts('hh1', 'med-1', { limit: 5 });

View file

@ -31,9 +31,10 @@ describe('purchases service', () => {
it('listPurchases builds query string', async () => {
mockGet.mockResolvedValue({ data: [] });
await listPurchases('hh1', { status: 'ordered', storeId: 'st-1', limit: 10 });
await listPurchases('hh1', { status: 'ordered', storeId: 'st-1', limit: 10, cursor: 'curr-123' });
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('status=ordered'));
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('storeId=st-1'));
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('cursor=curr-123'));
});
it('getPurchase calls GET', async () => {

View file

@ -36,6 +36,12 @@ describe('refills service', () => {
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('userId=u-1'));
});
it('listRefillLists with no query', async () => {
mockGet.mockResolvedValue({ data: [] });
await listRefillLists('hh1');
expect(mockGet).toHaveBeenCalledWith('/households/hh1/refills/lists');
});
it('listRefillLists with query', async () => {
mockGet.mockResolvedValue({ data: [] });
await listRefillLists('hh1', { status: 'active' });

View file

@ -83,5 +83,10 @@ describe('shopping-lists service', () => {
apiClient.baseUrl = 'https://api.meshitrack.com';
const urlSecure = ShoppingListsService.getShoppingListSyncSocketUrl('hh1', 'list1');
expect(urlSecure).toBe('wss://api.meshitrack.com/households/hh1/shopping-lists/list1/sync');
// Test falsy baseUrl fallback path
(apiClient as any).baseUrl = '';
const urlFalsy = ShoppingListsService.getShoppingListSyncSocketUrl('hh1', 'list1');
expect(urlFalsy).toBe('ws:///households/hh1/shopping-lists/list1/sync');
});
});