From db6c15fe1e885230790015c9455ac39e698ab184 Mon Sep 17 00:00:00 2001 From: dainty92 Date: Mon, 3 Mar 2025 00:20:05 +0100 Subject: [PATCH] fix: organisations.service.spec.ts --- .../tests/organisations.service.spec.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/modules/organisations/tests/organisations.service.spec.ts b/src/modules/organisations/tests/organisations.service.spec.ts index 01c53c2df..f4bf6e9f2 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');