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-21 17:09:54 +00:00
|
|
|
import { getCallingNotificationText } from '../../util/callingNotification';
|
2024-08-06 19:29:13 +00:00
|
|
|
import {
|
|
|
|
CallMode,
|
|
|
|
CallDirection,
|
|
|
|
CallType,
|
|
|
|
GroupCallStatus,
|
|
|
|
} from '../../types/CallDisposition';
|
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 { getPeerIdFromConversation } from '../../util/callDisposition';
|
2024-07-30 23:21:33 +00:00
|
|
|
import { HOUR } from '../../util/durations';
|
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.
|
|
|
|
|
2024-07-30 23:21:33 +00:00
|
|
|
it('says that the incoming 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()),
|
2023-08-16 20:54:39 +00:00
|
|
|
ringerId: callCreator.serviceId ?? null,
|
2023-08-09 00:53:06 +00:00
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
timestamp: Date.now(),
|
2024-07-30 23:21:33 +00:00
|
|
|
status: GroupCallStatus.Joined,
|
|
|
|
},
|
|
|
|
callCreator,
|
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: true,
|
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
|
|
|
'The video call has ended'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('says that the outgoing call has ended', () => {
|
|
|
|
const callCreator = getDefaultConversation();
|
|
|
|
assert.strictEqual(
|
|
|
|
getCallingNotificationText(
|
|
|
|
{
|
|
|
|
callHistory: {
|
|
|
|
callId: '123',
|
|
|
|
peerId: getPeerIdFromConversation(getDefaultGroup()),
|
|
|
|
ringerId: callCreator.serviceId ?? null,
|
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Outgoing,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
status: GroupCallStatus.Joined,
|
|
|
|
},
|
|
|
|
callCreator,
|
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: true,
|
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
|
|
|
'The video call has ended'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('says declined incoming calls', () => {
|
|
|
|
const callCreator = getDefaultConversation();
|
|
|
|
assert.strictEqual(
|
|
|
|
getCallingNotificationText(
|
|
|
|
{
|
|
|
|
callHistory: {
|
|
|
|
callId: '123',
|
|
|
|
peerId: getPeerIdFromConversation(getDefaultGroup()),
|
|
|
|
ringerId: callCreator.serviceId ?? null,
|
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
status: GroupCallStatus.Declined,
|
|
|
|
},
|
|
|
|
callCreator,
|
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: true,
|
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
|
|
|
'Declined video call'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('says older ended incoming calls', () => {
|
|
|
|
const callCreator = getDefaultConversation();
|
|
|
|
assert.strictEqual(
|
|
|
|
getCallingNotificationText(
|
|
|
|
{
|
|
|
|
callHistory: {
|
|
|
|
callId: '123',
|
|
|
|
peerId: getPeerIdFromConversation(getDefaultGroup()),
|
|
|
|
ringerId: callCreator.serviceId ?? null,
|
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
timestamp: Date.now() - HOUR,
|
|
|
|
status: GroupCallStatus.Joined,
|
|
|
|
},
|
|
|
|
callCreator,
|
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: true,
|
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
|
|
|
'Incoming video call'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('says older ended incoming missed calls', () => {
|
|
|
|
const callCreator = getDefaultConversation();
|
|
|
|
assert.strictEqual(
|
|
|
|
getCallingNotificationText(
|
|
|
|
{
|
|
|
|
callHistory: {
|
|
|
|
callId: '123',
|
|
|
|
peerId: getPeerIdFromConversation(getDefaultGroup()),
|
|
|
|
ringerId: callCreator.serviceId ?? null,
|
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
timestamp: Date.now() - HOUR,
|
2023-08-09 00:53:06 +00:00
|
|
|
status: GroupCallStatus.Missed,
|
|
|
|
},
|
|
|
|
callCreator,
|
2023-08-21 17:09:54 +00:00
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: true,
|
2020-12-07 20:43:19 +00:00
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
2023-12-12 16:11:39 +00:00
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
2020-12-07 20:43:19 +00:00
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
2024-07-30 23:21:33 +00:00
|
|
|
'Missed video call'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('says older ended outgoing calls', () => {
|
|
|
|
const callCreator = getDefaultConversation();
|
|
|
|
assert.strictEqual(
|
|
|
|
getCallingNotificationText(
|
|
|
|
{
|
|
|
|
callHistory: {
|
|
|
|
callId: '123',
|
|
|
|
peerId: getPeerIdFromConversation(getDefaultGroup()),
|
|
|
|
ringerId: callCreator.serviceId ?? null,
|
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Outgoing,
|
|
|
|
timestamp: Date.now() - HOUR,
|
|
|
|
status: GroupCallStatus.Joined,
|
|
|
|
},
|
|
|
|
callCreator,
|
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: true,
|
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
|
|
|
'Outgoing video call'
|
2020-12-07 20:43:19 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
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()),
|
2023-08-16 20:54:39 +00:00
|
|
|
ringerId: callCreator.serviceId ?? null,
|
2023-08-09 00:53:06 +00:00
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
status: GroupCallStatus.Ringing,
|
|
|
|
},
|
|
|
|
callCreator,
|
2023-08-21 17:09:54 +00:00
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: false,
|
2020-12-07 20:43:19 +00:00
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
2023-12-12 16:11:39 +00:00
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
2020-12-07 20:43:19 +00:00
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
2024-07-30 23:21:33 +00:00
|
|
|
'Luigi started a video call'
|
2020-12-07 20:43:19 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
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()),
|
2023-08-16 20:54:39 +00:00
|
|
|
ringerId: callCreator.serviceId ?? null,
|
2023-08-09 00:53:06 +00:00
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
status: GroupCallStatus.Ringing,
|
|
|
|
},
|
|
|
|
callCreator,
|
2023-08-21 17:09:54 +00:00
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: false,
|
2020-12-07 20:43:19 +00:00
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
2023-12-12 16:11:39 +00:00
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
2020-12-07 20:43:19 +00:00
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
2024-07-30 23:21:33 +00:00
|
|
|
'Luigi Mario started a video call'
|
2020-12-07 20:43:19 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
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()),
|
2023-08-16 20:54:39 +00:00
|
|
|
ringerId: callCreator.serviceId ?? null,
|
2023-08-09 00:53:06 +00:00
|
|
|
mode: CallMode.Group,
|
|
|
|
type: CallType.Group,
|
|
|
|
direction: CallDirection.Outgoing,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
status: GroupCallStatus.Ringing,
|
|
|
|
},
|
|
|
|
callCreator,
|
2023-08-21 17:09:54 +00:00
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: false,
|
2020-12-07 20:43:19 +00:00
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
2023-12-12 16:11:39 +00:00
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
2020-12-07 20:43:19 +00:00
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
2024-07-30 23:21:33 +00:00
|
|
|
'You started a video call'
|
2020-12-07 20:43:19 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
2023-08-21 17:09:54 +00:00
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: false,
|
2020-12-07 20:43:19 +00:00
|
|
|
deviceCount: 1,
|
|
|
|
maxDevices: 23,
|
2023-12-12 16:11:39 +00:00
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
2020-12-07 20:43:19 +00:00
|
|
|
},
|
|
|
|
i18n
|
|
|
|
),
|
2024-07-30 23:21:33 +00:00
|
|
|
'A video call was started'
|
2020-12-07 20:43:19 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|