Implement medicine library and cabinet

This commit is contained in:
Aerilyn Weber 2026-03-28 08:19:48 +09:00
parent db79af06f7
commit 1f66fab30f
72 changed files with 7642 additions and 319 deletions

View file

@ -56,6 +56,7 @@ vi.mock('../users/users.repository.js', () => ({
UsersRepository: class {
findByKeycloakId = mockFindByKeycloakId;
update = mockUserUpdate;
upsertFromToken = vi.fn().mockResolvedValue({ householdIds: ['hh1'] });
},
}));
@ -117,6 +118,8 @@ describe('households.routes', () => {
beforeEach(async () => {
vi.clearAllMocks();
// Default: auth plugin finds user with hh1 membership (routes with householdId guard pass)
mockFindByKeycloakId.mockResolvedValue({ householdIds: ['hh1'], defaultHouseholdId: null });
app = await buildTestApp();
});
@ -143,6 +146,43 @@ describe('households.routes', () => {
});
});
describe('POST /api/v1/households (ObjectId/Date conversion)', () => {
it('handles ObjectId and Date objects in response', async () => {
const household = makeFakeHousehold({
_id: { toString: () => 'hh-obj' },
createdAt: { toISOString: () => '2024-01-01T00:00:00.000Z' },
updatedAt: { toISOString: () => '2024-01-02T00:00:00.000Z' },
members: [
{
userId: 'kc-1',
role: HouseholdRole.OWNER,
joinedAt: { toISOString: () => '2024-01-01T00:00:00.000Z' },
},
],
settings: null,
});
mockCreate.mockResolvedValue(household);
mockFindByKeycloakId.mockResolvedValue({ householdIds: [], defaultHouseholdId: null });
mockUserUpdate.mockResolvedValue({});
const res = await app.inject({
method: 'POST',
url: '/api/v1/households',
headers: authHeaders,
payload: { name: 'Test' },
});
expect(res.statusCode).toBe(201);
const body = res.json();
expect(body._id).toBe('hh-obj');
expect(body.createdAt).toBe('2024-01-01T00:00:00.000Z');
expect(body.members[0].joinedAt).toBe('2024-01-01T00:00:00.000Z');
expect(body.settings.timezone).toBe('UTC');
expect(body.settings.currency).toBe('USD');
expect(body.settings.language).toBe('en');
});
});
describe('GET /api/v1/households/:id', () => {
it('returns a household', async () => {
const household = makeFakeHousehold();