|
2 | 2 | /* eslint-disable global-require */ |
3 | 3 | import { SDK_ACTIONS } from '../../../dux/sdk/actionTypes'; |
4 | 4 | import { USER_ACTIONS } from '../../../dux/user/actionTypes'; |
5 | | -import { getConnectSbError, getMissingParamError, setUpConnection, setUpParams } from '../setupConnection'; |
| 5 | +import { getMissingParamError, setUpConnection, setUpParams } from '../setupConnection'; |
6 | 6 | import { SetupConnectionTypes } from '../types'; |
7 | 7 | import { generateSetUpConnectionParams, mockSdk, mockUser, mockUser2 } from './data.mocks'; |
8 | 8 |
|
@@ -44,6 +44,48 @@ describe('useConnect/setupConnection', () => { |
44 | 44 | expect(setUpConnectionProps.sdkDispatcher).toBeCalledWith({ type: SDK_ACTIONS.SDK_ERROR }); |
45 | 45 | }); |
46 | 46 |
|
| 47 | + it('should replace nickname with userId when isUserIdUsedForNickname is true', async () => { |
| 48 | + const newUser = { |
| 49 | + userId: 'new-userid', |
| 50 | + nickname: '', |
| 51 | + profileUrl: 'new-user-profile-url', |
| 52 | + }; |
| 53 | + const setUpConnectionProps = generateSetUpConnectionParams(); |
| 54 | + await setUpConnection({ |
| 55 | + ...setUpConnectionProps, |
| 56 | + ...newUser, |
| 57 | + isUserIdUsedForNickname: true, |
| 58 | + }); |
| 59 | + |
| 60 | + const updatedUser = { nickname: newUser.userId, profileUrl: newUser.profileUrl }; |
| 61 | + expect(mockSdk.updateCurrentUserInfo).toHaveBeenCalledWith(updatedUser); |
| 62 | + expect(setUpConnectionProps.userDispatcher).toHaveBeenCalledWith({ |
| 63 | + type: USER_ACTIONS.UPDATE_USER_INFO, |
| 64 | + payload: updatedUser, |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should not replace nickname with userId when isUserIdUsedForNickname is false', async () => { |
| 69 | + const newUser = { |
| 70 | + userId: 'new-userid', |
| 71 | + nickname: '', |
| 72 | + profileUrl: 'new-user-profile-url', |
| 73 | + }; |
| 74 | + const setUpConnectionProps = generateSetUpConnectionParams(); |
| 75 | + await setUpConnection({ |
| 76 | + ...setUpConnectionProps, |
| 77 | + ...newUser, |
| 78 | + isUserIdUsedForNickname: false, |
| 79 | + }); |
| 80 | + |
| 81 | + const updatedUser = { nickname: '', profileUrl: newUser.profileUrl }; |
| 82 | + expect(mockSdk.updateCurrentUserInfo).toHaveBeenCalledWith(updatedUser); |
| 83 | + expect(setUpConnectionProps.userDispatcher).toHaveBeenCalledWith({ |
| 84 | + type: USER_ACTIONS.UPDATE_USER_INFO, |
| 85 | + payload: updatedUser, |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
47 | 89 | it('should call setUpConnection when there is proper SDK', async () => { |
48 | 90 | const setUpConnectionProps = generateSetUpConnectionParams(); |
49 | 91 | await setUpConnection(setUpConnectionProps); |
@@ -107,8 +149,11 @@ describe('useConnect/setupConnection', () => { |
107 | 149 |
|
108 | 150 | it('should call connectCbError if connection fails', async () => { |
109 | 151 | const setUpConnectionProps = generateSetUpConnectionParams(); |
110 | | - setUpConnectionProps.userId = 'unknown'; |
111 | | - const errorMessage = getConnectSbError(); |
| 152 | + setUpConnectionProps.userId = ''; |
| 153 | + const errorMessage = getMissingParamError({ |
| 154 | + userId: '', |
| 155 | + appId: setUpConnectionProps.appId, |
| 156 | + }); |
112 | 157 |
|
113 | 158 | await expect(setUpConnection(setUpConnectionProps)) |
114 | 159 | .rejects.toMatch(errorMessage); |
|
0 commit comments