-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |