Skip to content

Commit

Permalink
fix bug (#2413)
Browse files Browse the repository at this point in the history
  • Loading branch information
ratik21 authored Nov 8, 2024
1 parent 747d4e4 commit e538503
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/store/users/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ describe(fetchCurrentUserProfileImage, () => {
const initialState = new StoreBuilder().withCurrentUser(currentUser).withRegistration({ isFirstTimeLogin: true });

await expectSaga(fetchCurrentUserProfileImage)
.provide([[call(updateUserProfileImageFromCache, expect.anything()), '']])
.provide([
[call(updateUserProfileImageFromCache, expect.anything()), ''],
[
spawn(matrixEditProfile, { displayName: 'Alice' }),
undefined,
],
])
.withReducer(rootReducer, initialState.build())
.call(updateUserProfileImageFromCache, currentUser)
.run();
Expand Down Expand Up @@ -180,7 +186,7 @@ describe(fetchCurrentUserProfileImage, () => {
});

describe(updateUserProfileImageFromCache, () => {
it('returns undefined if no profile image is found', async () => {
it('updates only displayname & returns undefined if no profile image is found', async () => {
const currentUser: any = {
id: 'user-id-1',
profileSummary: { firstName: 'Alice' },
Expand All @@ -189,7 +195,15 @@ describe(updateUserProfileImageFromCache, () => {

mockIdb.put('profileImage', undefined);

const { returnValue } = await expectSaga(updateUserProfileImageFromCache, currentUser).run();
const { returnValue } = await expectSaga(updateUserProfileImageFromCache, currentUser)
.provide([
[
spawn(matrixEditProfile, { displayName: 'Alice' }),
undefined,
],
])
.spawn(matrixEditProfile, { displayName: 'Alice' })
.run();

expect(returnValue).toBeUndefined();
});
Expand Down
3 changes: 3 additions & 0 deletions src/store/users/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export function* updateUserProfileImageFromCache(currentUser: User) {
} else {
console.error('Failed to update user profile on registration:', response.error);
}
} else {
// only update the displayname if the user hasn't uploaded a profile image during registration
yield spawn(matrixEditProfile, { displayName: name });
}

return undefined;
Expand Down

0 comments on commit e538503

Please sign in to comment.