Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { ConfigBody } from '@devcycle/types'
import {
initialize,
VariableType,
initEventQueue,
setPlatformData,
setConfigData,
Expand All @@ -18,6 +17,7 @@ import {
} from '../__tests__/bucketingImportHelper'
import largeTestData from '@devcycle/bucketing-test-data/json-data/largeConfig.json'
import testData from '@devcycle/bucketing-test-data/json-data/testData.json'
import { VariableType_PB } from '../protobuf/compiled'
const { config } = testData

const largeConfig = largeTestData.largeConfig as unknown as ConfigBody
Expand Down Expand Up @@ -64,63 +64,63 @@ benchmarkSuite('variableForUser', {
const variable = variableForUser({
user,
variableKey: 'feature4Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
})
if (!variable) throw new Error('variable should not be defaulted')
},
['variableForUser_PB']: () => {
const variable = variableForUser_PB({
user,
variableKey: 'feature4Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
})
if (!variable) throw new Error('variable should not be defaulted')
},
['variableForUser - large user']: () => {
const variable = variableForUser({
user: largeUser,
variableKey: 'feature4Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
})
if (!variable) throw new Error('variable should not be defaulted')
},
['variableForUser_PB - large user']: () => {
const variable = variableForUser_PB({
user: largeUser,
variableKey: 'feature4Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
})
if (!variable) throw new Error('variable should not be defaulted')
},
['variableForUser - defaulted']: () => {
const variable = variableForUser({
user: defaultUser,
variableKey: 'feature4Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
})
if (variable) throw new Error('variable should be defaulted')
},
['variableForUser_PB - defaulted']: () => {
const variable = variableForUser_PB({
user: defaultUser,
variableKey: 'feature4Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
})
if (variable) throw new Error('variable should be defaulted')
},
['variableForUser - unknown key']: () => {
const variable = variableForUser({
user: defaultUser,
variableKey: 'unknown key',
variableType: VariableType.String,
variableType: VariableType_PB.String,
})
if (variable) throw new Error('variable should be defaulted')
},
['variableForUser_PB - unknown key']: () => {
const variable = variableForUser_PB({
user: defaultUser,
variableKey: 'unknown key',
variableType: VariableType.String,
variableType: VariableType_PB.String,
})
if (variable) throw new Error('variable should be defaulted')
},
Expand All @@ -131,7 +131,7 @@ benchmarkSuite('variableForUser - Large Config', {
console.log('setup variableForUser - Large Config tests')
await initialize(true)
// @ts-ignore
initSDK('sdkKey', largeConfig)
initSDK('sdkKey', 'clientUUID_large', largeConfig)
},
teardownSuite() {
cleanupSDK()
Expand All @@ -140,15 +140,15 @@ benchmarkSuite('variableForUser - Large Config', {
const variable = variableForUser({
user: largeConfigUser,
variableKey: 'v-key-50',
variableType: VariableType.Boolean,
variableType: VariableType_PB.Boolean,
})
if (!variable) throw new Error('variable should not be defaulted')
},
['variableForUser_PB']: () => {
const variable = variableForUser_PB({
user: largeConfigUser,
variableKey: 'v-key-50',
variableType: VariableType.Boolean,
variableType: VariableType_PB.Boolean,
})
if (!variable) throw new Error('variable should not be defaulted')
},
Expand Down Expand Up @@ -176,7 +176,7 @@ benchmarkSuite('generateBucketedConfigForUser - Large Config', {
console.log('setup generateBucketedConfigForUser - Large Config tests')
await initialize(true)
// @ts-ignore
initSDK('sdkKey', largeConfig)
initSDK('sdkKey', 'clientUUID_large_2', largeConfig)
},
teardownSuite() {
cleanupSDK()
Expand All @@ -202,7 +202,7 @@ benchmarkSuite('initEventQueue', {
cleanupSDK()
},
['initEventQueue']: () => {
initEventQueue('sdkKey_' + i, JSON.stringify({}))
initEventQueue('sdkKey_' + i, 'clientUUID_' + i, JSON.stringify({}))
i++
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
setPlatformData,
setClientCustomData,
variableForUser as variableForUser_AS,
VariableType,
} from '../bucketingImportHelper'
import testData from '@devcycle/bucketing-test-data/json-data/testData.json'
const { config, barrenConfig, configWithNullCustomData } = testData
Expand All @@ -21,6 +20,7 @@ import {
variableForUserPB,
VariableForUserArgs,
} from '../protobufVariableHelper'
import { VariableType_PB } from '../../protobuf/compiled'

type BoundedHash = { rolloutHash: number; bucketingHash: number }

Expand Down Expand Up @@ -88,7 +88,11 @@ const testGenerateBucketingConfigWithOverrides = (
}

const expectVariableForUser = (
args: { user: any; variableKey: string; variableType: VariableType },
args: {
user: any
variableKey: string
variableType: VariableType_PB
},
expectedValue: unknown,
) => {
const variable = variableForUser({ ...args, sdkKey })
Expand Down Expand Up @@ -305,7 +309,7 @@ describe('Config Parsing and Generating', () => {
{
user,
variableKey: 'swagTest',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables.swagTest,
)
Expand Down Expand Up @@ -482,36 +486,36 @@ describe('Config Parsing and Generating', () => {
{
user,
variableKey: 'audience-match',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables['audience-match'],
)
expectVariableForUser(
{
user,
variableKey: 'feature2.cool',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables['feature2.cool'],
)
expectVariableForUser(
{
user,
variableKey: 'feature2.hello',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables['feature2.hello'],
)
expectVariableForUser(
{
user,
variableKey: 'swagTest',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables['swagTest'],
)
expectVariableForUser(
{ user, variableKey: 'test', variableType: VariableType.String },
{ user, variableKey: 'test', variableType: VariableType_PB.String },
expected.variables['test'],
)
})
Expand Down Expand Up @@ -581,16 +585,20 @@ describe('Config Parsing and Generating', () => {
},
},
}
console.log(`new config: ${JSON.stringify(newConfig)}`)
initSDK(sdkKey, newConfig)

console.log(`user: ${JSON.stringify(user)}`)
const c = generateBucketedConfig(user)
console.log(`bucketed config: ${JSON.stringify(c)}`)
console.log(`expected: ${JSON.stringify(expected)}`)
expect(c).toEqual(expected)

expectVariableForUser(
{
user,
variableKey: 'feature2Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables['feature2Var'],
)
Expand Down Expand Up @@ -719,7 +727,7 @@ describe('Config Parsing and Generating', () => {
{
user,
variableKey: 'feature2Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables['feature2Var'],
)
Expand Down Expand Up @@ -859,7 +867,7 @@ describe('Config Parsing and Generating', () => {
{
user,
variableKey: 'feature2Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables['feature2Var'],
)
Expand Down Expand Up @@ -975,15 +983,15 @@ describe('Config Parsing and Generating', () => {
{
user,
variableKey: 'swagTest',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables['swagTest'],
)
expectVariableForUser(
{
user,
variableKey: 'feature2Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables['feature2Var'],
)
Expand All @@ -1004,7 +1012,7 @@ describe('Config Parsing and Generating', () => {
{
user,
variableKey: 'feature2Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
null,
)
Expand Down Expand Up @@ -1036,7 +1044,7 @@ describe('Config Parsing and Generating', () => {
{
user,
variableKey: 'feature2Var',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
null,
)
Expand All @@ -1057,7 +1065,7 @@ describe('Config Parsing and Generating', () => {
{
user,
variableKey: 'feature2.cool',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
null,
)
Expand Down Expand Up @@ -1129,7 +1137,7 @@ describe('Config Parsing and Generating', () => {
{
user,
variableKey: 'audience-match',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
null,
)
Expand Down Expand Up @@ -1201,7 +1209,7 @@ describe('Config Parsing and Generating', () => {
{
user,
variableKey: 'audience-match',
variableType: VariableType.String,
variableType: VariableType_PB.String,
},
expected.variables['audience-match'],
)
Expand Down
Loading
Loading