Use esbuild

This commit is contained in:
Fedor Indutny 2022-02-11 13:38:52 -08:00 committed by GitHub
parent 3c1ccce9bd
commit 0174687542
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 528 additions and 906 deletions

View file

@ -1,34 +1,19 @@
// Copyright 2021 Signal Messenger, LLC
// Copyright 2021-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import * as sinon from 'sinon';
import { times } from 'lodash';
import * as remoteConfig from '../../RemoteConfig';
import { updateRemoteConfig } from '../helpers/RemoteConfigStub';
import { UUID } from '../../types/UUID';
import { isConversationTooBigToRing } from '../../conversations/isConversationTooBigToRing';
const CONFIG_KEY = 'global.calling.maxGroupCallRingSize';
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, () => ({ uuid: UUID.generate().toString(), 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: [] }));
@ -45,17 +30,20 @@ describe('isConversationTooBigToRing', () => {
}
};
it('returns whether there are 16 or more people in the group, if there is nothing in remote config', () => {
it('returns whether there are 16 or more people in the group, if there is nothing in remote config', async () => {
await updateRemoteConfig([]);
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');
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 },
]);
textMaximum(16);
});
it('returns whether there are 9 or more people in the group, if the remote config value is 9', () => {
getMaxGroupCallRingSizeStub.returns('9');
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 }]);
textMaximum(9);
});
});

View file

@ -1,66 +1,56 @@
// Copyright 2021 Signal Messenger, LLC
// Copyright 2021-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import * as sinon from 'sinon';
import * as remoteConfig from '../../RemoteConfig';
import { updateRemoteConfig } from '../helpers/RemoteConfigStub';
import {
getGroupSizeRecommendedLimit,
getGroupSizeHardLimit,
} from '../../groups/limits';
const RECOMMENDED_SIZE_KEY = 'global.groupsv2.maxGroupSize';
const HARD_LIMIT_KEY = 'global.groupsv2.groupSizeHardLimit';
describe('group limit utilities', () => {
let sinonSandbox: sinon.SinonSandbox;
let getRecommendedLimitStub: sinon.SinonStub;
let getHardLimitStub: sinon.SinonStub;
beforeEach(() => {
sinonSandbox = sinon.createSandbox();
const getValueStub = sinonSandbox.stub(remoteConfig, 'getValue');
getRecommendedLimitStub = getValueStub.withArgs(
'global.groupsv2.maxGroupSize'
);
getHardLimitStub = getValueStub.withArgs(
'global.groupsv2.groupSizeHardLimit'
);
});
afterEach(() => {
sinonSandbox.restore();
});
describe('getGroupSizeRecommendedLimit', () => {
it('throws if the value in remote config is not defined', () => {
getRecommendedLimitStub.returns(undefined);
it('throws if the value in remote config is not defined', async () => {
await updateRemoteConfig([]);
assert.throws(getGroupSizeRecommendedLimit);
});
it('throws if the value in remote config is not a parseable integer', () => {
getRecommendedLimitStub.returns('uh oh');
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 },
]);
assert.throws(getGroupSizeRecommendedLimit);
});
it('returns the value in remote config, parsed as an integer', () => {
getRecommendedLimitStub.returns('123');
it('returns the value in remote config, parsed as an integer', async () => {
await updateRemoteConfig([
{ name: RECOMMENDED_SIZE_KEY, value: '123', enabled: true },
]);
assert.strictEqual(getGroupSizeRecommendedLimit(), 123);
});
});
describe('getGroupSizeHardLimit', () => {
it('throws if the value in remote config is not defined', () => {
getHardLimitStub.returns(undefined);
it('throws if the value in remote config is not defined', async () => {
await updateRemoteConfig([]);
assert.throws(getGroupSizeHardLimit);
});
it('throws if the value in remote config is not a parseable integer', () => {
getHardLimitStub.returns('uh oh');
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 },
]);
assert.throws(getGroupSizeHardLimit);
});
it('returns the value in remote config, parsed as an integer', () => {
getHardLimitStub.returns('123');
it('returns the value in remote config, parsed as an integer', async () => {
await updateRemoteConfig([
{ name: HARD_LIMIT_KEY, value: '123', enabled: true },
]);
assert.strictEqual(getGroupSizeHardLimit(), 123);
});
});

View file

@ -0,0 +1,18 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { refreshRemoteConfig } from '../../RemoteConfig';
import type { WebAPIType } from '../../textsecure/WebAPI';
import type { UnwrapPromise } from '../../types/Util';
export async function updateRemoteConfig(
newConfig: UnwrapPromise<ReturnType<WebAPIType['getConfig']>>
): Promise<void> {
const fakeServer = {
async getConfig() {
return newConfig;
},
} as Partial<WebAPIType> as unknown as WebAPIType;
await refreshRemoteConfig(fakeServer);
}