Cleanup after initial plan

This commit is contained in:
Aerilyn Weber 2026-05-19 10:13:40 +09:00
parent d2a7e652b3
commit 245520fb50
53 changed files with 6733 additions and 621 deletions

View file

@ -90,4 +90,59 @@ describe(MealPlanRepository.name, () => {
);
});
});
describe('findById', () => {
it('finds meal plan by id and householdId', async () => {
const mockPlan = { _id: 'mp1', weekStartDate: '2026-05-18' };
vi.mocked(MealPlanModel.findOne).mockReturnValue(makeChain(mockPlan) as never);
const result = await repo.findById('mp1', 'hh1');
expect(MealPlanModel.findOne).toHaveBeenCalledWith({
_id: 'mp1',
householdId: 'hh1',
});
expect(result).toEqual(mockPlan);
});
});
describe('update', () => {
it('updates meal plan using findOneAndUpdate', async () => {
vi.mocked(MealPlanModel.findOneAndUpdate).mockReturnValue(makeChain({ _id: 'mp1' }) as never);
await repo.update('mp1', 'hh1', { status: MealPlanStatus.ACTIVE });
expect(MealPlanModel.findOneAndUpdate).toHaveBeenCalledWith(
{ _id: 'mp1', householdId: 'hh1' },
{ $set: { status: MealPlanStatus.ACTIVE } },
{ new: true, lean: true },
);
});
});
describe('delete', () => {
it('deletes meal plan using findOneAndDelete', async () => {
vi.mocked(MealPlanModel.findOneAndDelete).mockReturnValue(makeChain({ _id: 'mp1' }) as never);
const result = await repo.delete('mp1', 'hh1');
expect(MealPlanModel.findOneAndDelete).toHaveBeenCalledWith({
_id: 'mp1',
householdId: 'hh1',
});
expect(result).toEqual({ _id: 'mp1' });
});
});
describe('findByHousehold pagination cursor', () => {
it('applies pagination filter when cursor is provided', async () => {
const chain = makeChain([]);
vi.mocked(MealPlanModel.find).mockReturnValue(chain as never);
const cursor = Buffer.from('some-mongo-id').toString('base64');
await repo.findByHousehold('hh1', { limit: 20, cursor });
expect(MealPlanModel.find).toHaveBeenCalledWith({
householdId: 'hh1',
_id: { $gt: 'some-mongo-id' }
});
});
});
});