Skip to content

Commit

Permalink
test: inject migration finalisation when call is ongoing
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykBuniX committed Nov 15, 2023
1 parent b7917f7 commit 2ae102c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/script/conversation/ConversationRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,10 @@ describe('ConversationRepository', () => {
});

describe('updateConversationProtocol', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('should update the protocol-related fields after protocol was updated to mixed and inject event', async () => {
const conversation = _generateConversation();
const conversationRepository = await testFactory.exposeConversationActors();
Expand Down Expand Up @@ -2100,6 +2104,7 @@ describe('ConversationRepository', () => {
protocol: newProtocol,
overwites: {cipher_suite: newCipherSuite, epoch: newEpoch},
});

jest
.spyOn(conversationRepository['conversationService'], 'getConversationById')
.mockResolvedValueOnce(mockedConversationResponse);
Expand All @@ -2120,6 +2125,50 @@ describe('ConversationRepository', () => {
expect(updatedConversation.cipherSuite).toEqual(newCipherSuite);
expect(updatedConversation.epoch).toEqual(newEpoch);
});

it('should inject a system message if conversation protocol changed to mls during a call', async () => {
jest.useFakeTimers();
const conversation = _generateConversation();
const selfUser = generateUser();
conversation.selfUser(selfUser);
const conversationRepository = await testFactory.exposeConversationActors();
const newProtocol = ConversationProtocol.MLS;

const mockedProtocolUpdateEventResponse = {
data: {
protocol: newProtocol,
},
qualified_conversation: conversation.qualifiedId,
time: '2020-10-13T14:00:00.000Z',
type: CONVERSATION_EVENT.PROTOCOL_UPDATE,
} as ConversationProtocolUpdateEvent;

jest
.spyOn(conversationRepository['conversationService'], 'updateConversationProtocol')
.mockResolvedValueOnce(mockedProtocolUpdateEventResponse);

const newCipherSuite = 1;
const newEpoch = 2;
const mockedConversationResponse = generateAPIConversation({
protocol: newProtocol,
overwites: {cipher_suite: newCipherSuite, epoch: newEpoch},
});
jest
.spyOn(conversationRepository['conversationService'], 'getConversationById')
.mockResolvedValueOnce(mockedConversationResponse);

const injectEventMock = jest
.spyOn(conversationRepository['eventRepository'], 'injectEvent')
.mockImplementation(jest.fn());
jest.spyOn(conversationRepository['callingRepository'], 'findCall').mockReturnValue({} as any);

await conversationRepository.updateConversationProtocol(conversation, newProtocol);

expect(injectEventMock.mock.calls).toEqual([
[mockedProtocolUpdateEventResponse, EventRepository.SOURCE.BACKEND_RESPONSE],
[expect.objectContaining({type: ClientEvent.CONVERSATION.MLS_MIGRATION_FINALISATION_ONGOING_CALL})],
]);
});
});

describe('addUsers', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/script/conversation/ConversationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3084,11 +3084,12 @@ export class ConversationRepository {

private readonly injectMLSMigrationFinalisationOngoingCallMessage = (conversation: Conversation): void => {
const currentTimestamp = this.serverTimeHandler.toServerTimestamp();
const joinedAfterMLSMigrationFinalisationEvent = EventBuilder.buildMLSMigrationFinalisationOngoingCall(
const mlsMigrationFinalisationOngoingCallEvent = EventBuilder.buildMLSMigrationFinalisationOngoingCall(
conversation,
currentTimestamp,
);
return void this.eventRepository.injectEvent(joinedAfterMLSMigrationFinalisationEvent);

return void this.eventRepository.injectEvent(mlsMigrationFinalisationOngoingCallEvent);
};

/**
Expand Down

0 comments on commit 2ae102c

Please sign in to comment.