Skip to content

Commit e8e983e

Browse files
committed
assignment value type
1 parent d8ed352 commit e8e983e

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

src/client/eppo-client-assignment-details.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'fs';
22

33
import {
4+
AssignmentVariationValue,
45
IAssignmentTestCase,
56
MOCK_UFC_RESPONSE_FILE,
67
readMockUFCResponse,
@@ -328,8 +329,8 @@ describe('EppoClient get*AssignmentDetails', () => {
328329
flagKey: string,
329330
subjectKey: string,
330331
subjectAttributes: Record<string, AttributeType>,
331-
defaultValue: boolean | string | number | object,
332-
) => IAssignmentDetails<boolean | string | number | object>;
332+
defaultValue: AssignmentVariationValue,
333+
) => IAssignmentDetails<AssignmentVariationValue>;
333334
if (!assignmentFn) {
334335
throw new Error(`Unknown variation type: ${variationType}`);
335336
}

src/client/eppo-client.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as td from 'testdouble';
44

55
import {
66
ASSIGNMENT_TEST_DATA_DIR,
7+
AssignmentVariationValue,
78
getTestAssignments,
89
IAssignmentTestCase,
910
MOCK_UFC_RESPONSE_FILE,
@@ -28,7 +29,11 @@ import { Flag, ObfuscatedFlag, VariationType, FormatEnum, Variation } from '../i
2829
import { getMD5Hash } from '../obfuscation';
2930
import { AttributeType } from '../types';
3031

31-
import EppoClient, { checkTypeMatch, FlagConfigurationRequestParameters } from './eppo-client';
32+
import EppoClient, {
33+
checkTypeMatch,
34+
FlagConfigurationRequestParameters,
35+
IAssignmentDetails,
36+
} from './eppo-client';
3237
import { initConfiguration } from './test-utils';
3338

3439
// Use a known salt to produce deterministic hashes
@@ -352,7 +357,7 @@ describe('EppoClient E2E test', () => {
352357

353358
let assignments: {
354359
subject: SubjectTestCase;
355-
assignment: string | boolean | number | null | object;
360+
assignment: AssignmentVariationValue;
356361
}[] = [];
357362

358363
const typeAssignmentFunctions = assignmentWithDetails
@@ -375,8 +380,8 @@ describe('EppoClient E2E test', () => {
375380
flagKey: string,
376381
subjectKey: string,
377382
subjectAttributes: Record<string, AttributeType>,
378-
defaultValue: boolean | string | number | object,
379-
) => never;
383+
defaultValue: AssignmentVariationValue,
384+
) => AssignmentVariationValue | IAssignmentDetails<AssignmentVariationValue>;
380385
if (!assignmentFn) {
381386
throw new Error(`Unknown variation type: ${variationType}`);
382387
}

test/testHelpers.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import * as fs from 'fs';
22

33
import { isEqual } from 'lodash';
44

5-
import { AttributeType, ContextAttributes, IAssignmentDetails, VariationType } from '../src';
5+
import {
6+
AttributeType,
7+
ContextAttributes,
8+
IAssignmentDetails,
9+
Variation,
10+
VariationType,
11+
} from '../src';
612
import { IFlagEvaluationDetails } from '../src/flag-evaluation-details-builder';
713
import { IBanditParametersResponse, IUniversalFlagConfigResponse } from '../src/http-client';
814

@@ -20,17 +26,19 @@ const MOCK_PRECOMPUTED_FILENAME = 'precomputed-v1';
2026
export const MOCK_PRECOMPUTED_WIRE_FILE = `${MOCK_PRECOMPUTED_FILENAME}.json`;
2127
export const MOCK_DEOBFUSCATED_PRECOMPUTED_RESPONSE_FILE = `${MOCK_PRECOMPUTED_FILENAME}-deobfuscated.json`;
2228

29+
export type AssignmentVariationValue = Variation['value'] | object;
30+
2331
export interface SubjectTestCase {
2432
subjectKey: string;
2533
subjectAttributes: Record<string, AttributeType>;
26-
assignment: string | number | boolean | object;
34+
assignment: AssignmentVariationValue;
2735
evaluationDetails: IFlagEvaluationDetails;
2836
}
2937

3038
export interface IAssignmentTestCase {
3139
flag: string;
3240
variationType: VariationType;
33-
defaultValue: string | number | boolean | object;
41+
defaultValue: AssignmentVariationValue;
3442
subjects: SubjectTestCase[];
3543
}
3644

@@ -85,21 +93,15 @@ export function getTestAssignments(
8593
flagKey: string,
8694
subjectKey: string,
8795
subjectAttributes: Record<string, AttributeType>,
88-
defaultValue: string | number | boolean | object,
89-
) => never,
96+
defaultValue: AssignmentVariationValue,
97+
) => AssignmentVariationValue | IAssignmentDetails<AssignmentVariationValue>,
9098
): {
9199
subject: SubjectTestCase;
92-
assignment:
93-
| string
94-
| boolean
95-
| number
96-
| null
97-
| object
98-
| IAssignmentDetails<typeof testCase.defaultValue>;
100+
assignment: AssignmentVariationValue | IAssignmentDetails<AssignmentVariationValue>;
99101
}[] {
100102
const assignments: {
101103
subject: SubjectTestCase;
102-
assignment: string | boolean | number | null | object;
104+
assignment: AssignmentVariationValue;
103105
}[] = [];
104106
for (const subject of testCase.subjects) {
105107
const assignment = assignmentFn(
@@ -121,13 +123,7 @@ const testHelperInstantiationDate = new Date();
121123
export function validateTestAssignments(
122124
assignments: {
123125
subject: SubjectTestCase;
124-
assignment:
125-
| string
126-
| boolean
127-
| number
128-
| object
129-
| null
130-
| IAssignmentDetails<string | boolean | number | object>;
126+
assignment: AssignmentVariationValue | IAssignmentDetails<AssignmentVariationValue>;
131127
}[],
132128
flag: string,
133129
withDetails: boolean,

0 commit comments

Comments
 (0)