Skip to content

Commit

Permalink
feat: add test coverage for updateUserPresence
Browse files Browse the repository at this point in the history
  • Loading branch information
domw30 committed Oct 17, 2023
1 parent 04488f9 commit 30cd94e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/store/channels-list/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
otherUserJoinedChannel,
otherUserLeftChannel,
mapToZeroUsers,
updateUserPresence,
} from './saga';

import { SagaActionTypes, setStatus } from '.';
Expand Down Expand Up @@ -56,6 +57,7 @@ const MOCK_CONVERSATIONS = [mockConversation('0001'), mockConversation('0002')];
const chatClient = {
getChannels: () => MOCK_CHANNELS,
getConversations: () => MOCK_CONVERSATIONS,
getUserPresence: () => {},
};

describe('channels list saga', () => {
Expand Down Expand Up @@ -625,4 +627,48 @@ describe('channels list saga', () => {
});
});
});

describe(updateUserPresence, () => {
function subject(conversations, provide = []) {
return expectSaga(updateUserPresence, conversations).provide([
[matchers.call.fn(chat.get), chatClient],
...provide,
]);
}

const mockOtherMembers = [{ matrixId: 'member_001' }, { matrixId: 'member_002' }, { matrixId: 'member_003' }];
const mockConversations = [{ otherMembers: mockOtherMembers }];

it('exits early if feature flag is not enabled', async () => {
featureFlags.enableMatrix = false;
await subject(mockConversations).not.call(chat.get).run();
});

it('fetches and updates user presence data', async () => {
featureFlags.enableMatrix = true;

const mockPresenceData = {
lastSeenAt: '2023-01-01T00:00:00.000Z',
isOnline: true,
};

await subject(mockConversations, [
[matchers.call([chatClient, chatClient.getUserPresence], 'member_001'), mockPresenceData],
[matchers.call([chatClient, chatClient.getUserPresence], 'member_002'), mockPresenceData],
[matchers.call([chatClient, chatClient.getUserPresence], 'member_003'), mockPresenceData],
])
.call(chat.get)
.call([chatClient, chatClient.getUserPresence], 'member_001')
.call([chatClient, chatClient.getUserPresence], 'member_002')
.call([chatClient, chatClient.getUserPresence], 'member_003')
.run();
});

it('does not fail if member does not have matrixId', async () => {
featureFlags.enableMatrix = true;
const conversationsWithMissingMatrixId = [{ otherMembers: [{ matrixId: null }] }];

await subject(conversationsWithMissingMatrixId).call(chat.get).not.call(chatClient.getUserPresence).run();
});
});
});

0 comments on commit 30cd94e

Please sign in to comment.