-
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
4 changed files
with
59 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ dist/ | |
# caches | ||
.cache | ||
.DS_Store | ||
|
||
.idea |
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
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 |
---|---|---|
@@ -1,34 +1,44 @@ | ||
import { ExperimentClient } from 'src/client'; | ||
import { ExperimentUser } from 'src/types/user'; | ||
|
||
const API_KEY = 'client-DvWljIjiiuqLbyjqdvBaLFfEBrAvGuA3'; | ||
const API_KEY = 'server-qz35UwzJ5akieoAdIgzM4m9MIiOLXLoz'; | ||
|
||
const testUser: ExperimentUser = { user_id: 'test_user' }; | ||
|
||
const testClient: ExperimentClient = new ExperimentClient(API_KEY, {}); | ||
|
||
const testTimeoutNoRetriesClient = new ExperimentClient(API_KEY, { | ||
fetchRetries: 0, | ||
fetchTimeoutMillis: 1, | ||
}); | ||
|
||
const testTimeoutRetrySuccessClient = new ExperimentClient(API_KEY, { | ||
fetchTimeoutMillis: 1, | ||
}); | ||
|
||
test('ExperimentClient.fetch, success', async () => { | ||
const variants = await testClient.fetch(testUser); | ||
const client = new ExperimentClient(API_KEY, {}); | ||
const variants = await client.fetch(testUser); | ||
const variant = variants['sdk-ci-test']; | ||
expect(variant).toEqual({ value: 'on', payload: 'payload' }); | ||
}); | ||
|
||
test('ExperimentClient.fetch, no retries, timeout failure', async () => { | ||
const variants = await testTimeoutNoRetriesClient.fetch(testUser); | ||
const client = new ExperimentClient(API_KEY, { | ||
fetchRetries: 0, | ||
fetchTimeoutMillis: 1, | ||
}); | ||
const variants = await client.fetch(testUser); | ||
expect(variants).toEqual({}); | ||
}); | ||
|
||
test('ExperimentClient.fetch, no retries, timeout failure', async () => { | ||
const variants = await testTimeoutRetrySuccessClient.fetch(testUser); | ||
const client = new ExperimentClient(API_KEY, { | ||
fetchTimeoutMillis: 1, | ||
}); | ||
const variants = await client.fetch(testUser); | ||
const variant = variants['sdk-ci-test']; | ||
expect(variant).toEqual({ value: 'on', payload: 'payload' }); | ||
}); | ||
|
||
test('ExperimentClient.fetch, retry once, timeout first then succeed with 0 backoff', async () => { | ||
const client = new ExperimentClient(API_KEY, { | ||
debug: true, | ||
fetchTimeoutMillis: 1, | ||
fetchRetries: 1, | ||
fetchRetryBackoffMinMillis: 0, | ||
fetchRetryTimeoutMillis: 10_000, | ||
}); | ||
const variants = await client.fetch(testUser); | ||
const variant = variants['sdk-ci-test']; | ||
expect(variant).toEqual({ value: 'on', payload: 'payload' }); | ||
}); |