diff --git a/app/products/calls/actions/calls.test.ts b/app/products/calls/actions/calls.test.ts index 8d1d20406..4b298cec7 100644 --- a/app/products/calls/actions/calls.test.ts +++ b/app/products/calls/actions/calls.test.ts @@ -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')); diff --git a/app/products/calls/actions/calls.ts b/app/products/calls/actions/calls.ts index fb3dfc336..214a835f4 100644 --- a/app/products/calls/actions/calls.ts +++ b/app/products/calls/actions/calls.ts @@ -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};