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
2 changes: 2 additions & 0 deletions packages/core/test/TestCaseResult.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface TestCase {
value: FlagValue
reason: string
errorCode?: string
serialId?: number | null
doLog?: boolean
variant?: string
flagMetadata?: PrecomputedFlagMetadata
}
Expand Down
16 changes: 14 additions & 2 deletions packages/core/test/evaluation/flags-v1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ describe('Universal Flag Configuration V1', () => {
const ufcJson = fs.readFileSync(path.join(fixtureDirectory, 'ufc-config.json'), 'utf8')
return JSON.parse(ufcJson) as UniversalFlagConfigurationV1
}
// Keep ordered repeated cases on the same prepared configuration.
const configuration = getUFC()

const expectMetadata = (details: ResolutionDetails<FlagValue>, expected: TestCase['result']) => {
if (expected.serialId !== undefined) {
expect(details.flagMetadata?.__dd_split_serial_id ?? null).toBe(expected.serialId)
}
if (expected.doLog !== undefined) {
expect(details.flagMetadata?.__dd_do_log).toBe(expected.doLog)
}
}

const getTestCaseFileNames = (): string[] => {
const fixtureFiles = fs.readdirSync(path.join(fixtureDirectory, 'evaluation-cases')).sort()
Expand All @@ -45,7 +56,6 @@ describe('Universal Flag Configuration V1', () => {
context: EvaluationContext,
immediate: ExperimentationOptOutOption = false
): ResolutionDetails<FlagValue> => {
const configuration = getUFC()
if (testCase.variationType === 'BOOLEAN') {
return evaluateRulesBasedConfiguration(
configuration,
Expand Down Expand Up @@ -94,7 +104,7 @@ describe('Universal Flag Configuration V1', () => {
}

it.each(['constructor', '__proto__'])('treats inherited JSON flag key %s as missing', (flagKey) => {
expect(evaluateRulesBasedConfiguration(getUFC(), 'boolean', flagKey, false, {}, logger)).toMatchObject({
expect(evaluateRulesBasedConfiguration(configuration, 'boolean', flagKey, false, {}, logger)).toMatchObject({
value: false,
reason: 'ERROR',
errorCode: 'FLAG_NOT_FOUND',
Expand All @@ -119,6 +129,7 @@ describe('Universal Flag Configuration V1', () => {
if (testCase.result.errorCode !== undefined || testCase.result.reason !== 'ERROR') {
expect(details.errorCode).toEqual(testCase.result.errorCode)
}
expectMetadata(details, testCase.result)
})

for (const [capability, mode] of [
Expand All @@ -134,6 +145,7 @@ describe('Universal Flag Configuration V1', () => {
expect(details.value).toStrictEqual(expected.value)
expect(details.reason).toEqual(expected.reason)
expect(details.errorCode).toEqual(expected.errorCode)
expectMetadata(details, expected)
})
}
}
Expand Down
25 changes: 20 additions & 5 deletions packages/node-server/test/ffe-system.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type SystemTestCase = {
result: {
value: FlagValue
reason: string
serialId?: number | null
doLog?: boolean
}
}

Expand Down Expand Up @@ -52,10 +54,10 @@ function getTestCases(testCaseFileName: string): SystemTestCase[] {
) as SystemTestCase[]
}

async function evaluateTestCase(testCase: SystemTestCase): Promise<ResolutionDetails<FlagValue>> {
const provider = new DatadogNodeServerProvider({ exposureChannel })
provider.setConfiguration(configuration)

async function evaluateTestCase(
provider: DatadogNodeServerProvider,
testCase: SystemTestCase
): Promise<ResolutionDetails<FlagValue>> {
const context = {
...(testCase.targetingKey === null ? {} : { targetingKey: testCase.targetingKey }),
...testCase.attributes,
Expand All @@ -77,12 +79,25 @@ async function evaluateTestCase(testCase: SystemTestCase): Promise<ResolutionDet
describe('FFE system tests through DatadogNodeServerProvider', () => {
describe.each(getTestCaseFileNames())('should evaluate for %s', (testCaseFileName) => {
const testCases = getTestCases(testCaseFileName)
let provider: DatadogNodeServerProvider

beforeAll(() => {
// Repeated cases must exercise the same provider in fixture order.
provider = new DatadogNodeServerProvider({ exposureChannel })
provider.setConfiguration(configuration)
})

it.each(testCases)('with context $targetingKey and flag $flag', async (testCase) => {
const details = await evaluateTestCase(testCase)
const details = await evaluateTestCase(provider, testCase)

expect(details.value).toEqual(testCase.result.value)
expect(details.reason).toEqual(testCase.result.reason)
if (testCase.result.serialId !== undefined) {
expect(details.flagMetadata?.__dd_split_serial_id ?? null).toBe(testCase.result.serialId)
}
if (testCase.result.doLog !== undefined) {
expect(details.flagMetadata?.__dd_do_log).toBe(testCase.result.doLog)
}
})
})
})
Loading