Skip to content

Commit

Permalink
chore: test number conversion to string in as
Browse files Browse the repository at this point in the history
  • Loading branch information
jsalaber committed Jul 30, 2024
1 parent fed5e79 commit d9dad5c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
setClientCustomData,
variableForUser as variableForUser_AS,
VariableType,
convertNumberToString,
} from '../bucketingImportHelper'
import testData from '@devcycle/bucketing-test-data/json-data/testData.json'
const { config, barrenConfig, configWithNullCustomData } = testData
Expand Down Expand Up @@ -217,6 +218,22 @@ describe('User Hashing and Bucketing', () => {
})
})

describe('AS Number conversion', () => {
it('converts numbers to strings', () => {
const number = 610
const convertedNumber = convertNumberToString(number)
expect(typeof convertedNumber).toBe('string')
expect(convertedNumber).toBe('610')
})

it('converts floats to strings', () => {
const number = 610.61
const convertedNumber = convertNumberToString(number)
expect(typeof convertedNumber).toBe('string')
expect(convertedNumber).toBe('610.61')
})
})

describe('Config Parsing and Generating', () => {
afterEach(() => cleanupSDK(sdkKey))

Expand Down
4 changes: 4 additions & 0 deletions lib/shared/bucketing-assembly-script/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export function generateBucketedConfigForUser(
return bucketedConfig.stringify()
}

export function convertNumberToString(num: number): string {
return num.toString()
}

export function generateBucketedConfigForUserUTF8(
sdkKey: string,
userJSONStr: Uint8Array,
Expand Down
17 changes: 17 additions & 0 deletions lib/shared/bucketing/__tests__/bucketing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
decideTargetVariation,
generateBucketedConfig,
doesUserPassRollout,
convertNumberToString,
} from '../src/bucketing'
import {
config,
Expand Down Expand Up @@ -99,6 +100,22 @@ describe('User Hashing and Bucketing', () => {
})
})

describe('TypeScript Number conversion', () => {
it('converts numbers to strings', () => {
const number = 610
const convertedNumber = convertNumberToString(number)
expect(typeof convertedNumber).toBe('string')
expect(convertedNumber).toBe('610')
})

it('converts floats to strings', () => {
const number = 610.61
const convertedNumber = convertNumberToString(number)
expect(typeof convertedNumber).toBe('string')
expect(convertedNumber).toBe('610.61')
})
})

describe('Config Parsing and Generating', () => {
it('generates the correctly modified config from the example config', () => {
const user = {
Expand Down
4 changes: 4 additions & 0 deletions lib/shared/bucketing/src/bucketing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ const checkRolloutAndEvaluate = ({
}
}

export const convertNumberToString = (num: number): string => {
return num.toString()
}

export const getSegmentedFeatureDataFromConfig = ({
config,
user,
Expand Down

0 comments on commit d9dad5c

Please sign in to comment.