Handle maxGroupCallRingSize remote config flag

This commit is contained in:
Evan Hahn 2021-08-17 09:01:27 -05:00 committed by GitHub
parent f5a3d4bc8a
commit 502dad8f6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -23,6 +23,7 @@ export type ConfigKeyType =
| 'desktop.sendSenderKey2' | 'desktop.sendSenderKey2'
| 'desktop.storage' | 'desktop.storage'
| 'desktop.storageWrite3' | 'desktop.storageWrite3'
| 'global.calling.maxGroupCallRingSize'
| 'global.groupsv2.groupSizeHardLimit' | 'global.groupsv2.groupSizeHardLimit'
| 'global.groupsv2.maxGroupSize'; | 'global.groupsv2.maxGroupSize';
type ConfigValueType = { type ConfigValueType = {

View file

@ -3,6 +3,7 @@
import { isNumber } from 'lodash'; import { isNumber } from 'lodash';
import { parseIntOrThrow } from '../util/parseIntOrThrow'; import { parseIntOrThrow } from '../util/parseIntOrThrow';
import { parseIntWithFallback } from '../util/parseIntWithFallback';
import { getValue, ConfigKeyType } from '../RemoteConfig'; import { getValue, ConfigKeyType } from '../RemoteConfig';
function makeGetter(configKey: ConfigKeyType): (fallback?: number) => number { function makeGetter(configKey: ConfigKeyType): (fallback?: number) => number {
@ -24,6 +25,10 @@ function makeGetter(configKey: ConfigKeyType): (fallback?: number) => number {
export const getGroupSizeRecommendedLimit = makeGetter( export const getGroupSizeRecommendedLimit = makeGetter(
'global.groupsv2.maxGroupSize' 'global.groupsv2.maxGroupSize'
); );
export const getGroupSizeHardLimit = makeGetter( export const getGroupSizeHardLimit = makeGetter(
'global.groupsv2.groupSizeHardLimit' 'global.groupsv2.groupSizeHardLimit'
); );
export const getMaxGroupCallRingSize = (): number =>
parseIntWithFallback(getValue('global.calling.maxGroupCallRingSize'), 16);

View file

@ -8,12 +8,14 @@ import * as remoteConfig from '../../RemoteConfig';
import { import {
getGroupSizeRecommendedLimit, getGroupSizeRecommendedLimit,
getGroupSizeHardLimit, getGroupSizeHardLimit,
getMaxGroupCallRingSize,
} from '../../groups/limits'; } from '../../groups/limits';
describe('group limit utilities', () => { describe('group limit utilities', () => {
let sinonSandbox: sinon.SinonSandbox; let sinonSandbox: sinon.SinonSandbox;
let getRecommendedLimitStub: sinon.SinonStub; let getRecommendedLimitStub: sinon.SinonStub;
let getHardLimitStub: sinon.SinonStub; let getHardLimitStub: sinon.SinonStub;
let getMaxGroupCallRingSizeStub: sinon.SinonStub;
beforeEach(() => { beforeEach(() => {
sinonSandbox = sinon.createSandbox(); sinonSandbox = sinon.createSandbox();
@ -25,6 +27,9 @@ describe('group limit utilities', () => {
getHardLimitStub = getValueStub.withArgs( getHardLimitStub = getValueStub.withArgs(
'global.groupsv2.groupSizeHardLimit' 'global.groupsv2.groupSizeHardLimit'
); );
getMaxGroupCallRingSizeStub = getValueStub.withArgs(
'global.calling.maxGroupCallRingSize'
);
}); });
afterEach(() => { afterEach(() => {
@ -64,4 +69,21 @@ describe('group limit utilities', () => {
assert.strictEqual(getGroupSizeHardLimit(), 123); 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);
});
});
}); });