test: finished setExpirationStartTimestamp tests

pull/2971/head
William Grant 2 years ago
parent 3a930eb323
commit a9d1abbfff

@ -6,12 +6,14 @@ import {
setExpirationStartTimestamp,
} from '../../../../util/expiringMessages';
import { isValidUnixTimestamp } from '../../../../session/utils/Timestamps';
import { GetNetworkTime } from '../../../../session/apis/snode_api/getNetworkTime';
describe('Disappearing Messages', () => {
stubWindowLog();
const getLatestTimestampOffset = 200000;
beforeEach(() => {
// TODO Stubbing
Sinon.stub(GetNetworkTime, 'getLatestTimestampOffset').returns(getLatestTimestampOffset);
});
afterEach(() => {
@ -30,7 +32,6 @@ describe('Disappearing Messages', () => {
'it should be a valid unix timestamp'
).to.be.true;
});
it('returns a valid unix timestamp for deleteAfterSend', async () => {
const mode: DisappearingMessageConversationModeType = 'deleteAfterSend';
const expirationStartTimestamp = setExpirationStartTimestamp(mode);
@ -41,19 +42,49 @@ describe('Disappearing Messages', () => {
'it should be a valid unix timestamp'
).to.be.true;
});
it('returns undefined when disappearing messages is off', async () => {
const mode: DisappearingMessageConversationModeType = 'off';
const expirationStartTimestamp = setExpirationStartTimestamp(mode);
expect(expirationStartTimestamp, 'it should return undefined').to.be.undefined;
});
it('if we give it a timestamp it returns the older timestamp for deleteAfterRead', async () => {
const mode: DisappearingMessageConversationModeType = 'deleteAfterRead';
const timestamp = new Date().valueOf();
const expirationStartTimestamp = setExpirationStartTimestamp(mode, timestamp);
expect(expirationStartTimestamp, 'it should return a number').to.be.is.a('number');
expect(
isValidUnixTimestamp(expirationStartTimestamp!),
'it should be a valid unix timestamp'
).to.be.true;
expect(
expirationStartTimestamp,
'expirationStartTimestamp should be less than the input timestamp'
).to.be.lessThan(timestamp);
});
it('if we give it a timestamp it returns the older timestamp for deleteAfterSend', async () => {
const mode: DisappearingMessageConversationModeType = 'deleteAfterSend';
const timestamp = new Date().valueOf();
const expirationStartTimestamp = setExpirationStartTimestamp(mode, timestamp);
// TODO Test with timestamp argument
// Timestamp is bigger
// Timestamp is smaller
// Timestamp is the equal
// Timestamp is invalid
expect(expirationStartTimestamp, 'it should return a number').to.be.is.a('number');
expect(
isValidUnixTimestamp(expirationStartTimestamp!),
'it should be a valid unix timestamp'
).to.be.true;
expect(
expirationStartTimestamp,
'expirationStartTimestamp should be less than the input timestamp'
).to.be.lessThan(timestamp);
});
it('if we give it an invalid timestamp it returns undefined', async () => {
const mode: DisappearingMessageConversationModeType = 'deleteAfterSend';
const timestamp = -1;
const expirationStartTimestamp = setExpirationStartTimestamp(mode, timestamp);
expect(expirationStartTimestamp, 'it should return undefined').to.be.undefined;
});
});
it('changeToDisappearingMessageType', async () => {

@ -13,6 +13,7 @@ import { MessageModel } from '../models/message';
import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime';
import { ReleasedFeatures } from './releaseFeature';
import { expireMessageOnSnode } from '../session/apis/snode_api/expireRequest';
import { isValidUnixTimestamp } from '../session/utils/Timestamps';
// NOTE this must match Content.ExpirationType in the protobuf
// TODO double check this
@ -255,6 +256,12 @@ export function setExpirationStartTimestamp(
// TODO legacy messages support will be removed in a future release
if (timestamp) {
if (!isValidUnixTimestamp(timestamp)) {
window.log.debug(
`WIP: [setExpirationStartTimestamp] We compared 2 timestamps for a disappearing message (${mode}) and the argument timestamp is invalid`
);
return undefined;
}
window.log.debug(
`WIP: [setExpirationStartTimestamp] We compare 2 timestamps for a disappearing message (${mode}):\nexpirationStartTimestamp `,
new Date(expirationStartTimestamp).toLocaleTimeString(),
@ -277,7 +284,6 @@ export function setExpirationStartTimestamp(
expirationStartTimestamp
).toLocaleTimeString()}`
);
// TODO needs improvement
} else if (mode === 'legacy') {
window.log.debug(
`WIP: [setExpirationStartTimestamp] We set the start timestamp for a legacy message to ${new Date(

Loading…
Cancel
Save