2020-12-07 20:43:19 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
2023-08-09 00:53:06 +00:00
|
|
|
import {
|
|
|
|
CallExternalState,
|
|
|
|
getCallingNotificationText,
|
|
|
|
} from '../../util/callingNotification';
|
2020-12-07 20:43:19 +00:00
|
|
|
import { CallMode } from '../../types/Calling';
|
2021-09-18 00:30:08 +00:00
|
|
|
import { setupI18n } from '../../util/setupI18n';
|
2020-12-07 20:43:19 +00:00
|
|
|
import enMessages from '../../../_locales/en/messages.json';
|
2023-08-09 00:53:06 +00:00
|
|
|
import {
|
|
|
|
getDefaultConversation,
|
|
|
|
getDefaultGroup,
|
|
|
|
} from '../helpers/getDefaultConversation';
|
|
|
|
import {
|
|
|
|
CallDirection,
|
|
|
|
CallType,
|
|
|
|
GroupCallStatus,
|
|
|
|
} from '../../types/CallDisposition';
|
|
|
|
import { getPeerIdFromConversation } from '../../util/callDisposition';
|
2020-12-07 20:43:19 +00:00
|
|
|
|
|
|
|
describe('calling notification helpers', () => {
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
describe('getCallingNotificationText', () => {
|
|
|
|
// Direct call behavior is not tested here.
|
|
|
|
|
|
|
|
it('says that the call has ended', () => {
|
2023-08-09 00:53:06 +00:00
|
|
|
const callCreator = getDefaultConversation();
|
2020-12-07 20:43:19 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
getCallingNotificationText(
|
|
|
|
{
|
2023-08-09 00:53:06 +00:00
|
|
|
callHistory: {
|
|
|
|
callId: '123',
|
|
|
|
peerId: getPeerIdFromConversation(getDefaultGroup()),
|
|
|
|
ringerId: callCreator.uuid ?? null,
|
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
status: GroupCallStatus.Missed,
|
|
|
|
},
|
|
|
|
callCreator,
|
|
|
|
callExternalState: CallExternalState.Ended,
|
2020-12-07 20:43:19 +00:00
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
|
|
|
'The group call has ended'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("includes the creator's first name when describing a call", () => {
|
2023-08-09 00:53:06 +00:00
|
|
|
const callCreator = getDefaultConversation({
|
2023-01-12 23:29:07 +00:00
|
|
|
systemGivenName: 'Luigi',
|
|
|
|
});
|
2020-12-07 20:43:19 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
getCallingNotificationText(
|
|
|
|
{
|
2023-08-09 00:53:06 +00:00
|
|
|
callHistory: {
|
|
|
|
callId: '123',
|
|
|
|
peerId: getPeerIdFromConversation(getDefaultGroup()),
|
|
|
|
ringerId: callCreator.uuid ?? null,
|
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
status: GroupCallStatus.Ringing,
|
|
|
|
},
|
|
|
|
callCreator,
|
|
|
|
callExternalState: CallExternalState.Active,
|
2020-12-07 20:43:19 +00:00
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
|
|
|
'Luigi started a group call'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("if the creator doesn't have a first name, falls back to their title", () => {
|
2023-08-09 00:53:06 +00:00
|
|
|
const callCreator = getDefaultConversation({
|
2023-01-12 23:29:07 +00:00
|
|
|
systemGivenName: undefined,
|
|
|
|
title: 'Luigi Mario',
|
|
|
|
});
|
2020-12-07 20:43:19 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
getCallingNotificationText(
|
|
|
|
{
|
2023-08-09 00:53:06 +00:00
|
|
|
callHistory: {
|
|
|
|
callId: '123',
|
|
|
|
peerId: getPeerIdFromConversation(getDefaultGroup()),
|
|
|
|
ringerId: callCreator.uuid ?? null,
|
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
status: GroupCallStatus.Ringing,
|
|
|
|
},
|
|
|
|
callCreator,
|
|
|
|
callExternalState: CallExternalState.Active,
|
2020-12-07 20:43:19 +00:00
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
|
|
|
'Luigi Mario started a group call'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has a special message if you were the one to start the call', () => {
|
2023-08-09 00:53:06 +00:00
|
|
|
const callCreator = getDefaultConversation({
|
2023-01-12 23:29:07 +00:00
|
|
|
isMe: true,
|
|
|
|
});
|
2020-12-07 20:43:19 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
getCallingNotificationText(
|
|
|
|
{
|
2023-08-09 00:53:06 +00:00
|
|
|
callHistory: {
|
|
|
|
callId: '123',
|
|
|
|
peerId: getPeerIdFromConversation(getDefaultGroup()),
|
|
|
|
ringerId: callCreator.uuid ?? null,
|
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Outgoing,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
status: GroupCallStatus.Ringing,
|
|
|
|
},
|
|
|
|
callCreator,
|
|
|
|
callExternalState: CallExternalState.Active,
|
2020-12-07 20:43:19 +00:00
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
|
|
|
'You started a group call'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles an unknown creator', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
getCallingNotificationText(
|
|
|
|
{
|
2023-08-09 00:53:06 +00:00
|
|
|
callHistory: {
|
|
|
|
callId: '123',
|
|
|
|
peerId: getPeerIdFromConversation(getDefaultGroup()),
|
|
|
|
ringerId: null,
|
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Outgoing,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
status: GroupCallStatus.Ringing,
|
|
|
|
},
|
|
|
|
callCreator: null,
|
|
|
|
callExternalState: CallExternalState.Active,
|
2020-12-07 20:43:19 +00:00
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
|
|
|
'A group call was started'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|