diff --git a/src/modules/organisations/tests/organisations.service.spec.ts b/src/modules/organisations/tests/organisations.service.spec.ts index 01c53c2d..f4bf6e9f 100644 --- a/src/modules/organisations/tests/organisations.service.spec.ts +++ b/src/modules/organisations/tests/organisations.service.spec.ts @@ -267,18 +267,20 @@ describe('OrganisationsService', () => { const orgId = 'org-id'; const mockOrganisation = { id: orgId, isDeleted: false } as Organisation; - jest.spyOn(organisationRepository, 'findOne').mockResolvedValue(mockOrganisation); + jest + .spyOn(organisationRepository, 'findOne') + .mockResolvedValueOnce(mockOrganisation) // Before deletion + .mockResolvedValueOnce({ ...mockOrganisation, isDeleted: true }); // After deletion + jest.spyOn(organisationRepository, 'update').mockResolvedValue({ affected: 1 } as any); const result = await service.deleteorganisation(orgId); - expect(result).toEqual({ - message: 'Organisation deleted successfully', - }); + expect(result).toEqual({ message: 'Organisation deleted successfully' }); expect(organisationRepository.update).toHaveBeenCalledWith({ id: orgId }, { isDeleted: true }); // Check if the entity was marked as deleted - const updatedOrg = await organisationRepository.findOne({ where: { id: orgId } }); + const updatedOrg = await organisationRepository.findOne({ where: { id: orgId }, withDeleted: true }); expect(updatedOrg?.isDeleted).toBe(true); }); @@ -288,7 +290,7 @@ describe('OrganisationsService', () => { { id: 'org2', name: 'Deleted Org', isDeleted: true }, ] as Organisation[]; - jest.spyOn(organisationRepository, 'find').mockResolvedValue(mockOrganisations); + jest.spyOn(organisationRepository, 'find').mockResolvedValue(mockOrganisations.filter(org => !org.isDeleted)); const result = await service.getUserOrganisations('test-user-id');