Don't ring large groups

This commit is contained in:
Evan Hahn 2021-09-02 17:34:38 -05:00 committed by GitHub
parent 1f45bce0a2
commit 3e18a8a337
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 144 additions and 44 deletions

View file

@ -0,0 +1,61 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import * as sinon from 'sinon';
import { times } from 'lodash';
import { v4 as uuid } from 'uuid';
import * as remoteConfig from '../../RemoteConfig';
import { isConversationTooBigToRing } from '../../conversations/isConversationTooBigToRing';
describe('isConversationTooBigToRing', () => {
let sinonSandbox: sinon.SinonSandbox;
let getMaxGroupCallRingSizeStub: sinon.SinonStub;
beforeEach(() => {
sinonSandbox = sinon.createSandbox();
const getValueStub = sinonSandbox.stub(remoteConfig, 'getValue');
getMaxGroupCallRingSizeStub = getValueStub.withArgs(
'global.calling.maxGroupCallRingSize'
);
});
const fakeMemberships = (count: number) =>
times(count, () => ({ conversationId: uuid(), isAdmin: false }));
afterEach(() => {
sinonSandbox.restore();
});
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 }));
}
};
it('returns whether there are 16 or more people in the group, if there is nothing in remote config', () => {
textMaximum(16);
});
it('returns whether there are 16 or more people in the group, if the remote config value is bogus', () => {
getMaxGroupCallRingSizeStub.returns('uh oh');
textMaximum(16);
});
it('returns whether there are 9 or more people in the group, if the remote config value is 9', () => {
getMaxGroupCallRingSizeStub.returns('9');
textMaximum(9);
});
});

View file

@ -8,14 +8,12 @@ import * as remoteConfig from '../../RemoteConfig';
import {
getGroupSizeRecommendedLimit,
getGroupSizeHardLimit,
getMaxGroupCallRingSize,
} from '../../groups/limits';
describe('group limit utilities', () => {
let sinonSandbox: sinon.SinonSandbox;
let getRecommendedLimitStub: sinon.SinonStub;
let getHardLimitStub: sinon.SinonStub;
let getMaxGroupCallRingSizeStub: sinon.SinonStub;
beforeEach(() => {
sinonSandbox = sinon.createSandbox();
@ -27,9 +25,6 @@ describe('group limit utilities', () => {
getHardLimitStub = getValueStub.withArgs(
'global.groupsv2.groupSizeHardLimit'
);
getMaxGroupCallRingSizeStub = getValueStub.withArgs(
'global.calling.maxGroupCallRingSize'
);
});
afterEach(() => {
@ -69,21 +64,4 @@ describe('group limit utilities', () => {
assert.strictEqual(getGroupSizeHardLimit(), 123);
});
});
describe('getMaxGroupCallRingSize', () => {
it('returns 16 if the value in remote config is not defined', () => {
getMaxGroupCallRingSizeStub.returns(undefined);
assert.strictEqual(getMaxGroupCallRingSize(), 16);
});
it('returns 16 if the value in remote config is not a parseable integer', () => {
getMaxGroupCallRingSizeStub.returns('uh oh');
assert.strictEqual(getMaxGroupCallRingSize(), 16);
});
it('returns the value in remote config, parsed as an integer', () => {
getMaxGroupCallRingSizeStub.returns('123');
assert.strictEqual(getMaxGroupCallRingSize(), 123);
});
});
});