File tree 3 files changed +23
-2
lines changed
3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -296,6 +296,19 @@ describe('UserService', () => {
296
296
) ;
297
297
} ) ;
298
298
299
+ it ( 'when supplied a firebase user dto with an email that already exists, it should return an error' , async ( ) => {
300
+ const repoSaveSpy = jest . spyOn ( repo , 'save' ) ;
301
+ const authServiceUpdateEmailSpy = jest
302
+ . spyOn ( mockAuthService , 'updateFirebaseUserEmail' )
303
+ . mockImplementationOnce ( async ( ) => {
304
+ throw new Error ( 'Email already exists' ) ;
305
+ } ) ;
306
+
307
+ await expect ( service . updateUser ( updateUserDto , mockUserEntity . id ) ) . rejects . toThrow (
308
+ 'Email already exists' ,
309
+ ) ;
310
+ } ) ;
311
+
299
312
it ( 'should not fail update on crisp api call errors' , async ( ) => {
300
313
const mocked = jest . mocked ( updateCrispProfile ) ;
301
314
mocked . mockRejectedValue ( new Error ( 'Crisp API call failed' ) ) ;
@@ -305,7 +318,6 @@ describe('UserService', () => {
305
318
expect ( mocked ) . toHaveBeenCalled ( ) ;
306
319
expect ( user . name ) . toBe ( updateUserDto . name ) ;
307
320
expect ( user . email ) . toBe ( updateUserDto . email ) ;
308
-
309
321
mocked . mockReset ( ) ;
310
322
} ) ;
311
323
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import { SubscriptionUserService } from 'src/subscription-user/subscription-user
10
10
import { TherapySessionService } from 'src/therapy-session/therapy-session.service' ;
11
11
import { SIGNUP_TYPE } from 'src/utils/constants' ;
12
12
import { FIREBASE_ERRORS } from 'src/utils/errors' ;
13
- import { FIREBASE_EVENTS } from 'src/utils/logs' ;
13
+ import { FIREBASE_EVENTS , USER_SERVICE_EVENTS } from 'src/utils/logs' ;
14
14
import {
15
15
createServiceUserProfiles ,
16
16
updateServiceUserProfilesUser ,
@@ -218,6 +218,11 @@ export class UserService {
218
218
...updateUserDto ,
219
219
} ;
220
220
const updatedUser = await this . userRepository . save ( newUserData ) ;
221
+ this . logger . log ( {
222
+ event : USER_SERVICE_EVENTS . USER_UPDATED ,
223
+ userId : user . id ,
224
+ fields : Object . keys ( updateUserDto ) ,
225
+ } ) ;
221
226
222
227
const isCrispBaseUpdateRequired =
223
228
user . signUpLanguage !== updateUserDto . signUpLanguage && user . name !== updateUserDto . name ;
Original file line number Diff line number Diff line change @@ -2,3 +2,7 @@ export enum FIREBASE_EVENTS {
2
2
UPDATE_FIREBASE_USER_EMAIL = 'UPDATE_FIREBASE_USER_EMAIL' ,
3
3
UPDATE_FIREBASE_EMAIL_ALREADY_UPDATED = 'UPDATE_FIREBASE_EMAIL_ALREADY_UPDATED' ,
4
4
}
5
+
6
+ export enum USER_SERVICE_EVENTS {
7
+ USER_UPDATED = 'USER_UPDATED' ,
8
+ }
You can’t perform that action at this time.
0 commit comments