2022-10-20 21:02:22 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
|
2023-09-14 17:04:48 +00:00
|
|
|
import { normalizeAci } from '../util/normalizeAci';
|
2022-10-20 21:02:22 +00:00
|
|
|
import {
|
|
|
|
getCountryCodeValue,
|
|
|
|
getBucketValue,
|
|
|
|
innerIsBucketValueEnabled,
|
|
|
|
} from '../RemoteConfig';
|
|
|
|
|
|
|
|
describe('RemoteConfig', () => {
|
2023-12-07 23:59:54 +00:00
|
|
|
const aci = normalizeAci('95b9729c-51ea-4ddb-b516-652befe78062', 'test');
|
2022-10-20 21:02:22 +00:00
|
|
|
|
|
|
|
describe('#innerIsBucketValueEnabled', () => {
|
2023-12-07 23:59:54 +00:00
|
|
|
// Note: bucketValue is 627610 for 'desktop.pnp' key
|
2022-10-20 21:02:22 +00:00
|
|
|
|
|
|
|
it('returns true for 100% wildcard', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
innerIsBucketValueEnabled(
|
2023-12-07 23:59:54 +00:00
|
|
|
'desktop.pnp',
|
2022-10-20 21:02:22 +00:00
|
|
|
'*:1000000',
|
|
|
|
'+12125550000',
|
2023-08-16 20:54:39 +00:00
|
|
|
aci
|
2022-10-20 21:02:22 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-12-07 23:59:54 +00:00
|
|
|
it('returns true for 70% on country code 1', () => {
|
2022-10-20 21:02:22 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
innerIsBucketValueEnabled(
|
2023-12-07 23:59:54 +00:00
|
|
|
'desktop.pnp',
|
|
|
|
'1:700000',
|
2022-10-20 21:02:22 +00:00
|
|
|
'+12125550000',
|
2023-08-16 20:54:39 +00:00
|
|
|
aci
|
2022-10-20 21:02:22 +00:00
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-12-07 23:59:54 +00:00
|
|
|
it('returns false for 50% on country code 1', () => {
|
2022-10-20 21:02:22 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
innerIsBucketValueEnabled(
|
2023-12-07 23:59:54 +00:00
|
|
|
'desktop.pnp',
|
|
|
|
'1:500000',
|
2022-10-20 21:02:22 +00:00
|
|
|
'+12125550000',
|
2023-08-16 20:54:39 +00:00
|
|
|
aci
|
2022-10-20 21:02:22 +00:00
|
|
|
),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getCountryCodeValue', () => {
|
|
|
|
it('returns undefined for empty value', () => {
|
|
|
|
assert.strictEqual(getCountryCodeValue(1, '', 'flagName'), undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws for malformed flag', () => {
|
|
|
|
assert.throws(
|
|
|
|
() => getCountryCodeValue(1, 'hi:::', 'flagName'),
|
|
|
|
"invalid number ''"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws for non-integer value', () => {
|
|
|
|
assert.throws(
|
|
|
|
() => getCountryCodeValue(1, '1:cd', 'flagName'),
|
|
|
|
"invalid number 'cd'"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns wildcard value if no other codes', () => {
|
|
|
|
assert.strictEqual(getCountryCodeValue(1, '*:56,2:74', 'flagName'), 56);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns value for specific codes, instead of wildcard', () => {
|
|
|
|
assert.strictEqual(getCountryCodeValue(1, '*:56,1:74', 'flagName'), 74);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns undefined if no wildcard or specific value', () => {
|
|
|
|
assert.strictEqual(
|
|
|
|
getCountryCodeValue(1, '2:56,3:74', 'flagName'),
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getBucketValue', () => {
|
|
|
|
it('returns undefined for empty value', () => {
|
|
|
|
const flagName = 'research.megaphone.1';
|
|
|
|
|
2023-12-07 23:59:54 +00:00
|
|
|
assert.strictEqual(getBucketValue(aci, flagName), 222732);
|
2022-10-20 21:02:22 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|