Skip to content

Commit 3bb7387

Browse files
authored
Consolidate getAssignmentsWithSubjectAttributes and getAssignments into one function (#29)
* Consolidate getAssignmentsWithSubjectAttributes and getAssignments into one function * Delete unused getAssignments function
1 parent 1c4e87f commit 3bb7387

File tree

1 file changed

+9
-36
lines changed

1 file changed

+9
-36
lines changed

src/index.spec.ts

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,14 @@ describe('EppoJSClient E2E test', () => {
215215
expectedAssignments,
216216
}: IAssignmentTestCase) => {
217217
console.log(`---- Test Case for ${experiment} Experiment ----`);
218-
const assignments = subjectsWithAttributes
219-
? getAssignmentsWithSubjectAttributes(subjectsWithAttributes, experiment, valueType)
220-
: getAssignments(subjects, experiment, valueType);
218+
219+
const assignments = getAssignmentsWithSubjectAttributes(
220+
subjectsWithAttributes
221+
? subjectsWithAttributes
222+
: subjects.map((subject) => ({ subjectKey: subject })),
223+
experiment,
224+
valueType,
225+
);
221226

222227
switch (valueType) {
223228
case ValueTestType.BoolType: {
@@ -249,43 +254,11 @@ describe('EppoJSClient E2E test', () => {
249254
});
250255
});
251256

252-
function getAssignments(
253-
subjects: string[],
254-
experiment: string,
255-
valueTestType: ValueTestType = ValueTestType.StringType,
256-
): (EppoValue | null)[] {
257-
return subjects.map((subjectKey) => {
258-
switch (valueTestType) {
259-
case ValueTestType.BoolType: {
260-
const ba = globalClient.getBoolAssignment(subjectKey, experiment);
261-
if (ba === null) return null;
262-
return EppoValue.Bool(ba);
263-
}
264-
case ValueTestType.NumericType: {
265-
const na = globalClient.getNumericAssignment(subjectKey, experiment);
266-
if (na === null) return null;
267-
return EppoValue.Numeric(na);
268-
}
269-
case ValueTestType.StringType: {
270-
const sa = globalClient.getStringAssignment(subjectKey, experiment);
271-
if (sa === null) return null;
272-
return EppoValue.String(sa);
273-
}
274-
case ValueTestType.JSONType: {
275-
const sa = globalClient.getJSONStringAssignment(subjectKey, experiment);
276-
const oa = globalClient.getParsedJSONAssignment(subjectKey, experiment);
277-
if (oa == null || sa === null) return null;
278-
return EppoValue.JSON(sa, oa);
279-
}
280-
}
281-
});
282-
}
283-
284257
function getAssignmentsWithSubjectAttributes(
285258
subjectsWithAttributes: {
286259
subjectKey: string;
287260
// eslint-disable-next-line @typescript-eslint/no-explicit-any
288-
subjectAttributes: Record<string, any>;
261+
subjectAttributes?: Record<string, any>;
289262
}[],
290263
experiment: string,
291264
valueTestType: ValueTestType = ValueTestType.StringType,

0 commit comments

Comments
 (0)