-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
0ba9617
commit d2e5a2f
Showing
67 changed files
with
6,386 additions
and
308 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
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,9 +1,26 @@ | ||
export default { | ||
failFast: true, | ||
failWithoutAssertions: false, | ||
babel: { | ||
testOptions: { | ||
babelrc: false, | ||
configFile: false, | ||
}, | ||
}, | ||
files: ['__test/**/__tests__/*.js'], | ||
files: [ | ||
'__test/**/__tests__/**/*.js', | ||
'!__test/**/__tests__/utils/**', | ||
'!__test/**/__tests__/testdata/**', | ||
'!__test/**/__tests__/mocks/**', | ||
], | ||
"typescript": { | ||
"extensions": [ | ||
"ts", | ||
"tsx" | ||
], | ||
"rewritePaths": { | ||
"src/": "build/" | ||
}, | ||
"compile": "tsc" | ||
} | ||
}; |
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
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,108 @@ | ||
import anyTest, { TestFn } from 'ava'; | ||
import { Bucketeer, DefaultLogger, User, initialize } from '../lib'; | ||
import { HOST, FEATURE_TAG, TARGETED_SEGMENT_USER_ID, FEATURE_ID_BOOLEAN, FEATURE_ID_STRING, FEATURE_ID_INT, FEATURE_ID_JSON, FEATURE_ID_FLOAT, TOKEN } from './constants/constants'; | ||
|
||
const test = anyTest as TestFn<{ bktClient: Bucketeer; targetedSegmentUser: User }>; | ||
|
||
test.before( async (t) => { | ||
t.context = { | ||
bktClient: initialize({ | ||
host: HOST, | ||
token: TOKEN, | ||
tag: FEATURE_TAG, | ||
logger: new DefaultLogger('error'), | ||
enableLocalEvaluation: false, | ||
cachePollingInterval: 3000, | ||
}), | ||
targetedSegmentUser: { id: TARGETED_SEGMENT_USER_ID, data: {} }, | ||
}; | ||
}); | ||
|
||
test.after(async (t) => { | ||
const { bktClient } = t.context; | ||
bktClient.destroy(); | ||
}); | ||
|
||
test('boolVariation', async (t) => { | ||
const { bktClient, targetedSegmentUser } = t.context; | ||
t.is(await bktClient.booleanVariation(targetedSegmentUser, FEATURE_ID_BOOLEAN, false), true); | ||
t.deepEqual( | ||
await bktClient.booleanVariationDetails(targetedSegmentUser, FEATURE_ID_BOOLEAN, false), | ||
{ | ||
featureId: FEATURE_ID_BOOLEAN, | ||
featureVersion: 5, | ||
userId: targetedSegmentUser.id, | ||
variationId: 'f948b6dd-c366-4828-8ee0-72edbe2c0eea', | ||
variationName: 'variation 1', | ||
variationValue: true, | ||
reason: 'DEFAULT', | ||
} | ||
) | ||
}); | ||
|
||
test('stringVariation', async (t) => { | ||
const { bktClient, targetedSegmentUser } = t.context; | ||
t.is(await bktClient.stringVariation(targetedSegmentUser, FEATURE_ID_STRING, ''), 'value-3'); | ||
t.deepEqual( | ||
await bktClient.stringVariationDetails(targetedSegmentUser, FEATURE_ID_STRING, 'true'), | ||
{ | ||
featureId: FEATURE_ID_STRING, | ||
featureVersion: 22, | ||
userId: targetedSegmentUser.id, | ||
variationId: 'e92fa326-2c7a-45f2-aaf7-ab9eb59f0ccf', | ||
variationName: 'variation 3', | ||
variationValue: 'value-3', | ||
reason: 'RULE', | ||
} | ||
) | ||
}); | ||
|
||
test('numberVariation', async (t) => { | ||
const { bktClient, targetedSegmentUser } = t.context; | ||
t.is(await bktClient.numberVariation(targetedSegmentUser, FEATURE_ID_INT, 0), 10); | ||
t.deepEqual( | ||
await bktClient.numberVariationDetails(targetedSegmentUser, FEATURE_ID_INT, 1), | ||
{ | ||
featureId: FEATURE_ID_INT, | ||
featureVersion: 5, | ||
userId: targetedSegmentUser.id, | ||
variationId: '935ac588-c3ef-4bc8-915b-666369cdcada', | ||
variationName: 'variation 1', | ||
variationValue: 10, | ||
reason: 'DEFAULT', | ||
} | ||
) | ||
|
||
t.is(await bktClient.numberVariation(targetedSegmentUser, FEATURE_ID_FLOAT, 0.0), 2.1); | ||
t.deepEqual( | ||
await bktClient.numberVariationDetails(targetedSegmentUser, FEATURE_ID_FLOAT, 1.1), | ||
{ | ||
featureId: FEATURE_ID_FLOAT, | ||
featureVersion: 5, | ||
userId: targetedSegmentUser.id, | ||
variationId: '0b04a309-31cd-471f-acf0-0ea662d16737', | ||
variationName: 'variation 1', | ||
variationValue: 2.1, | ||
reason: 'DEFAULT', | ||
} | ||
) | ||
|
||
}); | ||
|
||
test('objectVariation', async (t) => { | ||
const { bktClient, targetedSegmentUser } = t.context; | ||
t.deepEqual(await bktClient.getJsonVariation(targetedSegmentUser, FEATURE_ID_JSON, {}), { "str": "str1", "int": "int1" }); | ||
t.deepEqual(await bktClient.objectVariation(targetedSegmentUser, FEATURE_ID_JSON, {}), { "str": "str1", "int": "int1" }); | ||
t.deepEqual( | ||
await bktClient.objectVariationDetails(targetedSegmentUser, FEATURE_ID_JSON, {}), | ||
{ | ||
featureId: FEATURE_ID_JSON, | ||
featureVersion: 5, | ||
userId: targetedSegmentUser.id, | ||
variationId: 'ff8299ed-80c9-4d30-9e92-a55750ad3ffb', | ||
variationName: 'variation 1', | ||
variationValue: { str: 'str1', int: 'int1' }, | ||
reason: 'DEFAULT', | ||
} | ||
) | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import test from 'ava' | ||
import { initialize, DefaultLogger } from '../../lib'; | ||
import { HOST, TOKEN, FEATURE_TAG, TARGETED_USER_ID, FEATURE_ID_BOOLEAN, SERVER_ROLE_TOKEN } from '../constants/constants'; | ||
import { isMetricsEvent } from '../../lib/objects/metricsEvent'; | ||
import { BKTClientImpl } from '../../lib/client'; | ||
|
||
test('Using a random string in the api key setting should not throw exception', async (t) => { | ||
const bktClient = initialize({ | ||
host: HOST, | ||
token: "TOKEN_RANDOM", | ||
tag: FEATURE_TAG, | ||
cachePollingInterval: 1000, | ||
enableLocalEvaluation: true, | ||
logger: new DefaultLogger("error") | ||
}); | ||
|
||
await new Promise((resolve) => { | ||
setTimeout(resolve, 3000); | ||
}); | ||
|
||
const user = { id: TARGETED_USER_ID, data: {} } | ||
// The client can not load the evaluation, we will received the default value `true` | ||
// Other SDK clients e2e test will expect the value is `false` | ||
const result = await t.notThrowsAsync(bktClient.booleanVariation(user, FEATURE_ID_BOOLEAN, true)); | ||
t.true(result); | ||
|
||
const bktClientImpl = bktClient as BKTClientImpl | ||
const events = bktClientImpl.eventStore.getAll() | ||
t.true(events.some((e) => { | ||
return isMetricsEvent(e.event); | ||
})); | ||
|
||
bktClient.destroy() | ||
}); | ||
|
||
test('altering featureTag should not affect api request', async (t) => { | ||
const config = { | ||
host: HOST, | ||
token: SERVER_ROLE_TOKEN, | ||
tag: FEATURE_TAG, | ||
cachePollingInterval: 1000, | ||
enableLocalEvaluation: true, | ||
logger: new DefaultLogger("error") | ||
} | ||
|
||
const bktClient = initialize(config); | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, 3000); | ||
}); | ||
|
||
const user = { id: TARGETED_USER_ID, data: {} } | ||
const result = await t.notThrowsAsync(bktClient.booleanVariation(user, FEATURE_ID_BOOLEAN, false)); | ||
t.true(result); | ||
config.tag = "RANDOME" | ||
|
||
const resultAfterAlterAPIKey = await t.notThrowsAsync(bktClient.booleanVariation(user, FEATURE_ID_BOOLEAN, false)); | ||
t.true(resultAfterAlterAPIKey); | ||
|
||
bktClient.destroy() | ||
}); | ||
|
||
test('Altering the api key should not affect api request', async (t) => { | ||
const config = { | ||
host: HOST, | ||
token: SERVER_ROLE_TOKEN, | ||
tag: FEATURE_TAG, | ||
cachePollingInterval: 1000, | ||
enableLocalEvaluation: true, | ||
logger: new DefaultLogger("error") | ||
} | ||
|
||
const bktClient = initialize(config); | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, 3000); | ||
}); | ||
|
||
const user = { id: TARGETED_USER_ID, data: {} } | ||
const result = await t.notThrowsAsync(bktClient.booleanVariation(user, FEATURE_ID_BOOLEAN, false)); | ||
t.true(result); | ||
config.token = "RANDOME" | ||
|
||
const resultAfterAlterAPIKey = await t.notThrowsAsync(bktClient.booleanVariation(user, FEATURE_ID_BOOLEAN, false)); | ||
t.true(resultAfterAlterAPIKey); | ||
|
||
bktClient.destroy() | ||
}); | ||
|
||
//Note: There is a different compared to other SDK clients. | ||
test('Using a random string in the featureTag setting should affect api request', async (t) => { | ||
const bktClient = initialize({ | ||
host: HOST, | ||
token: SERVER_ROLE_TOKEN, | ||
tag: "RANDOM", | ||
cachePollingInterval: 1000, | ||
enableLocalEvaluation: true, | ||
logger: new DefaultLogger("error") | ||
}); | ||
|
||
await new Promise((resolve) => { | ||
setTimeout(resolve, 3000); | ||
}); | ||
|
||
const user = { id: TARGETED_USER_ID, data: {} } | ||
const result = await t.notThrowsAsync(bktClient.booleanVariation(user, FEATURE_ID_BOOLEAN, true)); | ||
// The client can not load the evaluation, we will received the default value `true` | ||
// Other SDK clients e2e test will expect the value is `false` | ||
t.true(result); | ||
|
||
const bktClientImpl = bktClient as BKTClientImpl | ||
const events = bktClientImpl.eventStore.getAll() | ||
t.true(events.some((e) => { | ||
return isMetricsEvent(e.event); | ||
})); | ||
|
||
bktClient.destroy() | ||
}); |
Oops, something went wrong.