Skip to content

Commit

Permalink
Merge pull request #504 from chaynHQ/develop
Browse files Browse the repository at this point in the history
Merge Develop onto Main
  • Loading branch information
eleanorreem authored Jul 3, 2024
2 parents 33c0f5d + 86ef218 commit 05cc216
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ describe('UserService', () => {
);
});

it('when supplied a firebase user dto with an email that already exists, it should return an error', async () => {
const repoSaveSpy = jest.spyOn(repo, 'save');
const authServiceUpdateEmailSpy = jest
.spyOn(mockAuthService, 'updateFirebaseUserEmail')
.mockImplementationOnce(async () => {
throw new Error('Email already exists');
});

await expect(service.updateUser(updateUserDto, mockUserEntity.id)).rejects.toThrow(
'Email already exists',
);
});

it('should not fail update on crisp api call errors', async () => {
const mocked = jest.mocked(updateCrispProfile);
mocked.mockRejectedValue(new Error('Crisp API call failed'));
Expand All @@ -305,7 +318,6 @@ describe('UserService', () => {
expect(mocked).toHaveBeenCalled();
expect(user.name).toBe(updateUserDto.name);
expect(user.email).toBe(updateUserDto.email);

mocked.mockReset();
});

Expand Down
7 changes: 6 additions & 1 deletion src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SubscriptionUserService } from 'src/subscription-user/subscription-user
import { TherapySessionService } from 'src/therapy-session/therapy-session.service';
import { SIGNUP_TYPE } from 'src/utils/constants';
import { FIREBASE_ERRORS } from 'src/utils/errors';
import { FIREBASE_EVENTS } from 'src/utils/logs';
import { FIREBASE_EVENTS, USER_SERVICE_EVENTS } from 'src/utils/logs';
import {
createServiceUserProfiles,
updateServiceUserProfilesUser,
Expand Down Expand Up @@ -218,6 +218,11 @@ export class UserService {
...updateUserDto,
};
const updatedUser = await this.userRepository.save(newUserData);
this.logger.log({
event: USER_SERVICE_EVENTS.USER_UPDATED,
userId: user.id,
fields: Object.keys(updateUserDto),
});

const isCrispBaseUpdateRequired =
user.signUpLanguage !== updateUserDto.signUpLanguage && user.name !== updateUserDto.name;
Expand Down
4 changes: 4 additions & 0 deletions src/utils/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ export enum FIREBASE_EVENTS {
UPDATE_FIREBASE_USER_EMAIL = 'UPDATE_FIREBASE_USER_EMAIL',
UPDATE_FIREBASE_EMAIL_ALREADY_UPDATED = 'UPDATE_FIREBASE_EMAIL_ALREADY_UPDATED',
}

export enum USER_SERVICE_EVENTS {
USER_UPDATED = 'USER_UPDATED',
}

0 comments on commit 05cc216

Please sign in to comment.