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 db6c15f commit 14b6632
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/modules/organisations/tests/organisations.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,8 @@ describe('OrganisationsService', () => {
const orgId = 'org-id';
const mockOrganisation = { id: orgId, isDeleted: false } as Organisation;

jest
.spyOn(organisationRepository, 'findOne')
.mockResolvedValueOnce(mockOrganisation) // Before deletion
.mockResolvedValueOnce({ ...mockOrganisation, isDeleted: true }); // After deletion

// Ensure `findOneBy` is mocked correctly
jest.spyOn(organisationRepository, 'findOneBy').mockResolvedValue(mockOrganisation);
jest.spyOn(organisationRepository, 'update').mockResolvedValue({ affected: 1 } as any);

const result = await service.deleteorganisation(orgId);
Expand All @@ -280,7 +277,7 @@ describe('OrganisationsService', () => {
expect(organisationRepository.update).toHaveBeenCalledWith({ id: orgId }, { isDeleted: true });

// Check if the entity was marked as deleted
const updatedOrg = await organisationRepository.findOne({ where: { id: orgId }, withDeleted: true });
const updatedOrg = await organisationRepository.findOneBy({ id: orgId });
expect(updatedOrg?.isDeleted).toBe(true);
});

Expand All @@ -290,7 +287,8 @@ describe('OrganisationsService', () => {
{ id: 'org2', name: 'Deleted Org', isDeleted: true },
] as Organisation[];

jest.spyOn(organisationRepository, 'find').mockResolvedValue(mockOrganisations.filter(org => !org.isDeleted));
// Ensure `findBy` is mocked instead of `find`
jest.spyOn(organisationRepository, 'findBy').mockResolvedValue(mockOrganisations.filter(org => !org.isDeleted));

const result = await service.getUserOrganisations('test-user-id');

Expand Down

0 comments on commit 14b6632

Please sign in to comment.