2021-06-30 00:51:57 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
2021-08-02 19:26:48 +00:00
|
|
|
import * as moment from 'moment';
|
2021-07-01 23:57:10 +00:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2021-07-19 22:44:49 +00:00
|
|
|
import { SendStatus } from '../../../messages/MessageSendState';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2021-07-19 22:44:49 +00:00
|
|
|
MessageAttributesType,
|
|
|
|
ShallowChallengeError,
|
|
|
|
} from '../../../model-types.d';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConversationType } from '../../../state/ducks/conversations';
|
2022-11-19 08:31:18 +00:00
|
|
|
import {
|
|
|
|
getDefaultConversation,
|
|
|
|
getDefaultGroup,
|
|
|
|
} from '../../../test-both/helpers/getDefaultConversation';
|
2021-06-30 00:51:57 +00:00
|
|
|
|
|
|
|
import {
|
2021-08-02 19:26:48 +00:00
|
|
|
canDeleteForEveryone,
|
2021-10-29 23:19:44 +00:00
|
|
|
canReact,
|
2021-07-01 23:57:10 +00:00
|
|
|
canReply,
|
2022-07-11 23:34:55 +00:00
|
|
|
cleanBodyForDirectionCheck,
|
2021-07-19 22:44:49 +00:00
|
|
|
getMessagePropStatus,
|
2021-06-30 00:51:57 +00:00
|
|
|
isEndSession,
|
|
|
|
isGroupUpdate,
|
|
|
|
isIncoming,
|
|
|
|
isOutgoing,
|
|
|
|
} from '../../../state/selectors/message';
|
|
|
|
|
|
|
|
describe('state/selectors/messages', () => {
|
2021-07-19 22:44:49 +00:00
|
|
|
let ourConversationId: string;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
ourConversationId = uuid();
|
|
|
|
});
|
|
|
|
|
2022-07-11 23:34:55 +00:00
|
|
|
describe('cleanBodyForDirectionCheck', () => {
|
|
|
|
it('drops emoji', () => {
|
|
|
|
const body = "😮😮😮😮 that's wild!";
|
|
|
|
const expected = " that's wild!";
|
|
|
|
const actual = cleanBodyForDirectionCheck(body);
|
|
|
|
assert.strictEqual(actual, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('drops mentions', () => {
|
|
|
|
const body = "heyo, how's it going \uFFFC? And \uFFFC too!";
|
|
|
|
const expected = "heyo, how's it going ? And too!";
|
|
|
|
const actual = cleanBodyForDirectionCheck(body);
|
|
|
|
assert.strictEqual(actual, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('drops links', () => {
|
|
|
|
const body =
|
|
|
|
'You should download it from https://signal.org/download. Then read something on https://signal.org/blog. Then donate at https://signal.org/donate.';
|
|
|
|
const expected =
|
|
|
|
'You should download it from . Then read something on . Then donate at .';
|
|
|
|
const actual = cleanBodyForDirectionCheck(body);
|
|
|
|
assert.strictEqual(actual, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('drops all of them at the same time', () => {
|
|
|
|
const body =
|
|
|
|
'https://signal.org/download 😮 \uFFFC Did you really join Signal?';
|
|
|
|
const expected = ' Did you really join Signal?';
|
|
|
|
const actual = cleanBodyForDirectionCheck(body);
|
|
|
|
assert.strictEqual(actual, expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-08-02 19:26:48 +00:00
|
|
|
describe('canDeleteForEveryone', () => {
|
|
|
|
it('returns false for incoming messages', () => {
|
|
|
|
const message = {
|
|
|
|
type: 'incoming' as const,
|
|
|
|
sent_at: Date.now() - 1000,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.isFalse(canDeleteForEveryone(message));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false for messages that were already deleted for everyone', () => {
|
|
|
|
const message = {
|
|
|
|
type: 'outgoing' as const,
|
|
|
|
deletedForEveryone: true,
|
|
|
|
sent_at: Date.now() - 1000,
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Read,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Delivered,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.isFalse(canDeleteForEveryone(message));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false for messages that were are too old to delete', () => {
|
|
|
|
const message = {
|
|
|
|
type: 'outgoing' as const,
|
2023-10-13 21:54:36 +00:00
|
|
|
sent_at: Date.now() - moment.duration(25, 'hours').asMilliseconds(),
|
2021-08-02 19:26:48 +00:00
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Read,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Delivered,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.isFalse(canDeleteForEveryone(message));
|
|
|
|
});
|
|
|
|
|
2021-12-02 21:28:19 +00:00
|
|
|
it("returns false for messages that haven't been sent to anyone", () => {
|
2021-08-02 19:26:48 +00:00
|
|
|
const message = {
|
|
|
|
type: 'outgoing' as const,
|
|
|
|
sent_at: Date.now() - 1000,
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Failed,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
2021-12-02 21:28:19 +00:00
|
|
|
status: SendStatus.Pending,
|
2021-08-02 19:26:48 +00:00
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.isFalse(canDeleteForEveryone(message));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true for messages that meet all criteria for deletion', () => {
|
|
|
|
const message = {
|
|
|
|
type: 'outgoing' as const,
|
|
|
|
sent_at: Date.now() - 1000,
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
2021-12-02 21:28:19 +00:00
|
|
|
status: SendStatus.Sent,
|
2021-08-02 19:26:48 +00:00
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
2021-12-02 21:28:19 +00:00
|
|
|
status: SendStatus.Delivered,
|
2021-08-02 19:26:48 +00:00
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Failed,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.isTrue(canDeleteForEveryone(message));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-10-29 23:19:44 +00:00
|
|
|
describe('canReact', () => {
|
2022-11-19 08:31:18 +00:00
|
|
|
const defaultConversation = getDefaultConversation();
|
2021-10-29 23:19:44 +00:00
|
|
|
|
|
|
|
it('returns false for disabled v1 groups', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'incoming' as const,
|
|
|
|
};
|
|
|
|
const getConversationById = () => ({
|
2022-11-19 08:31:18 +00:00
|
|
|
...getDefaultGroup(),
|
2021-10-29 23:19:44 +00:00
|
|
|
isGroupV1AndDisabled: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.isFalse(canReact(message, ourConversationId, getConversationById));
|
|
|
|
});
|
|
|
|
|
|
|
|
// NOTE: This is missing a test for mandatory profile sharing.
|
|
|
|
|
|
|
|
it('returns false if the message was deleted for everyone', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'incoming' as const,
|
|
|
|
deletedForEveryone: true,
|
|
|
|
};
|
|
|
|
const getConversationById = () => defaultConversation;
|
|
|
|
|
|
|
|
assert.isFalse(canReact(message, ourConversationId, getConversationById));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false for outgoing messages that have not been sent', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'outgoing' as const,
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const getConversationById = () => defaultConversation;
|
|
|
|
|
|
|
|
assert.isFalse(canReact(message, ourConversationId, getConversationById));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true for outgoing messages that are only sent to yourself', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'outgoing' as const,
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const getConversationById = () => defaultConversation;
|
|
|
|
|
|
|
|
assert.isTrue(canReact(message, ourConversationId, getConversationById));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true for outgoing messages that have been sent to at least one person', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'outgoing' as const,
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const getConversationById = () => ({
|
2022-11-19 08:31:18 +00:00
|
|
|
...getDefaultGroup(),
|
2021-10-29 23:19:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.isTrue(canReact(message, ourConversationId, getConversationById));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true for incoming messages', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'incoming' as const,
|
|
|
|
};
|
|
|
|
const getConversationById = () => defaultConversation;
|
|
|
|
|
|
|
|
assert.isTrue(canReact(message, ourConversationId, getConversationById));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-07-01 23:57:10 +00:00
|
|
|
describe('canReply', () => {
|
|
|
|
const defaultConversation: ConversationType = {
|
|
|
|
id: uuid(),
|
|
|
|
type: 'direct',
|
|
|
|
title: 'Test conversation',
|
|
|
|
isMe: false,
|
|
|
|
sharedGroupNames: [],
|
|
|
|
acceptedMessageRequest: true,
|
2021-11-02 23:01:13 +00:00
|
|
|
badges: [],
|
2021-07-01 23:57:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
it('returns false for disabled v1 groups', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'incoming' as const,
|
|
|
|
};
|
|
|
|
const getConversationById = () => ({
|
2022-11-19 08:31:18 +00:00
|
|
|
...getDefaultGroup(),
|
2021-07-01 23:57:10 +00:00
|
|
|
isGroupV1AndDisabled: true,
|
|
|
|
});
|
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
assert.isFalse(canReply(message, ourConversationId, getConversationById));
|
2021-07-01 23:57:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// NOTE: This is missing a test for mandatory profile sharing.
|
|
|
|
|
|
|
|
it('returns false if the message was deleted for everyone', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'incoming' as const,
|
|
|
|
deletedForEveryone: true,
|
|
|
|
};
|
|
|
|
const getConversationById = () => defaultConversation;
|
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
assert.isFalse(canReply(message, ourConversationId, getConversationById));
|
2021-07-01 23:57:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false for outgoing messages that have not been sent', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'outgoing' as const,
|
2021-07-19 22:44:49 +00:00
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const getConversationById = () => defaultConversation;
|
|
|
|
|
|
|
|
assert.isFalse(canReply(message, ourConversationId, getConversationById));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true for outgoing messages that are only sent to yourself', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'outgoing' as const,
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
2021-07-01 23:57:10 +00:00
|
|
|
};
|
|
|
|
const getConversationById = () => defaultConversation;
|
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
assert.isTrue(canReply(message, ourConversationId, getConversationById));
|
2021-07-01 23:57:10 +00:00
|
|
|
});
|
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
it('returns true for outgoing messages that have been sent to at least one person', () => {
|
2021-07-01 23:57:10 +00:00
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'outgoing' as const,
|
2021-07-19 22:44:49 +00:00
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
2021-07-01 23:57:10 +00:00
|
|
|
};
|
2022-11-19 08:31:18 +00:00
|
|
|
const getConversationById = () => getDefaultGroup();
|
2021-07-01 23:57:10 +00:00
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
assert.isTrue(canReply(message, ourConversationId, getConversationById));
|
2021-07-01 23:57:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true for incoming messages', () => {
|
|
|
|
const message = {
|
|
|
|
conversationId: 'fake-conversation-id',
|
|
|
|
type: 'incoming' as const,
|
|
|
|
};
|
|
|
|
const getConversationById = () => defaultConversation;
|
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
assert.isTrue(canReply(message, ourConversationId, getConversationById));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getMessagePropStatus', () => {
|
|
|
|
const createMessage = (overrides: Partial<MessageAttributesType>) => ({
|
|
|
|
type: 'outgoing' as const,
|
|
|
|
...overrides,
|
|
|
|
});
|
|
|
|
|
2022-05-31 16:26:07 +00:00
|
|
|
it('returns undefined for incoming messages with no errors', () => {
|
2021-07-19 22:44:49 +00:00
|
|
|
const message = createMessage({ type: 'incoming' });
|
|
|
|
|
2021-07-21 19:21:16 +00:00
|
|
|
assert.isUndefined(getMessagePropStatus(message, ourConversationId));
|
2021-07-19 22:44:49 +00:00
|
|
|
});
|
|
|
|
|
2022-05-31 16:26:07 +00:00
|
|
|
it('returns "error" for incoming messages with errors', () => {
|
|
|
|
const message = createMessage({
|
|
|
|
type: 'incoming',
|
|
|
|
errors: [new Error('something went wrong')],
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
getMessagePropStatus(message, ourConversationId),
|
|
|
|
'error'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
it('returns "paused" for messages with challenges', () => {
|
|
|
|
const challengeError: ShallowChallengeError = Object.assign(
|
|
|
|
new Error('a challenge'),
|
|
|
|
{
|
|
|
|
name: 'SendMessageChallengeError',
|
|
|
|
retryAfter: 123,
|
|
|
|
data: {},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
const message = createMessage({ errors: [challengeError] });
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2021-07-21 19:21:16 +00:00
|
|
|
getMessagePropStatus(message, ourConversationId),
|
2021-07-19 22:44:49 +00:00
|
|
|
'paused'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns "partial-sent" if the message has errors but was sent to at least one person', () => {
|
|
|
|
const message = createMessage({
|
|
|
|
errors: [new Error('whoopsie')],
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Delivered,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2021-07-21 19:21:16 +00:00
|
|
|
getMessagePropStatus(message, ourConversationId),
|
2021-07-19 22:44:49 +00:00
|
|
|
'partial-sent'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns "error" if the message has errors and has not been sent', () => {
|
|
|
|
const message = createMessage({
|
|
|
|
errors: [new Error('whoopsie')],
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2021-07-21 19:21:16 +00:00
|
|
|
getMessagePropStatus(message, ourConversationId),
|
2021-07-19 22:44:49 +00:00
|
|
|
'error'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-07-27 15:42:25 +00:00
|
|
|
it('returns "viewed" if the message is just for you and has been sent', () => {
|
2021-07-19 22:44:49 +00:00
|
|
|
const message = createMessage({
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-07-21 19:21:16 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
getMessagePropStatus(message, ourConversationId),
|
2021-07-27 15:42:25 +00:00
|
|
|
'viewed'
|
2021-07-21 19:21:16 +00:00
|
|
|
);
|
2021-07-19 22:44:49 +00:00
|
|
|
});
|
|
|
|
|
2021-07-27 15:42:25 +00:00
|
|
|
it('returns "viewed" if the message was viewed by at least one person', () => {
|
|
|
|
const message = createMessage({
|
2021-07-19 22:44:49 +00:00
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
2021-07-27 15:42:25 +00:00
|
|
|
status: SendStatus.Viewed,
|
2021-07-19 22:44:49 +00:00
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Read,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
assert.strictEqual(
|
2021-07-27 15:42:25 +00:00
|
|
|
getMessagePropStatus(message, ourConversationId),
|
|
|
|
'viewed'
|
2021-07-19 22:44:49 +00:00
|
|
|
);
|
2021-07-27 15:42:25 +00:00
|
|
|
});
|
2021-07-19 22:44:49 +00:00
|
|
|
|
2021-07-27 15:42:25 +00:00
|
|
|
it('returns "read" if the message was read by at least one person', () => {
|
|
|
|
const message = createMessage({
|
2021-07-19 22:44:49 +00:00
|
|
|
sendStateByConversationId: {
|
2021-07-27 15:42:25 +00:00
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
2021-07-19 22:44:49 +00:00
|
|
|
[uuid()]: {
|
2021-07-27 15:42:25 +00:00
|
|
|
status: SendStatus.Read,
|
2021-07-19 22:44:49 +00:00
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
assert.strictEqual(
|
2021-07-27 15:42:25 +00:00
|
|
|
getMessagePropStatus(message, ourConversationId),
|
2021-07-19 22:44:49 +00:00
|
|
|
'read'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns "delivered" if the message was delivered to at least one person, but no "higher"', () => {
|
|
|
|
const message = createMessage({
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Delivered,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2021-07-21 19:21:16 +00:00
|
|
|
getMessagePropStatus(message, ourConversationId),
|
2021-07-19 22:44:49 +00:00
|
|
|
'delivered'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns "sent" if the message was sent to at least one person, but no "higher"', () => {
|
|
|
|
const message = createMessage({
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2021-07-21 19:21:16 +00:00
|
|
|
getMessagePropStatus(message, ourConversationId),
|
2021-07-19 22:44:49 +00:00
|
|
|
'sent'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns "sending" if the message has not been sent yet, even if it has been synced to yourself', () => {
|
|
|
|
const message = createMessage({
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Sent,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
[uuid()]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(
|
2021-07-21 19:21:16 +00:00
|
|
|
getMessagePropStatus(message, ourConversationId),
|
2021-07-19 22:44:49 +00:00
|
|
|
'sending'
|
|
|
|
);
|
2021-07-01 23:57:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-30 00:51:57 +00:00
|
|
|
describe('isEndSession', () => {
|
|
|
|
it('checks if it is end of the session', () => {
|
|
|
|
assert.isFalse(isEndSession({}));
|
|
|
|
assert.isFalse(isEndSession({ flags: undefined }));
|
|
|
|
assert.isFalse(isEndSession({ flags: 0 }));
|
|
|
|
assert.isFalse(isEndSession({ flags: 2 }));
|
|
|
|
assert.isFalse(isEndSession({ flags: 4 }));
|
|
|
|
|
|
|
|
assert.isTrue(isEndSession({ flags: 1 }));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isGroupUpdate', () => {
|
|
|
|
it('checks if is group update', () => {
|
|
|
|
assert.isFalse(isGroupUpdate({}));
|
|
|
|
assert.isFalse(isGroupUpdate({ group_update: undefined }));
|
|
|
|
|
|
|
|
assert.isTrue(isGroupUpdate({ group_update: { left: 'You' } }));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isIncoming', () => {
|
|
|
|
it('checks if is incoming message', () => {
|
|
|
|
assert.isFalse(isIncoming({ type: 'outgoing' }));
|
|
|
|
assert.isFalse(isIncoming({ type: 'call-history' }));
|
|
|
|
|
|
|
|
assert.isTrue(isIncoming({ type: 'incoming' }));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isOutgoing', () => {
|
|
|
|
it('checks if is outgoing message', () => {
|
|
|
|
assert.isFalse(isOutgoing({ type: 'incoming' }));
|
|
|
|
assert.isFalse(isOutgoing({ type: 'call-history' }));
|
|
|
|
|
|
|
|
assert.isTrue(isOutgoing({ type: 'outgoing' }));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|