Skip to content

Commit e26207b

Browse files
committed
universal tests
1 parent 5d2b695 commit e26207b

File tree

4 files changed

+197
-328
lines changed

4 files changed

+197
-328
lines changed

src/client/eppo-client-with-bandits.spec.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
testCasesByFileName,
88
BanditTestCase,
99
BANDIT_TEST_DATA_DIR,
10+
readMockConfigurationWireResponse,
11+
SHARED_BOOTSTRAP_BANDIT_FLAGS_FILE,
1012
} from '../../test/testHelpers';
1113
import ApiEndpoints from '../api-endpoints';
1214
import { IAssignmentEvent, IAssignmentLogger } from '../assignment-logger';
@@ -19,6 +21,7 @@ import {
1921
IConfigurationWire,
2022
IPrecomputedConfiguration,
2123
IObfuscatedPrecomputedConfigurationResponse,
24+
ConfigurationWireV1,
2225
} from '../configuration-wire/configuration-wire-types';
2326
import { Evaluator, FlagEvaluation } from '../evaluator';
2427
import {
@@ -94,8 +97,8 @@ describe('EppoClient Bandits E2E test', () => {
9497
describe('Shared test cases', () => {
9598
const testCases = testCasesByFileName<BanditTestCase>(BANDIT_TEST_DATA_DIR);
9699

97-
it.each(Object.keys(testCases))('Shared bandit test case - %s', async (fileName: string) => {
98-
const { flag: flagKey, defaultValue, subjects } = testCases[fileName];
100+
function testBanditCaseAgainstClient(client: EppoClient, testCase: BanditTestCase) {
101+
const { flag: flagKey, defaultValue, subjects } = testCase;
99102
let numAssignmentsChecked = 0;
100103
subjects.forEach((subject) => {
101104
// test files have actions as an array, so we convert them to a map as expected by the client
@@ -131,6 +134,35 @@ describe('EppoClient Bandits E2E test', () => {
131134
});
132135
// Ensure that this test case correctly checked some test assignments
133136
expect(numAssignmentsChecked).toBeGreaterThan(0);
137+
}
138+
139+
describe('bootstrapped client', () => {
140+
const banditFlagsConfig = ConfigurationWireV1.fromString(
141+
readMockConfigurationWireResponse(SHARED_BOOTSTRAP_BANDIT_FLAGS_FILE),
142+
);
143+
144+
let client: EppoClient;
145+
beforeAll(async () => {
146+
client = new EppoClient({
147+
flagConfigurationStore: new MemoryOnlyConfigurationStore(),
148+
banditVariationConfigurationStore: new MemoryOnlyConfigurationStore(),
149+
banditModelConfigurationStore: new MemoryOnlyConfigurationStore(),
150+
});
151+
client.setIsGracefulFailureMode(false);
152+
153+
// Bootstrap using the bandit flag config.
154+
await client.bootstrap(banditFlagsConfig);
155+
});
156+
157+
it.each(Object.keys(testCases))('Shared bandit test case - %s', async (fileName: string) => {
158+
testBanditCaseAgainstClient(client, testCases[fileName]);
159+
});
160+
});
161+
162+
describe('traditional client', () => {
163+
it.each(Object.keys(testCases))('Shared bandit test case - %s', async (fileName: string) => {
164+
testBanditCaseAgainstClient(client, testCases[fileName]);
165+
});
134166
});
135167
});
136168

0 commit comments

Comments
 (0)