Implement medicine library and cabinet
This commit is contained in:
parent
db79af06f7
commit
1f66fab30f
72 changed files with 7642 additions and 319 deletions
|
|
@ -93,6 +93,15 @@ describe('HouseholdsService', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('aborts transaction on error', async () => {
|
||||
mockHouseholdsRepo.create.mockRejectedValue(new Error('DB error'));
|
||||
|
||||
await expect(service.create({ name: 'Test' }, 'kc-1')).rejects.toThrow('DB error');
|
||||
|
||||
expect(mockSession.abortTransaction).toHaveBeenCalled();
|
||||
expect(mockSession.endSession).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles case when owner user not found in db', async () => {
|
||||
const household = { _id: 'hh1', name: 'Test', ownerUserId: 'kc-1' };
|
||||
mockHouseholdsRepo.create.mockResolvedValue(household);
|
||||
|
|
@ -153,6 +162,16 @@ describe('HouseholdsService', () => {
|
|||
await expect(service.update('hh1', { name: 'X' }, 'kc-3')).rejects.toThrow(ForbiddenError);
|
||||
});
|
||||
|
||||
it('throws NotFoundError when repo update returns null', async () => {
|
||||
mockHouseholdsRepo.findById.mockResolvedValue({
|
||||
_id: 'hh1',
|
||||
members: [{ userId: 'kc-1', role: HouseholdRole.OWNER }],
|
||||
});
|
||||
mockHouseholdsRepo.update.mockResolvedValue(null);
|
||||
|
||||
await expect(service.update('hh1', { name: 'X' }, 'kc-1')).rejects.toThrow(NotFoundError);
|
||||
});
|
||||
|
||||
it('throws ForbiddenError for non-member', async () => {
|
||||
mockHouseholdsRepo.findById.mockResolvedValue({
|
||||
_id: 'hh1',
|
||||
|
|
@ -186,6 +205,16 @@ describe('HouseholdsService', () => {
|
|||
|
||||
await expect(service.generateInviteCode('hh1', 'kc-3')).rejects.toThrow(ForbiddenError);
|
||||
});
|
||||
|
||||
it('throws NotFoundError when updateInviteCode returns null', async () => {
|
||||
mockHouseholdsRepo.findById.mockResolvedValue({
|
||||
_id: 'hh1',
|
||||
members: [{ userId: 'kc-1', role: HouseholdRole.OWNER }],
|
||||
});
|
||||
mockHouseholdsRepo.updateInviteCode.mockResolvedValue(null);
|
||||
|
||||
await expect(service.generateInviteCode('hh1', 'kc-1')).rejects.toThrow(NotFoundError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('join', () => {
|
||||
|
|
@ -236,6 +265,31 @@ describe('HouseholdsService', () => {
|
|||
await expect(service.join('CODE', 'kc-1')).rejects.toThrow(ConflictError);
|
||||
});
|
||||
|
||||
it('throws NotFoundError when addMember returns null', async () => {
|
||||
const household = {
|
||||
_id: 'hh1',
|
||||
members: [{ userId: 'kc-1', role: HouseholdRole.OWNER }],
|
||||
};
|
||||
mockHouseholdsRepo.findByInviteCode.mockResolvedValue(household);
|
||||
mockHouseholdsRepo.addMember.mockResolvedValue(null);
|
||||
|
||||
await expect(service.join('CODE', 'kc-2')).rejects.toThrow(NotFoundError);
|
||||
});
|
||||
|
||||
it('aborts transaction on error during join', async () => {
|
||||
const household = {
|
||||
_id: 'hh1',
|
||||
members: [{ userId: 'kc-1', role: HouseholdRole.OWNER }],
|
||||
};
|
||||
mockHouseholdsRepo.findByInviteCode.mockResolvedValue(household);
|
||||
mockHouseholdsRepo.addMember.mockRejectedValue(new Error('DB error'));
|
||||
|
||||
await expect(service.join('CODE', 'kc-2')).rejects.toThrow('DB error');
|
||||
|
||||
expect(mockSession.abortTransaction).toHaveBeenCalled();
|
||||
expect(mockSession.endSession).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles case when joining user not found in db', async () => {
|
||||
const household = {
|
||||
_id: 'hh1',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue