2021-05-13 20:57:27 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
2023-08-16 20:54:39 +00:00
|
|
|
import { generateAci } from '../../types/ServiceId';
|
2021-05-13 20:57:27 +00:00
|
|
|
|
|
|
|
import { isConversationSMSOnly } from '../../util/isConversationSMSOnly';
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const serviceId = generateAci();
|
|
|
|
|
2021-05-13 20:57:27 +00:00
|
|
|
describe('isConversationSMSOnly', () => {
|
2021-06-01 20:10:19 +00:00
|
|
|
it('returns false if passed an undefined type', () => {
|
2021-05-13 20:57:27 +00:00
|
|
|
assert.isFalse(
|
2021-06-01 20:10:19 +00:00
|
|
|
isConversationSMSOnly({
|
|
|
|
type: undefined,
|
|
|
|
})
|
2021-05-13 20:57:27 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
['direct', 'private'].forEach(type => {
|
2021-06-01 20:10:19 +00:00
|
|
|
it('returns false if passed an undefined discoveredUnregisteredAt', () => {
|
|
|
|
assert.isFalse(
|
|
|
|
isConversationSMSOnly({ type, discoveredUnregisteredAt: undefined })
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true if passed a very old discoveredUnregisteredAt', () => {
|
|
|
|
assert.isTrue(
|
|
|
|
isConversationSMSOnly({
|
|
|
|
type,
|
|
|
|
e164: 'e164',
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId,
|
2021-06-01 20:10:19 +00:00
|
|
|
discoveredUnregisteredAt: 1,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-05-13 20:57:27 +00:00
|
|
|
it(`returns true if passed a time fewer than 6 hours ago and is ${type}`, () => {
|
|
|
|
assert.isTrue(
|
|
|
|
isConversationSMSOnly({
|
|
|
|
type,
|
|
|
|
e164: 'e164',
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId,
|
2021-05-13 20:57:27 +00:00
|
|
|
discoveredUnregisteredAt: Date.now(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
const fiveHours = 1000 * 60 * 60 * 5;
|
|
|
|
assert.isTrue(
|
|
|
|
isConversationSMSOnly({
|
|
|
|
type,
|
|
|
|
e164: 'e164',
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId,
|
2021-05-13 20:57:27 +00:00
|
|
|
discoveredUnregisteredAt: Date.now() - fiveHours,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`returns true conversation is ${type} and has no uuid`, () => {
|
|
|
|
assert.isTrue(isConversationSMSOnly({ type, e164: 'e164' }));
|
|
|
|
assert.isFalse(isConversationSMSOnly({ type }));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false for groups', () => {
|
|
|
|
assert.isFalse(isConversationSMSOnly({ type: 'group' }));
|
|
|
|
});
|
|
|
|
});
|