2021-04-08 19:27:20 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
import { arePinnedConversationsEqual } from '../../util/arePinnedConversationsEqual';
|
2021-07-13 18:54:53 +00:00
|
|
|
import { SignalService as Proto } from '../../protobuf';
|
|
|
|
|
|
|
|
import PinnedConversation = Proto.AccountRecord.IPinnedConversation;
|
2021-04-08 19:27:20 +00:00
|
|
|
|
|
|
|
describe('arePinnedConversationsEqual', () => {
|
|
|
|
it('is equal if both have same values at same indices', () => {
|
|
|
|
const localValue = [
|
|
|
|
{
|
|
|
|
contact: {
|
|
|
|
uuid: '72313cde-2784-4a6f-a92a-abbe23763a60',
|
|
|
|
e164: '+13055551234',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-07-13 18:54:53 +00:00
|
|
|
groupMasterKey: new Uint8Array(32),
|
2021-04-08 19:27:20 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
const remoteValue = [
|
|
|
|
{
|
|
|
|
contact: {
|
|
|
|
uuid: '72313cde-2784-4a6f-a92a-abbe23763a60',
|
|
|
|
e164: '+13055551234',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-07-13 18:54:53 +00:00
|
|
|
groupMasterKey: new Uint8Array(32),
|
2021-04-08 19:27:20 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
assert.isTrue(arePinnedConversationsEqual(localValue, remoteValue));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is not equal if values are mixed', () => {
|
|
|
|
const localValue = [
|
|
|
|
{
|
|
|
|
contact: {
|
|
|
|
uuid: '72313cde-2784-4a6f-a92a-abbe23763a60',
|
|
|
|
e164: '+13055551234',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
contact: {
|
|
|
|
uuid: 'f59a9fed-9e91-4bb4-a015-d49e58b47e25',
|
|
|
|
e164: '+17865554321',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const remoteValue = [
|
|
|
|
{
|
|
|
|
contact: {
|
|
|
|
uuid: 'f59a9fed-9e91-4bb4-a015-d49e58b47e25',
|
|
|
|
e164: '+17865554321',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
contact: {
|
|
|
|
uuid: '72313cde-2784-4a6f-a92a-abbe23763a60',
|
|
|
|
e164: '+13055551234',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
assert.isFalse(arePinnedConversationsEqual(localValue, remoteValue));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is not equal if lengths are not same', () => {
|
|
|
|
const localValue = [
|
|
|
|
{
|
|
|
|
contact: {
|
|
|
|
uuid: '72313cde-2784-4a6f-a92a-abbe23763a60',
|
|
|
|
e164: '+13055551234',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
2021-07-13 18:54:53 +00:00
|
|
|
const remoteValue: Array<PinnedConversation> = [];
|
2021-04-08 19:27:20 +00:00
|
|
|
assert.isFalse(arePinnedConversationsEqual(localValue, remoteValue));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is not equal if content does not match', () => {
|
|
|
|
const localValue = [
|
|
|
|
{
|
|
|
|
contact: {
|
|
|
|
uuid: '72313cde-2784-4a6f-a92a-abbe23763a60',
|
|
|
|
e164: '+13055551234',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const remoteValue = [
|
|
|
|
{
|
2021-07-13 18:54:53 +00:00
|
|
|
groupMasterKey: new Uint8Array(32),
|
2021-04-08 19:27:20 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
assert.isFalse(arePinnedConversationsEqual(localValue, remoteValue));
|
|
|
|
});
|
|
|
|
});
|