Skip to content

Commit

Permalink
fix: the clientSDKKey field currently errors when you try and test th… (
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotCamblor authored May 15, 2024
1 parent 8955721 commit 24b3b24
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ describe.each([true, false])('Config Body', (utf8) => {
)
})

it('should parse if missing optional top level field', () => {
const config = cloneDeep(testData.config)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete config.clientSDKKey
expect(testConfigBody(JSON.stringify(config), utf8)).toEqual(
JSON.parse(
JSON.stringify({
...testData.config,
project: {
...testData.config.project,
settings: {
disablePassthroughRollouts: false
}
},
variableHashes: undefined,
clientSDKKey: undefined,
}),
),
)
})
it('should throw if target.rollout is missing type', () => {
const config = cloneDeep(testData.config)
const target: any = config.features[0].configuration.targets[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class Settings extends JSON.Value {
this.disablePassthroughRollouts = false
}
}

stringify(): string {
const json = new JSON.Obj()
json.set('disablePassthroughRollouts', this.disablePassthroughRollouts)
Expand Down Expand Up @@ -143,9 +142,8 @@ export class ConfigBody {
this.etag = etag
this.clientSDKKey = getStringFromJSONOptional(
configJSONObj,
'clientSDKKey',
'clientSDKKey'
)

this.project = new PublicProject(
getJSONObjFromJSON(configJSONObj, 'project'),
)
Expand Down Expand Up @@ -232,7 +230,9 @@ export class ConfigBody {
json.set('audiences', jsonObjFromMap(this.audiences))
json.set('features', jsonArrFromValueArray(this.features))
json.set('variables', jsonArrFromValueArray(this.variables))
json.set('clientSDKKey', this.clientSDKKey)
if (this.clientSDKKey) {
json.set('clientSDKKey', this.clientSDKKey)
}
return json.stringify()
}

Expand Down
1 change: 0 additions & 1 deletion lib/shared/bucketing-test-data/src/data/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ export const barrenConfig: ConfigBody = {
],
variables: [],
variableHashes: {},
clientSDKKey: 'test',
}

export const configWithNullCustomData: ConfigBody = {
Expand Down

0 comments on commit 24b3b24

Please sign in to comment.