signal-desktop/ts/test-both/groups/limits_test.ts

58 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2021 Signal Messenger, LLC
2021-03-03 20:09:58 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
2022-02-11 21:38:52 +00:00
import { updateRemoteConfig } from '../helpers/RemoteConfigStub';
2021-03-03 20:09:58 +00:00
import {
getGroupSizeRecommendedLimit,
getGroupSizeHardLimit,
} from '../../groups/limits';
2022-02-11 21:38:52 +00:00
const RECOMMENDED_SIZE_KEY = 'global.groupsv2.maxGroupSize';
const HARD_LIMIT_KEY = 'global.groupsv2.groupSizeHardLimit';
2021-03-03 20:09:58 +00:00
2022-02-11 21:38:52 +00:00
describe('group limit utilities', () => {
2021-03-03 20:09:58 +00:00
describe('getGroupSizeRecommendedLimit', () => {
2022-02-11 21:38:52 +00:00
it('throws if the value in remote config is not defined', async () => {
await updateRemoteConfig([]);
2021-03-03 20:09:58 +00:00
assert.throws(getGroupSizeRecommendedLimit);
});
2022-02-11 21:38:52 +00:00
it('throws if the value in remote config is not a parseable integer', async () => {
await updateRemoteConfig([
{ name: RECOMMENDED_SIZE_KEY, value: 'uh oh', enabled: true },
]);
2021-03-03 20:09:58 +00:00
assert.throws(getGroupSizeRecommendedLimit);
});
2022-02-11 21:38:52 +00:00
it('returns the value in remote config, parsed as an integer', async () => {
await updateRemoteConfig([
{ name: RECOMMENDED_SIZE_KEY, value: '123', enabled: true },
]);
2021-03-03 20:09:58 +00:00
assert.strictEqual(getGroupSizeRecommendedLimit(), 123);
});
});
describe('getGroupSizeHardLimit', () => {
2022-02-11 21:38:52 +00:00
it('throws if the value in remote config is not defined', async () => {
await updateRemoteConfig([]);
2021-03-03 20:09:58 +00:00
assert.throws(getGroupSizeHardLimit);
});
2022-02-11 21:38:52 +00:00
it('throws if the value in remote config is not a parseable integer', async () => {
await updateRemoteConfig([
{ name: HARD_LIMIT_KEY, value: 'uh oh', enabled: true },
]);
2021-03-03 20:09:58 +00:00
assert.throws(getGroupSizeHardLimit);
});
2022-02-11 21:38:52 +00:00
it('returns the value in remote config, parsed as an integer', async () => {
await updateRemoteConfig([
{ name: HARD_LIMIT_KEY, value: '123', enabled: true },
]);
2021-03-03 20:09:58 +00:00
assert.strictEqual(getGroupSizeHardLimit(), 123);
});
});
});