test: finished changeToDisappearingMessageType tests

pull/2971/head
William Grant 2 years ago
parent a9d1abbfff
commit 769808bd5c

@ -91,7 +91,8 @@ export interface ConversationAttributes {
profileKey?: string; // Consider this being a hex string if it is set
triggerNotificationsFor: ConversationNotificationSettingType;
avatarPointer?: string; // this is the url of the avatar on the file server v2. we use this to detect if we need to redownload the avatar from someone (not used for opengroups)
expireTimer: number; // in seconds, 0 means no expiration
/** in seconds, 0 means no expiration */
expireTimer: number;
members: Array<string>; // groups only members are all members for this group. zombies excluded (not used for communities)
groupAdmins: Array<string>; // for sogs and closed group: the unique admins of that group
@ -105,9 +106,12 @@ export interface ConversationAttributes {
blocksSogsMsgReqsTimestamp: number; // if the convo is blinded and the user has denied contact through sogs, this field be set to the user's latest message timestamp
expirationMode: DisappearingMessageConversationModeType; // disappearing messages setting for this conversation
lastDisappearingMessageChangeTimestamp: number; // to avoid applying a change of disappear change when our current one was applied more recently
hasOutdatedClient?: string; // to warn the user that the person he is talking to is using an old client which might cause issues
/** disappearing messages setting for this conversation */
expirationMode: DisappearingMessageConversationModeType;
/** to avoid applying a change of disappear change when our current one was applied more recently */
lastDisappearingMessageChangeTimestamp: number;
/** to warn the user that the person he is talking to is using an old client which might cause issues */
hasOutdatedClient?: string;
}
/**

@ -3,17 +3,32 @@ import Sinon from 'sinon';
import { stubWindowLog } from '../../../test-utils/utils';
import {
DisappearingMessageConversationModeType,
DisappearingMessageType,
changeToDisappearingConversationMode,
setExpirationStartTimestamp,
} from '../../../../util/expiringMessages';
import { isValidUnixTimestamp } from '../../../../session/utils/Timestamps';
import { GetNetworkTime } from '../../../../session/apis/snode_api/getNetworkTime';
import { ConversationModel } from '../../../../models/conversation';
import { ConversationTypeEnum } from '../../../../models/conversationAttributes';
import { UserUtils } from '../../../../session/utils';
describe('Disappearing Messages', () => {
stubWindowLog();
const getLatestTimestampOffset = 200000;
const ourNumber = '051234567890acbdef';
const conversationArgs = {
id: '050123456789abcdef050123456789abcdef0123456789abcdef050123456789ab',
type: ConversationTypeEnum.PRIVATE,
isApproved: true,
active_at: 123,
didApproveMe: true,
};
beforeEach(() => {
Sinon.stub(GetNetworkTime, 'getLatestTimestampOffset').returns(getLatestTimestampOffset);
Sinon.stub(UserUtils, 'getOurPubKeyStrFromCache').returns(ourNumber);
});
afterEach(() => {
@ -87,16 +102,140 @@ describe('Disappearing Messages', () => {
});
});
it('changeToDisappearingMessageType', async () => {
expect('TODO').to.be.eq('TODO');
describe('changeToDisappearingMessageType', () => {
it("if it's a Note to Self Conversation and expireTimer > 0 then the conversation mode is always deleteAfterSend", async () => {
const ourConversation = new ConversationModel({
...conversationArgs,
id: ourNumber,
} as any);
const expirationType = 'deleteAfterRead'; // not correct
const expireTimer = 60; // seconds
const conversationMode = changeToDisappearingConversationMode(
ourConversation,
expirationType,
expireTimer
);
expect(conversationMode, 'returns deleteAfterSend').to.be.eq('deleteAfterSend');
});
it("if it's a Group Conversation and expireTimer > 0 then the conversation mode is always deleteAfterSend", async () => {
const ourConversation = new ConversationModel({
...conversationArgs,
type: ConversationTypeEnum.GROUP,
// TODO update to 03 prefix when we release new groups
id: '05123456564',
} as any);
const expirationType = 'deleteAfterRead'; // not correct
const expireTimer = 60; // seconds
const conversationMode = changeToDisappearingConversationMode(
ourConversation,
expirationType,
expireTimer
);
expect(conversationMode, 'returns deleteAfterSend').to.be.eq('deleteAfterSend');
});
it("if it's a Private Conversation and expirationType is deleteAfterRead and expireTimer > 0 then the conversation mode stays as deleteAfterRead", async () => {
const ourConversation = new ConversationModel({
...conversationArgs,
} as any);
const expirationType = 'deleteAfterRead';
const expireTimer = 60; // seconds
const conversationMode = changeToDisappearingConversationMode(
ourConversation,
expirationType,
expireTimer
);
expect(conversationMode, 'returns deleteAfterRead').to.be.eq('deleteAfterRead');
});
it("if it's a Private Conversation and expirationType is deleteAfterSend and expireTimer > 0 then the conversation mode stays as deleteAfterSend", async () => {
const ourConversation = new ConversationModel({
...conversationArgs,
} as any);
const expirationType = 'deleteAfterSend';
const expireTimer = 60; // seconds
const conversationMode = changeToDisappearingConversationMode(
ourConversation,
expirationType,
expireTimer
);
expect(conversationMode, 'returns deleteAfterSend').to.be.eq('deleteAfterSend');
});
it('if the type is unknown and expireTimer = 0 then the conversation mode is off', async () => {
const conversation = new ConversationModel({ ...conversationArgs } as any);
const expirationType: DisappearingMessageType = 'unknown';
const expireTimer = 0; // seconds
const conversationMode = changeToDisappearingConversationMode(
conversation,
expirationType,
expireTimer
);
expect(conversationMode, 'returns off').to.be.eq('off');
});
it('if the type is undefined and expireTimer = 0 then the conversation mode is off', async () => {
const conversation = new ConversationModel({ ...conversationArgs } as any);
const expireTimer = 0; // seconds
const conversationMode = changeToDisappearingConversationMode(
conversation,
undefined,
expireTimer
);
expect(conversationMode, 'returns off').to.be.eq('off');
});
it('if the type and expireTimer are undefined then the conversation mode is off', async () => {
const conversation = new ConversationModel({ ...conversationArgs } as any);
const conversationMode = changeToDisappearingConversationMode(conversation);
expect(conversationMode, 'returns off').to.be.eq('off');
});
// TODO legacy messages support will be removed in a future release
it('if the type is unknown and expireTimer > 0 then the conversation mode is legacy', async () => {
const conversation = new ConversationModel({ ...conversationArgs } as any);
const expirationType: DisappearingMessageType = 'unknown';
const expireTimer = 60; // seconds
const conversationMode = changeToDisappearingConversationMode(
conversation,
expirationType,
expireTimer
);
expect(conversationMode, 'returns legacy').to.be.eq('legacy');
});
it('if the type is undefined and expireTimer > 0 then the conversation mode is legacy', async () => {
const conversation = new ConversationModel({ ...conversationArgs } as any);
const expireTimer = 60; // seconds
const conversationMode = changeToDisappearingConversationMode(
conversation,
undefined,
expireTimer
);
expect(conversationMode, 'returns legacy').to.be.eq('legacy');
});
});
it('changeToDisappearingConversationMode', async () => {
expect('TODO').to.be.eq('TODO');
describe('changeToDisappearingConversationMode', () => {
it('TODO', async () => {
expect('TODO').to.be.eq('TODO');
});
});
it('checkForExpireUpdateInContentMessage', async () => {
expect('TODO').to.be.eq('TODO');
describe('checkForExpireUpdateInContentMessage', () => {
it('TODO', async () => {
expect('TODO').to.be.eq('TODO');
});
});
});

@ -318,7 +318,7 @@ export function isLegacyDisappearingModeEnabled(
// TODO legacy messages support will be removed in a future release
/**
* Converts DisappearingMessageConversationType to DisappearingMessageType
* Converts DisappearingMessageConversationModeType to DisappearingMessageType
*
* NOTE Used for sending or receiving data messages (protobuf)
*
@ -349,13 +349,13 @@ export function changeToDisappearingMessageType(
// TODO legacy messages support will be removed in a future release
/**
* Converts DisappearingMessageType to DisappearingMessageConversationType
* Converts DisappearingMessageType to DisappearingMessageConversationModeType
*
* NOTE Used for the UI
*
* @param convo Conversation we want to set
* @param expirationType DisappearingMessageType
* @param expireTimer
* @param expireTimer in seconds, 0 means no expiration
* @returns
*/
export function changeToDisappearingConversationMode(

Loading…
Cancel
Save