2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
import { assert } from 'chai';
|
|
|
|
import * as sinon from 'sinon';
|
|
|
|
import { setup as setupI18n } from '../../../js/modules/i18n';
|
|
|
|
import enMessages from '../../../_locales/en/messages.json';
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
describe('Message', () => {
|
2020-10-26 22:15:28 +00:00
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
const attributes = {
|
|
|
|
type: 'outgoing',
|
|
|
|
body: 'hi',
|
|
|
|
conversationId: 'foo',
|
|
|
|
attachments: [],
|
|
|
|
received_at: new Date().getTime(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const source = '+1 415-555-5555';
|
|
|
|
const me = '+14155555556';
|
|
|
|
const ourUuid = window.getGuid();
|
|
|
|
|
|
|
|
function createMessage(attrs: { [key: string]: unknown }) {
|
2021-02-26 21:06:37 +00:00
|
|
|
const messages = new window.Whisper.MessageCollection();
|
2021-03-04 21:44:57 +00:00
|
|
|
return messages.add({
|
|
|
|
received_at: Date.now(),
|
|
|
|
...attrs,
|
|
|
|
});
|
2020-09-04 22:51:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
before(async () => {
|
|
|
|
window.ConversationController.reset();
|
|
|
|
await window.ConversationController.load();
|
|
|
|
window.textsecure.storage.put('number_id', `${me}.2`);
|
|
|
|
window.textsecure.storage.put('uuid_id', `${ourUuid}.2`);
|
|
|
|
});
|
|
|
|
|
|
|
|
after(async () => {
|
|
|
|
window.textsecure.storage.put('number_id', null);
|
|
|
|
window.textsecure.storage.put('uuid_id', null);
|
|
|
|
|
|
|
|
await window.Signal.Data.removeAll();
|
|
|
|
await window.storage.fetch();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function beforeEach() {
|
|
|
|
this.sandbox = sinon.createSandbox();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function afterEach() {
|
|
|
|
this.sandbox.restore();
|
|
|
|
});
|
|
|
|
|
2020-10-22 17:32:23 +00:00
|
|
|
// NOTE: These tests are incomplete.
|
|
|
|
describe('send', () => {
|
|
|
|
it("saves the result's dataMessage", async () => {
|
|
|
|
const message = createMessage({ type: 'outgoing', source });
|
|
|
|
|
|
|
|
const fakeDataMessage = new ArrayBuffer(0);
|
|
|
|
const result = {
|
|
|
|
dataMessage: fakeDataMessage,
|
|
|
|
};
|
|
|
|
const promise = Promise.resolve(result);
|
|
|
|
await message.send(promise);
|
|
|
|
|
|
|
|
assert.strictEqual(message.get('dataMessage'), fakeDataMessage);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates the `sent` attribute', async () => {
|
|
|
|
const message = createMessage({ type: 'outgoing', source, sent: false });
|
|
|
|
|
2020-10-28 21:54:33 +00:00
|
|
|
await message.send(Promise.resolve({}));
|
2020-10-22 17:32:23 +00:00
|
|
|
|
|
|
|
assert.isTrue(message.get('sent'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("triggers the 'done' event on success", async () => {
|
|
|
|
const message = createMessage({ type: 'outgoing', source });
|
|
|
|
|
|
|
|
let callCount = 0;
|
|
|
|
message.on('done', () => {
|
|
|
|
callCount += 1;
|
|
|
|
});
|
|
|
|
|
2020-10-28 21:54:33 +00:00
|
|
|
await message.send(Promise.resolve({}));
|
2020-10-22 17:32:23 +00:00
|
|
|
|
|
|
|
assert.strictEqual(callCount, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("triggers the 'sent' event on success", async () => {
|
|
|
|
const message = createMessage({ type: 'outgoing', source });
|
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
const listener = sinon.spy();
|
|
|
|
message.on('sent', listener);
|
2020-10-22 17:32:23 +00:00
|
|
|
|
2020-10-28 21:54:33 +00:00
|
|
|
await message.send(Promise.resolve({}));
|
2020-10-22 17:32:23 +00:00
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
sinon.assert.calledOnce(listener);
|
|
|
|
sinon.assert.calledWith(listener, message);
|
2020-10-22 17:32:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("triggers the 'done' event on failure", async () => {
|
|
|
|
const message = createMessage({ type: 'outgoing', source });
|
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
const listener = sinon.spy();
|
|
|
|
message.on('done', listener);
|
2020-10-22 17:32:23 +00:00
|
|
|
|
|
|
|
await message.send(Promise.reject(new Error('something went wrong!')));
|
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
sinon.assert.calledOnce(listener);
|
2020-10-22 17:32:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('saves errors from promise rejections with errors', async () => {
|
|
|
|
const message = createMessage({ type: 'outgoing', source });
|
|
|
|
|
|
|
|
const promise = Promise.reject(new Error('foo bar'));
|
|
|
|
await message.send(promise);
|
|
|
|
|
|
|
|
const errors = message.get('errors') || [];
|
|
|
|
assert.lengthOf(errors, 1);
|
|
|
|
assert.strictEqual(errors[0].message, 'foo bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('saves errors from promise rejections with objects', async () => {
|
|
|
|
const message = createMessage({ type: 'outgoing', source });
|
|
|
|
|
|
|
|
const result = {
|
|
|
|
errors: [new Error('baz qux')],
|
|
|
|
};
|
|
|
|
const promise = Promise.reject(result);
|
|
|
|
await message.send(promise);
|
|
|
|
|
|
|
|
const errors = message.get('errors') || [];
|
|
|
|
assert.lengthOf(errors, 1);
|
|
|
|
assert.strictEqual(errors[0].message, 'baz qux');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
describe('getContact', () => {
|
|
|
|
it('gets outgoing contact', () => {
|
2021-02-26 21:06:37 +00:00
|
|
|
const messages = new window.Whisper.MessageCollection();
|
2020-09-04 22:51:50 +00:00
|
|
|
const message = messages.add(attributes);
|
|
|
|
message.getContact();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('gets incoming contact', () => {
|
2021-02-26 21:06:37 +00:00
|
|
|
const messages = new window.Whisper.MessageCollection();
|
2020-09-04 22:51:50 +00:00
|
|
|
const message = messages.add({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
});
|
|
|
|
message.getContact();
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
describe('isIncoming', () => {
|
|
|
|
it('checks if is incoming message', () => {
|
2021-02-26 21:06:37 +00:00
|
|
|
const messages = new window.Whisper.MessageCollection();
|
2020-09-04 22:51:50 +00:00
|
|
|
let message = messages.add(attributes);
|
|
|
|
assert.notOk(message.isIncoming());
|
|
|
|
message = messages.add({ type: 'incoming' });
|
|
|
|
assert.ok(message.isIncoming());
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
describe('isOutgoing', () => {
|
|
|
|
it('checks if is outgoing message', () => {
|
2021-02-26 21:06:37 +00:00
|
|
|
const messages = new window.Whisper.MessageCollection();
|
2020-09-04 22:51:50 +00:00
|
|
|
let message = messages.add(attributes);
|
|
|
|
assert.ok(message.isOutgoing());
|
|
|
|
message = messages.add({ type: 'incoming' });
|
|
|
|
assert.notOk(message.isOutgoing());
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
describe('isGroupUpdate', () => {
|
|
|
|
it('checks if is group update', () => {
|
2021-02-26 21:06:37 +00:00
|
|
|
const messages = new window.Whisper.MessageCollection();
|
2020-09-04 22:51:50 +00:00
|
|
|
let message = messages.add(attributes);
|
|
|
|
assert.notOk(message.isGroupUpdate());
|
|
|
|
|
|
|
|
message = messages.add({ group_update: true });
|
|
|
|
assert.ok(message.isGroupUpdate());
|
2018-04-27 21:25:04 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|
2014-11-13 22:35:37 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
// Note that some of this method's behavior is untested:
|
|
|
|
// - Call history
|
|
|
|
// - Contacts
|
|
|
|
// - Expiration timer updates
|
|
|
|
// - Key changes
|
|
|
|
// - Profile changes
|
|
|
|
// - Stickers
|
|
|
|
describe('getNotificationData', () => {
|
|
|
|
it('handles unsupported messages', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
supportedVersionAtReceive: 0,
|
|
|
|
requiredProtocolVersion: Infinity,
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: 'Unsupported message' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles erased tap-to-view messages', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
isViewOnce: true,
|
|
|
|
isErased: true,
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: 'View-once Media' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles tap-to-view photos', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
isViewOnce: true,
|
|
|
|
isErased: false,
|
|
|
|
attachments: [
|
|
|
|
{
|
|
|
|
contentType: 'image/png',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: 'View-once Photo', emoji: '📷' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles tap-to-view videos', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
isViewOnce: true,
|
|
|
|
isErased: false,
|
|
|
|
attachments: [
|
|
|
|
{
|
|
|
|
contentType: 'video/mp4',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: 'View-once Video', emoji: '🎥' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles non-media tap-to-view file types', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
isViewOnce: true,
|
|
|
|
isErased: false,
|
|
|
|
attachments: [
|
|
|
|
{
|
|
|
|
contentType: 'text/plain',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: 'Media Message', emoji: '📎' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles group updates where you left the group', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
group_update: {
|
|
|
|
left: 'You',
|
|
|
|
},
|
|
|
|
}).getNotificationData(),
|
2020-09-09 02:25:05 +00:00
|
|
|
{ text: 'You are no longer a member of the group.' }
|
2020-09-04 22:51:50 +00:00
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles group updates where someone left the group', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: {
|
|
|
|
left: 'Alice',
|
|
|
|
},
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: 'Alice left the group.' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles empty group updates with a generic message', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source: 'Alice',
|
|
|
|
group_update: {},
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: 'Alice updated the group.' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles group name updates by you', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source: me,
|
|
|
|
group_update: { name: 'blerg' },
|
|
|
|
}).getNotificationData(),
|
|
|
|
{
|
|
|
|
text: "You updated the group. Group name is now 'blerg'.",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles group name updates by someone else', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: { name: 'blerg' },
|
|
|
|
}).getNotificationData(),
|
|
|
|
{
|
|
|
|
text: "+1 415-555-5555 updated the group. Group name is now 'blerg'.",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles group avatar updates', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: { avatarUpdated: true },
|
|
|
|
}).getNotificationData(),
|
|
|
|
{
|
|
|
|
text: '+1 415-555-5555 updated the group. Group avatar was updated.',
|
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles you joining the group', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: { joined: [me] },
|
|
|
|
}).getNotificationData(),
|
|
|
|
{
|
|
|
|
text: '+1 415-555-5555 updated the group. You joined the group.',
|
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles someone else joining the group', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: { joined: ['Bob'] },
|
|
|
|
}).getNotificationData(),
|
|
|
|
{
|
|
|
|
text: '+1 415-555-5555 updated the group. Bob joined the group.',
|
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles multiple people joining the group', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: { joined: ['Bob', 'Alice', 'Eve'] },
|
|
|
|
}).getNotificationData(),
|
|
|
|
{
|
|
|
|
text:
|
|
|
|
'+1 415-555-5555 updated the group. Bob, Alice, Eve joined the group.',
|
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles multiple people joining the group, including you', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: { joined: ['Bob', me, 'Alice', 'Eve'] },
|
|
|
|
}).getNotificationData(),
|
|
|
|
{
|
|
|
|
text:
|
|
|
|
'+1 415-555-5555 updated the group. Bob, Alice, Eve joined the group. You joined the group.',
|
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles multiple changes to group properties', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: { joined: ['Bob'], name: 'blerg' },
|
|
|
|
}).getNotificationData(),
|
|
|
|
{
|
|
|
|
text:
|
|
|
|
"+1 415-555-5555 updated the group. Bob joined the group. Group name is now 'blerg'.",
|
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles a session ending', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
flags: true,
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: i18n('sessionEnded') }
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles incoming message errors', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
errors: [{}],
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: i18n('incomingError') }
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
const attachmentTestCases = [
|
|
|
|
{
|
|
|
|
title: 'GIF',
|
|
|
|
attachment: {
|
|
|
|
contentType: 'image/gif',
|
|
|
|
},
|
|
|
|
expectedText: 'GIF',
|
|
|
|
expectedEmoji: '🎡',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'photo',
|
|
|
|
attachment: {
|
|
|
|
contentType: 'image/png',
|
|
|
|
},
|
|
|
|
expectedText: 'Photo',
|
|
|
|
expectedEmoji: '📷',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'video',
|
|
|
|
attachment: {
|
|
|
|
contentType: 'video/mp4',
|
|
|
|
},
|
|
|
|
expectedText: 'Video',
|
|
|
|
expectedEmoji: '🎥',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'voice message',
|
|
|
|
attachment: {
|
|
|
|
contentType: 'audio/ogg',
|
2020-10-26 22:15:28 +00:00
|
|
|
flags:
|
|
|
|
window.textsecure.protobuf.AttachmentPointer.Flags.VOICE_MESSAGE,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
expectedText: 'Voice Message',
|
|
|
|
expectedEmoji: '🎤',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'audio message',
|
|
|
|
attachment: {
|
|
|
|
contentType: 'audio/ogg',
|
|
|
|
fileName: 'audio.ogg',
|
|
|
|
},
|
|
|
|
expectedText: 'Audio Message',
|
|
|
|
expectedEmoji: '🔈',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'plain text',
|
|
|
|
attachment: {
|
|
|
|
contentType: 'text/plain',
|
|
|
|
},
|
|
|
|
expectedText: 'File',
|
|
|
|
expectedEmoji: '📎',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'unspecified-type',
|
|
|
|
attachment: {
|
|
|
|
contentType: null,
|
|
|
|
},
|
|
|
|
expectedText: 'File',
|
|
|
|
expectedEmoji: '📎',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
attachmentTestCases.forEach(
|
|
|
|
({ title, attachment, expectedText, expectedEmoji }) => {
|
|
|
|
it(`handles single ${title} attachments`, () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
attachments: [attachment],
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: expectedText, emoji: expectedEmoji }
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`handles multiple attachments where the first is a ${title}`, () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
attachments: [
|
|
|
|
attachment,
|
|
|
|
{
|
|
|
|
contentType: 'text/html',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: expectedText, emoji: expectedEmoji }
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`respects the caption for ${title} attachments`, () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
attachments: [attachment],
|
|
|
|
body: 'hello world',
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: 'hello world', emoji: expectedEmoji }
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2018-11-02 18:02:53 +00:00
|
|
|
);
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles a "plain" message', () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
body: 'hello world',
|
|
|
|
}).getNotificationData(),
|
|
|
|
{ text: 'hello world' }
|
|
|
|
);
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|
2020-09-04 22:51:50 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
describe('getNotificationText', () => {
|
|
|
|
it("returns a notification's text", () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
body: 'hello world',
|
|
|
|
}).getNotificationText(),
|
|
|
|
'hello world'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
it("shows a notification's emoji on non-Linux", function test() {
|
|
|
|
this.sandbox.stub(window.Signal.OS, 'isLinux').returns(false);
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
attachments: [
|
|
|
|
{
|
|
|
|
contentType: 'image/png',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}).getNotificationText(),
|
|
|
|
'📷 Photo'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
it('hides emoji on Linux', function test() {
|
|
|
|
this.sandbox.stub(window.Signal.OS, 'isLinux').returns(true);
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
attachments: [
|
|
|
|
{
|
|
|
|
contentType: 'image/png',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}).getNotificationText(),
|
|
|
|
'Photo'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isEndSession', () => {
|
|
|
|
it('checks if it is end of the session', () => {
|
2021-02-26 21:06:37 +00:00
|
|
|
const messages = new window.Whisper.MessageCollection();
|
2020-09-04 22:51:50 +00:00
|
|
|
let message = messages.add(attributes);
|
|
|
|
assert.notOk(message.isEndSession());
|
|
|
|
|
|
|
|
message = messages.add({ type: 'incoming', source, flags: true });
|
|
|
|
assert.ok(message.isEndSession());
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|
2020-09-04 22:51:50 +00:00
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
describe('MessageCollection', () => {
|
|
|
|
it('should be ordered oldest to newest', () => {
|
2021-02-26 21:06:37 +00:00
|
|
|
const messages = new window.Whisper.MessageCollection();
|
2020-09-04 22:51:50 +00:00
|
|
|
// Timestamps
|
2020-10-26 22:15:28 +00:00
|
|
|
const today = Date.now();
|
|
|
|
const tomorrow = today + 12345;
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
// Add threads
|
|
|
|
messages.add({ received_at: today });
|
|
|
|
messages.add({ received_at: tomorrow });
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
const { models } = messages;
|
2020-10-26 22:15:28 +00:00
|
|
|
const firstTimestamp = models[0].get('received_at');
|
|
|
|
const secondTimestamp = models[1].get('received_at');
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
// Compare timestamps
|
2020-10-26 22:15:28 +00:00
|
|
|
assert(typeof firstTimestamp === 'number');
|
|
|
|
assert(typeof secondTimestamp === 'number');
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
assert(firstTimestamp! < secondTimestamp!);
|
2018-04-27 21:25:04 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|