Skip to content

Commit

Permalink
fix: organisations.service.spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dainty92 committed Mar 3, 2025
1 parent 26be27f commit 0d72bfc
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions src/modules/organisations/tests/organisations.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,36 @@ describe('OrganisationsService', () => {
const orgId = 'org-id';

// Mock repository functions
organisationRepository.update = jest.fn().mockResolvedValue({ affected: 1 });
organisationRepository.findOneBy = jest.fn().mockResolvedValue({ id: orgId, isDeleted: true });
jest.spyOn(organisationRepository, 'update').mockResolvedValue({
affected: 1,
raw: [],
generatedMaps: [],
});

jest.spyOn(organisationRepository, 'findOneBy').mockResolvedValue({
id: orgId,
name: 'Test Organisation',
description: 'Mock description',
email: '[email protected]',
industry: 'Tech',
phone: '+1234567890',
address: '123 Test Street',
country: 'Nigeria',
isDeleted: true,
createdAt: new Date(),
updatedAt: new Date(),
type: 'Private',
owner: { id: 'owner-id', name: 'Owner Name' },
members: [],
state: 'Active',
city: 'Lagos',
zipCode: '100001',
products: [], // Add empty array for products
preferences: {}, // Add empty object for preferences
invites: [], // Add empty array for invites
created_at: new Date(),
updated_at: new Date(),
} as unknown as Partial<Organisation> as Organisation);

const result = await service.deleteorganisation(orgId);

Expand All @@ -281,18 +309,17 @@ describe('OrganisationsService', () => {
});

it('should exclude deleted organisations from queries', async () => {
const mockOrganisations = [
{ id: 'org1', name: 'Active Org', isDeleted: false },
{ id: 'org2', name: 'Deleted Org', isDeleted: true },
] as Organisation[];
jest.spyOn(organisationRepository, 'findAndCount').mockResolvedValue([[], 0]);

// Mock `findBy` to only return non-deleted organisations
organisationRepository.findBy = jest.fn().mockResolvedValue(mockOrganisations.filter(org => !org.isDeleted));
const result = await service.getUserOrganisations('user-id');

const result = await service.getUserOrganisations('test-user-id');
expect(result).toEqual({ organisations: [], total_count: 0 });

expect(result).toEqual(expect.arrayContaining([{ id: 'org1', name: 'Active Org' }]));
expect(result).not.toEqual(expect.arrayContaining([{ id: 'org2', name: 'Deleted Org' }]));
expect(organisationRepository.findAndCount).toHaveBeenCalledWith({
where: { isDeleted: false },
skip: expect.any(Number),
take: expect.any(Number),
});
});
});
});

0 comments on commit 0d72bfc

Please sign in to comment.