fix(api): update unit tests

This commit is contained in:
yassinedorbozgithub 2025-05-23 15:58:05 +01:00
parent 3ff2b97221
commit e0ff78ac71
2 changed files with 11 additions and 2 deletions

View File

@ -138,6 +138,7 @@ describe('PermissionRepository', () => {
expect(permissionModel.deleteOne).toHaveBeenCalledWith({ expect(permissionModel.deleteOne).toHaveBeenCalledWith({
_id: permissionToDelete.id, _id: permissionToDelete.id,
builtin: { $ne: true },
}); });
expect(result).toEqual({ expect(result).toEqual({

View File

@ -306,6 +306,7 @@ describe('BaseRepository', () => {
expect(dummyModel.deleteOne).toHaveBeenCalledWith({ expect(dummyModel.deleteOne).toHaveBeenCalledWith({
_id: createdId, _id: createdId,
builtin: { $ne: true },
}); });
expect(result).toEqualPayload({ acknowledged: true, deletedCount: 1 }); expect(result).toEqualPayload({ acknowledged: true, deletedCount: 1 });
}); });
@ -318,12 +319,13 @@ describe('BaseRepository', () => {
expect(dummyModel.deleteOne).toHaveBeenCalledWith({ expect(dummyModel.deleteOne).toHaveBeenCalledWith({
dummy: 'dummy test 2', dummy: 'dummy test 2',
builtin: { $ne: true },
}); });
expect(result).toEqualPayload({ acknowledged: true, deletedCount: 1 }); expect(result).toEqualPayload({ acknowledged: true, deletedCount: 1 });
}); });
it('should call lifecycle hooks appropriately when deleting by id', async () => { it('should call lifecycle hooks appropriately when deleting by id', async () => {
const criteria = createdId; jest.spyOn(dummyModel, 'deleteOne');
// Spies for lifecycle hooks // Spies for lifecycle hooks
const spyBeforeDelete = jest const spyBeforeDelete = jest
@ -333,7 +335,12 @@ describe('BaseRepository', () => {
.spyOn(dummyRepository, 'postDelete') .spyOn(dummyRepository, 'postDelete')
.mockResolvedValue(); .mockResolvedValue();
await dummyRepository.deleteOne(criteria); await dummyRepository.deleteOne(createdId);
expect(dummyModel.deleteOne).toHaveBeenCalledWith({
_id: createdId,
builtin: { $ne: true },
});
// Verifying that lifecycle hooks are called with correct parameters // Verifying that lifecycle hooks are called with correct parameters
expect(spyBeforeDelete).toHaveBeenCalledTimes(1); expect(spyBeforeDelete).toHaveBeenCalledTimes(1);
@ -341,6 +348,7 @@ describe('BaseRepository', () => {
expect.objectContaining({ $useProjection: true }), expect.objectContaining({ $useProjection: true }),
{ {
_id: new Types.ObjectId(createdId), _id: new Types.ObjectId(createdId),
builtin: { $ne: true },
}, },
); );
expect(spyAfterDelete).toHaveBeenCalledWith( expect(spyAfterDelete).toHaveBeenCalledWith(