2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-09-02 22:34:38 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
import { times } from 'lodash';
|
2022-02-11 21:38:52 +00:00
|
|
|
import { updateRemoteConfig } from '../helpers/RemoteConfigStub';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { generateAci } from '../../types/ServiceId';
|
2021-09-02 22:34:38 +00:00
|
|
|
|
|
|
|
import { isConversationTooBigToRing } from '../../conversations/isConversationTooBigToRing';
|
|
|
|
|
2022-02-11 21:38:52 +00:00
|
|
|
const CONFIG_KEY = 'global.calling.maxGroupCallRingSize';
|
2021-09-02 22:34:38 +00:00
|
|
|
|
2022-02-11 21:38:52 +00:00
|
|
|
describe('isConversationTooBigToRing', () => {
|
2021-09-02 22:34:38 +00:00
|
|
|
const fakeMemberships = (count: number) =>
|
2023-08-16 20:54:39 +00:00
|
|
|
times(count, () => ({ aci: generateAci(), isAdmin: false }));
|
2021-09-02 22:34:38 +00:00
|
|
|
|
|
|
|
it('returns false if there are no memberships (i.e., for a direct conversation)', () => {
|
|
|
|
assert.isFalse(isConversationTooBigToRing({}));
|
|
|
|
assert.isFalse(isConversationTooBigToRing({ memberships: [] }));
|
|
|
|
});
|
|
|
|
|
|
|
|
const textMaximum = (max: number): void => {
|
|
|
|
for (let count = 1; count < max; count += 1) {
|
|
|
|
const memberships = fakeMemberships(count);
|
|
|
|
assert.isFalse(isConversationTooBigToRing({ memberships }));
|
|
|
|
}
|
|
|
|
for (let count = max; count < max + 5; count += 1) {
|
|
|
|
const memberships = fakeMemberships(count);
|
|
|
|
assert.isTrue(isConversationTooBigToRing({ memberships }));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-11 21:38:52 +00:00
|
|
|
it('returns whether there are 16 or more people in the group, if there is nothing in remote config', async () => {
|
|
|
|
await updateRemoteConfig([]);
|
2021-09-02 22:34:38 +00:00
|
|
|
textMaximum(16);
|
|
|
|
});
|
|
|
|
|
2022-02-11 21:38:52 +00:00
|
|
|
it('returns whether there are 16 or more people in the group, if the remote config value is bogus', async () => {
|
|
|
|
await updateRemoteConfig([
|
|
|
|
{ name: CONFIG_KEY, value: 'uh oh', enabled: true },
|
|
|
|
]);
|
2021-09-02 22:34:38 +00:00
|
|
|
textMaximum(16);
|
|
|
|
});
|
|
|
|
|
2022-02-11 21:38:52 +00:00
|
|
|
it('returns whether there are 9 or more people in the group, if the remote config value is 9', async () => {
|
|
|
|
await updateRemoteConfig([{ name: CONFIG_KEY, value: '9', enabled: true }]);
|
2021-09-02 22:34:38 +00:00
|
|
|
textMaximum(9);
|
|
|
|
});
|
|
|
|
});
|