Skip to content

Commit

Permalink
fix: organisations.service.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
dainty92 committed Mar 2, 2025
1 parent c7143d8 commit db6c15f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/modules/organisations/tests/organisations.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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');

Expand Down

0 comments on commit db6c15f

Please sign in to comment.