MM-48447 - Calls: guard against possible bad response from server (null) (#6769)
* guard against possible bad response from server (null) * lock it down with a test
This commit is contained in:
parent
e4bff927c3
commit
ac75a07d4b
2 changed files with 31 additions and 1 deletions
|
|
@ -268,6 +268,36 @@ describe('Actions.Calls', () => {
|
|||
assert.equal((result.current[2] as CurrentCall | null), null);
|
||||
});
|
||||
|
||||
it('loadCalls fails from server', async () => {
|
||||
const expectedCallsState: CallsState = {
|
||||
serverUrl: 'server1',
|
||||
myUserId: 'userId1',
|
||||
calls: {},
|
||||
enabled: {},
|
||||
};
|
||||
|
||||
// setup
|
||||
const oldGetCalls = mockClient.getCalls;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
mockClient.getCalls = jest.fn(() => null);
|
||||
|
||||
const {result} = renderHook(() => {
|
||||
return [useCallsState('server1'), useChannelsWithCalls('server1'), useCurrentCall()];
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await CallsActions.loadCalls('server1', 'userId1');
|
||||
});
|
||||
expect(mockClient.getCalls).toBeCalled();
|
||||
assert.deepEqual((result.current[0] as CallsState), expectedCallsState);
|
||||
assert.deepEqual((result.current[1] as ChannelsWithCalls), {});
|
||||
assert.equal((result.current[2] as CurrentCall | null), null);
|
||||
|
||||
mockClient.getCalls = oldGetCalls;
|
||||
});
|
||||
|
||||
it('loadConfig', async () => {
|
||||
// setup
|
||||
const {result} = renderHook(() => useCallsConfig('server1'));
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export const loadCalls = async (serverUrl: string, userId: string) => {
|
|||
}
|
||||
let resp: ServerChannelState[] = [];
|
||||
try {
|
||||
resp = await client.getCalls();
|
||||
resp = await client.getCalls() || [];
|
||||
} catch (error) {
|
||||
await forceLogoutIfNecessary(serverUrl, error as ClientError);
|
||||
return {error};
|
||||
|
|
|
|||
Loading…
Reference in a new issue