Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added unittests for getUserProfile
  • Loading branch information
leoseg committed Nov 19, 2024
1 parent a61cec5 commit 93cac89
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,75 @@ describe('UserService', () => {
});
});

describe('getUserProfile', () => {
it('should return user entity and user DTO when user is found', async () => {
const mockUserEntity = new UserEntity();
mockUserEntity.id = 'userId1';
mockUserEntity.email = '[email protected]';
mockUserEntity.name = 'name';
mockUserEntity.createdAt = new Date('2024-11-19T19:18:51.796Z');
mockUserEntity.updatedAt = new Date('2024-11-19T19:18:51.796Z');
mockUserEntity.lastActiveAt = new Date('2024-11-19T19:18:51.796Z');
mockUserEntity.isActive = true;
mockUserEntity.isSuperAdmin = false;
mockUserEntity.signUpLanguage = 'en';
mockUserEntity.emailRemindersFrequency = EMAIL_REMINDERS_FREQUENCY.TWO_MONTHS;
mockUserEntity.firebaseUid = '123';
mockUserEntity.crispTokenId = '123';
mockUserEntity.serviceEmailsPermission = true;
mockUserEntity.contactPermission = true;
mockUserEntity.deletedAt = null;
mockUserEntity.courseUser = [];
mockUserEntity.partnerAccess = [];
mockUserEntity.partnerAdmin = null;
mockUserEntity.subscriptionUser = [];
mockUserEntity.therapySession = [];
mockUserEntity.eventLog = [];

const mockUserDto = {
user: {
id: 'userId1',
email: '[email protected]',
name: 'name',
createdAt: new Date('2024-11-19T19:18:51.796Z'),
updatedAt: new Date('2024-11-19T19:18:51.796Z'),
lastActiveAt: new Date('2024-11-19T19:18:51.796Z'),
isActive: true,
isSuperAdmin: false,
signUpLanguage: 'en',
emailRemindersFrequency: 'TWO_MONTHS',
firebaseUid: '123',
crispTokenId: '123',
deletedAt: null,
},
partnerAccesses: [],
partnerAdmin: null,
courses: [],
};

jest.spyOn(repo, 'createQueryBuilder').mockReturnValue({
leftJoinAndSelect: jest.fn().mockReturnThis(),
where: jest.fn().mockReturnThis(),
getOne: jest.fn().mockResolvedValue(mockUserEntity),
} as any);

const result = await service.getUserProfile('userId1');
expect(result).toEqual({ userEntity: mockUserEntity, userDto: mockUserDto });
});

it('should throw HttpException when user is not found', async () => {
jest.spyOn(repo, 'createQueryBuilder').mockReturnValue({
leftJoinAndSelect: jest.fn().mockReturnThis(),
where: jest.fn().mockReturnThis(),
getOne: jest.fn().mockResolvedValue(undefined),
} as any);

await expect(service.getUserProfile('userId1')).rejects.toThrow(
new HttpException('USER NOT FOUND', HttpStatus.NOT_FOUND),
);
});
});

// TODO - Extend getUser tests. At the moment, this is only used by super admins
describe('getUsers', () => {
it('getUsers', async () => {
Expand Down

0 comments on commit 93cac89

Please sign in to comment.