Phase 5 cleanup

This commit is contained in:
Aerilyn Weber 2026-04-26 18:44:59 +09:00
parent 5536acd67d
commit 76a516a417
136 changed files with 6322 additions and 1985 deletions

View file

@ -1,7 +1,9 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import type { apiClient as ApiClientType } from '../api-client';
// Create a fresh ApiClient for each test by re-importing
let apiClient: typeof import('../api-client').apiClient;
let apiClient: typeof ApiClientType;
beforeEach(async () => {
vi.restoreAllMocks();

View file

@ -21,7 +21,12 @@ describe('cabinet-events service', () => {
it('listCabinetEvents builds query string', async () => {
mockGet.mockResolvedValue({ data: [] });
await listCabinetEvents('hh1', { medicineId: 'med-1', eventType: 'dispense', startDate: '2026-01-01', endDate: '2026-02-01' });
await listCabinetEvents('hh1', {
medicineId: 'med-1',
eventType: 'dispense',
startDate: '2026-01-01',
endDate: '2026-02-01',
});
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('medicineId=med-1'));
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('eventType=dispense'));
expect(mockGet).toHaveBeenCalledWith(expect.stringContaining('startDate=2026-01-01'));

View file

@ -12,8 +12,14 @@ vi.mock('../api-client', () => ({
}));
import {
listCabinetItems, getCabinetItem, getCabinetSummary, getExpiringSoon,
createCabinetItem, updateCabinetItem, adjustCabinetItemQuantity, deleteCabinetItem,
listCabinetItems,
getCabinetItem,
getCabinetSummary,
getExpiringSoon,
createCabinetItem,
updateCabinetItem,
adjustCabinetItemQuantity,
deleteCabinetItem,
} from '../cabinet';
beforeEach(() => vi.clearAllMocks());
@ -80,7 +86,10 @@ describe('cabinet service', () => {
it('adjustCabinetItemQuantity calls POST', async () => {
mockPost.mockResolvedValue({ _id: 'ci-1' });
await adjustCabinetItemQuantity('hh1', 'ci-1', { adjustment: -5, reason: 'used' } as never);
expect(mockPost).toHaveBeenCalledWith('/households/hh1/cabinet/ci-1/adjust', { adjustment: -5, reason: 'used' });
expect(mockPost).toHaveBeenCalledWith('/households/hh1/cabinet/ci-1/adjust', {
adjustment: -5,
reason: 'used',
});
});
it('deleteCabinetItem calls DELETE', async () => {

View file

@ -10,7 +10,13 @@ vi.mock('../api-client', () => ({
apiClient: { get: mockGet, post: mockPost, patch: mockPatch },
}));
import { createHousehold, getHousehold, updateHousehold, generateInviteCode, joinHousehold } from '../households';
import {
createHousehold,
getHousehold,
updateHousehold,
generateInviteCode,
joinHousehold,
} from '../households';
beforeEach(() => vi.clearAllMocks());

View file

@ -12,8 +12,15 @@ vi.mock('../api-client', () => ({
}));
import {
listMedicines, getMedicine, createMedicine, updateMedicine, deleteMedicine,
listMedicineProducts, createMedicineProduct, updateMedicineProduct, deleteMedicineProduct,
listMedicines,
getMedicine,
createMedicine,
updateMedicine,
deleteMedicine,
listMedicineProducts,
createMedicineProduct,
updateMedicineProduct,
deleteMedicineProduct,
} from '../medicines';
beforeEach(() => vi.clearAllMocks());
@ -77,13 +84,17 @@ describe('medicines service', () => {
it('createMedicineProduct calls POST', async () => {
mockPost.mockResolvedValue({ _id: 'mp-1' });
await createMedicineProduct('hh1', 'med-1', { brand: 'Bayer' } as never);
expect(mockPost).toHaveBeenCalledWith('/households/hh1/medicines/med-1/products', { brand: 'Bayer' });
expect(mockPost).toHaveBeenCalledWith('/households/hh1/medicines/med-1/products', {
brand: 'Bayer',
});
});
it('updateMedicineProduct uses medicine-products path', async () => {
mockPatch.mockResolvedValue({ _id: 'mp-1' });
await updateMedicineProduct('hh1', 'mp-1', { brand: 'Updated' } as never);
expect(mockPatch).toHaveBeenCalledWith('/households/hh1/medicine-products/mp-1', { brand: 'Updated' });
expect(mockPatch).toHaveBeenCalledWith('/households/hh1/medicine-products/mp-1', {
brand: 'Updated',
});
});
it('deleteMedicineProduct calls DELETE', async () => {

View file

@ -11,7 +11,14 @@ vi.mock('../api-client', () => ({
apiClient: { get: mockGet, post: mockPost, patch: mockPatch, delete: mockDelete },
}));
import { listPurchases, getPurchase, createPurchase, updatePurchase, receivePurchase, deletePurchase } from '../purchases';
import {
listPurchases,
getPurchase,
createPurchase,
updatePurchase,
receivePurchase,
deletePurchase,
} from '../purchases';
beforeEach(() => vi.clearAllMocks());

View file

@ -11,8 +11,13 @@ vi.mock('../api-client', () => ({
}));
import {
getRefillAlerts, listRefillLists, createRefillList, getRefillList,
updateRefillList, updateRefillListItem, addToCabinet,
getRefillAlerts,
listRefillLists,
createRefillList,
getRefillList,
updateRefillList,
updateRefillListItem,
addToCabinet,
} from '../refills';
beforeEach(() => vi.clearAllMocks());
@ -60,16 +65,17 @@ describe('refills service', () => {
it('updateRefillList calls PATCH', async () => {
mockPatch.mockResolvedValue({ _id: 'rl-1' });
await updateRefillList('hh1', 'rl-1', { name: 'Updated' } as never);
expect(mockPatch).toHaveBeenCalledWith('/households/hh1/refills/lists/rl-1', { name: 'Updated' });
expect(mockPatch).toHaveBeenCalledWith('/households/hh1/refills/lists/rl-1', {
name: 'Updated',
});
});
it('updateRefillListItem calls PATCH with nested path', async () => {
mockPatch.mockResolvedValue({ _id: 'rl-1' });
await updateRefillListItem('hh1', 'rl-1', 'item-1', { purchased: true } as never);
expect(mockPatch).toHaveBeenCalledWith(
'/households/hh1/refills/lists/rl-1/items/item-1',
{ purchased: true },
);
expect(mockPatch).toHaveBeenCalledWith('/households/hh1/refills/lists/rl-1/items/item-1', {
purchased: true,
});
});
it('addToCabinet calls POST with empty body', async () => {

View file

@ -11,7 +11,14 @@ vi.mock('../api-client', () => ({
apiClient: { get: mockGet, post: mockPost, patch: mockPatch, delete: mockDelete },
}));
import { listRegimens, getRegimen, getBurnRates, createRegimen, updateRegimen, deleteRegimen } from '../regimens';
import {
listRegimens,
getRegimen,
getBurnRates,
createRegimen,
updateRegimen,
deleteRegimen,
} from '../regimens';
beforeEach(() => vi.clearAllMocks());

View file

@ -27,7 +27,13 @@ export async function recordPrice(
export async function getPriceHistory(
householdId: string,
medicineId: string,
query?: { storeId?: string; startDate?: string; endDate?: string; cursor?: string; limit?: number },
query?: {
storeId?: string;
startDate?: string;
endDate?: string;
cursor?: string;
limit?: number;
},
): Promise<MedicinePriceHistoryResponse> {
const params = new URLSearchParams();
if (query?.storeId) params.set('storeId', query.storeId);

View file

@ -37,7 +37,10 @@ export async function previewFill(
householdId: string,
data: OrganizerPreviewInput,
): Promise<OrganizerPreviewResponse> {
return apiClient.post<OrganizerPreviewResponse>(`/households/${householdId}/organizer/preview`, data);
return apiClient.post<OrganizerPreviewResponse>(
`/households/${householdId}/organizer/preview`,
data,
);
}
export async function executeFill(
@ -47,7 +50,10 @@ export async function executeFill(
return apiClient.post<OrganizerFillResponse>(`/households/${householdId}/organizer/fill`, data);
}
export async function undoFill(householdId: string, fillId: string): Promise<OrganizerFillResponse> {
export async function undoFill(
householdId: string,
fillId: string,
): Promise<OrganizerFillResponse> {
return apiClient.post<OrganizerFillResponse>(
`/households/${householdId}/organizer/fills/${fillId}/undo`,
{},

View file

@ -29,10 +29,7 @@ export async function listPurchases(
);
}
export async function getPurchase(
householdId: string,
id: string,
): Promise<PurchaseResponse> {
export async function getPurchase(householdId: string, id: string): Promise<PurchaseResponse> {
return apiClient.get<PurchaseResponse>(`/households/${householdId}/purchases/${id}`);
}
@ -48,10 +45,7 @@ export async function updatePurchase(
id: string,
data: UpdatePurchaseInput,
): Promise<PurchaseResponse> {
return apiClient.patch<PurchaseResponse>(
`/households/${householdId}/purchases/${id}`,
data,
);
return apiClient.patch<PurchaseResponse>(`/households/${householdId}/purchases/${id}`, data);
}
export async function receivePurchase(

View file

@ -49,16 +49,10 @@ export async function createRefillList(
householdId: string,
data: CreateRefillListInput,
): Promise<RefillListResponse> {
return apiClient.post<RefillListResponse>(
`/households/${householdId}/refills/lists`,
data,
);
return apiClient.post<RefillListResponse>(`/households/${householdId}/refills/lists`, data);
}
export async function getRefillList(
householdId: string,
id: string,
): Promise<RefillListResponse> {
export async function getRefillList(householdId: string, id: string): Promise<RefillListResponse> {
return apiClient.get<RefillListResponse>(`/households/${householdId}/refills/lists/${id}`);
}

View file

@ -23,7 +23,9 @@ export async function listRegimens(
if (query?.cursor) params.set('cursor', query.cursor);
if (query?.limit) params.set('limit', String(query.limit));
const qs = params.toString();
return apiClient.get<RegimenListResponse>(`/households/${householdId}/regimens${qs ? `?${qs}` : ''}`);
return apiClient.get<RegimenListResponse>(
`/households/${householdId}/regimens${qs ? `?${qs}` : ''}`,
);
}
export async function getRegimen(householdId: string, id: string): Promise<RegimenResponse> {
@ -34,7 +36,10 @@ export async function getBurnRates(householdId: string): Promise<BurnRateRespons
return apiClient.get<BurnRateResponse>(`/households/${householdId}/regimens/burn-rate`);
}
export async function createRegimen(householdId: string, data: CreateRegimenInput): Promise<RegimenResponse> {
export async function createRegimen(
householdId: string,
data: CreateRegimenInput,
): Promise<RegimenResponse> {
return apiClient.post<RegimenResponse>(`/households/${householdId}/regimens`, data);
}

View file

@ -22,9 +22,7 @@ export async function listStores(
if (query?.cursor) params.set('cursor', query.cursor);
if (query?.limit) params.set('limit', String(query.limit));
const qs = params.toString();
return apiClient.get<StoreListResponse>(
`/households/${householdId}/stores${qs ? `?${qs}` : ''}`,
);
return apiClient.get<StoreListResponse>(`/households/${householdId}/stores${qs ? `?${qs}` : ''}`);
}
export async function getStore(householdId: string, id: string): Promise<StoreResponse> {