Skip to content

Commit

Permalink
Update configBody type to include bucketingKey and new comparators
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotCamblor committed Aug 7, 2024
1 parent 0426944 commit 2f83052
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ describe.each([true, false])('Config Body', (utf8) => {
)
})

it('should parse target.bucketingKey exists', () => {
const config = cloneDeep(testData.config)
const target: any = config.features[0].configuration.targets[0]
target.bucketingKey = 'bucketingKey'
expect(testConfigBody(JSON.stringify(config), utf8)).toEqual(
postProcessedConfig(config),
)
})

it('should parse startsWith/endsWith filter', () => {
const config = cloneDeep(testData.config)
const filters =
config.features[0].configuration.targets[0]._audience.filters
filters.filters[0] = {
type: 'user',
comparator: 'startWith',
subType: 'email',
values: [],
} as (typeof filters.filters)[0]
expect(testConfigBody(JSON.stringify(config), utf8)).toEqual(
postProcessedConfig(config),
)
})

it('should handle extended UTF8 characters, from UTF8: ' + utf8, () => {
const testConfig = immutable.set(testData.config, 'project.key', '👍 ö')
expect(testConfigBody(JSON.stringify(testConfig), utf8)).toEqual(
Expand Down
9 changes: 7 additions & 2 deletions lib/shared/bucketing-assembly-script/assembly/types/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Target extends JSON.Value {
readonly _audience: Audience
readonly rollout: Rollout | null
readonly distribution: TargetDistribution[]

readonly bucketingKey: string | null
private readonly _sortedDistribution: TargetDistribution[]

constructor(target: JSON.Obj) {
Expand All @@ -43,6 +43,7 @@ export class Target extends JSON.Value {
value: distribution[i]._variation
})
}
this.bucketingKey = getStringFromJSONOptional(target, 'bucketingKey')
this._sortedDistribution = sortObjectsByString<TargetDistribution>(sortingArray, 'desc')
}

Expand All @@ -69,6 +70,9 @@ export class Target extends JSON.Value {
if (this.rollout) {
json.set('rollout', this.rollout)
}
if (this.bucketingKey) {
json.set('bucketingKey', this.bucketingKey)
}
json.set('distribution', jsonArrFromValueArray(this.distribution))
return json.stringify()
}
Expand Down Expand Up @@ -171,7 +175,8 @@ export const validSubTypes = [
]

const validComparators = [
'=', '!=', '>', '>=', '<', '<=', 'exist', '!exist', 'contain', '!contain'
'=', '!=', '>', '>=', '<', '<=', 'exist', '!exist', 'contain', '!contain',
'startWith', '!startWith', 'endWith', '!endWith'
]

const validAudienceMatchComparators = ['=', '!=']
Expand Down

0 comments on commit 2f83052

Please sign in to comment.