Skip to content

Commit 3e1cd78

Browse files
authored
Consolidate getAssignmentsWithSubjectAttributes and getAssignments into one function (#22)
* Consolidate getAssignmentsWithSubjectAttributes and getAssignments into one function * Delete unused getAssignments function
1 parent 92fddca commit 3e1cd78

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

src/client/eppo-client.spec.ts

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,13 @@ describe('EppoClient E2E test', () => {
246246
}: IAssignmentTestCase) => {
247247
`---- Test Case for ${experiment} Experiment ----`;
248248

249-
const assignments = subjectsWithAttributes
250-
? getAssignmentsWithSubjectAttributes(subjectsWithAttributes, experiment, valueType)
251-
: getAssignments(subjects, experiment, valueType);
249+
const assignments = getAssignmentsWithSubjectAttributes(
250+
subjectsWithAttributes
251+
? subjectsWithAttributes
252+
: subjects.map((subject) => ({ subjectKey: subject })),
253+
experiment,
254+
valueType,
255+
);
252256

253257
switch (valueType) {
254258
case ValueTestType.BoolType: {
@@ -391,43 +395,11 @@ describe('EppoClient E2E test', () => {
391395
expect(assignment).toEqual('control');
392396
});
393397

394-
function getAssignments(
395-
subjects: string[],
396-
experiment: string,
397-
valueTestType: ValueTestType = ValueTestType.StringType,
398-
): (EppoValue | null)[] {
399-
return subjects.map((subjectKey) => {
400-
switch (valueTestType) {
401-
case ValueTestType.BoolType: {
402-
const ba = globalClient.getBoolAssignment(subjectKey, experiment);
403-
if (ba === null) return null;
404-
return EppoValue.Bool(ba);
405-
}
406-
case ValueTestType.NumericType: {
407-
const na = globalClient.getNumericAssignment(subjectKey, experiment);
408-
if (na === null) return null;
409-
return EppoValue.Numeric(na);
410-
}
411-
case ValueTestType.StringType: {
412-
const sa = globalClient.getStringAssignment(subjectKey, experiment);
413-
if (sa === null) return null;
414-
return EppoValue.String(sa);
415-
}
416-
case ValueTestType.JSONType: {
417-
const sa = globalClient.getJSONStringAssignment(subjectKey, experiment);
418-
const oa = globalClient.getParsedJSONAssignment(subjectKey, experiment);
419-
if (oa == null || sa === null) return null;
420-
return EppoValue.JSON(sa, oa);
421-
}
422-
}
423-
});
424-
}
425-
426398
function getAssignmentsWithSubjectAttributes(
427399
subjectsWithAttributes: {
428400
subjectKey: string;
429401
// eslint-disable-next-line @typescript-eslint/no-explicit-any
430-
subjectAttributes: Record<string, any>;
402+
subjectAttributes?: Record<string, any>;
431403
}[],
432404
experiment: string,
433405
valueTestType: ValueTestType = ValueTestType.StringType,

0 commit comments

Comments
 (0)