Skip to content

Commit

Permalink
added eu test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhukaihan committed Jun 27, 2024
1 parent c5cce04 commit f23680c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/node/src/local/cohort/poller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class CohortPoller implements CohortUpdater {
}
if (changed) {
this.storage.replaceAll(updatedCohorts);
this.logger.debug('[Experiment] cohort updated');
}

if (onChange && changed) {
Expand Down
70 changes: 70 additions & 0 deletions packages/node/test/local/client.eu.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import path from 'path';

import * as dotenv from 'dotenv';
import { Experiment } from 'src/factory';

dotenv.config({ path: path.join(__dirname, '../../', '.env') });

if (!process.env['API_KEY'] && !process.env['SECRET_KEY']) {
throw new Error(
'No env vars found. If running on local, have you created .env file correct environment variables? Checkout README.md',
);
}

// Simple EU test for connectivity.
const apiKey = 'server-Qlp7XiSu6JtP2S3JzA95PnP27duZgQCF';

const client = Experiment.initializeLocal(apiKey, {
serverZone: 'eu',
cohortConfig: {
apiKey: process.env['EU_API_KEY'],
secretKey: process.env['EU_SECRET_KEY'],
},
});

beforeAll(async () => {
await client.start();
});

afterAll(async () => {
client.stop();
});

test('ExperimentClient.evaluate all flags, success', async () => {
const variants = await client.evaluate({
user_id: 'test_user',
});
const variant = variants['sdk-local-evaluation-userid'];
expect(variant.key).toEqual('on');
expect(variant.value).toEqual('on');
});

// Evaluate V2

test('ExperimentClient.evaluateV2 all flags, success', async () => {
const variants = await client.evaluateV2({
user_id: 'test_user',
});
const variant = variants['sdk-local-evaluation-userid'];
expect(variant.key).toEqual('on');
expect(variant.value).toEqual('on');
});

test('ExperimentClient.evaluateV2 cohort, targeted', async () => {
const variants = await client.evaluateV2({
device_id: '0',
user_id: '1',
});
const variant = variants['sdk-local-evaluation-user-cohort'];
expect(variant.key).toEqual('on');
expect(variant.value).toEqual('on');
});

test('ExperimentClient.evaluateV2 cohort, not targeted', async () => {
const variants = await client.evaluateV2({
user_id: '666',
});
const variant = variants['sdk-local-evaluation-user-cohort'];
expect(variant.key).toEqual('off');
expect(variant.value).toBeUndefined();
});

0 comments on commit f23680c

Please sign in to comment.