Skip to content

Commit 19de7c3

Browse files
committed
handle looking at obfuscated rules for details
1 parent 570984c commit 19de7c3

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

src/client/eppo-client.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ describe('EppoClient E2E test', () => {
386386
assignmentFn,
387387
);
388388

389-
validateTestAssignments(assignments, flag, assignmentWithDetails);
389+
validateTestAssignments(assignments, flag, assignmentWithDetails, isObfuscated);
390390
});
391391
});
392392
});

src/evaluator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ export class Evaluator {
144144
configDetails.configFormat,
145145
);
146146
} catch (err: any) {
147-
console.error('>>>>', err);
148147
const flagEvaluationDetails = flagEvaluationDetailsBuilder.gracefulBuild(
149148
'ASSIGNMENT_ERROR',
150149
`Assignment Error: ${err.message}`,

test/testHelpers.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isEqual } from 'lodash';
55
import { AttributeType, ContextAttributes, IAssignmentDetails, Variation, VariationType } from '../src';
66
import { IFlagEvaluationDetails } from '../src/flag-evaluation-details-builder';
77
import { IBanditParametersResponse, IUniversalFlagConfigResponse } from '../src/http-client';
8+
import { getMD5Hash } from '../src/obfuscation';
89

910
export const TEST_DATA_DIR = './test/data/ufc/';
1011
export const ASSIGNMENT_TEST_DATA_DIR = TEST_DATA_DIR + 'tests/';
@@ -113,29 +114,6 @@ export function getTestAssignments(
113114
return assignments;
114115
}
115116

116-
export function getTestAssignmentDetails(
117-
testCase: IAssignmentTestCase,
118-
assignmentDetailsFn: (
119-
flagKey: string,
120-
subjectKey: string,
121-
subjectAttributes: Record<string, AttributeType>,
122-
defaultValue: string | number | boolean | object,
123-
) => never,
124-
): {
125-
subject: SubjectTestCase;
126-
assignmentDetails: IAssignmentDetails<string | boolean | number | object>;
127-
}[] {
128-
return testCase.subjects.map((subject) => ({
129-
subject,
130-
assignmentDetails: assignmentDetailsFn(
131-
testCase.flag,
132-
subject.subjectKey,
133-
subject.subjectAttributes,
134-
testCase.defaultValue,
135-
),
136-
}));
137-
}
138-
139117
export function validateTestAssignments(
140118
assignments: {
141119
subject: SubjectTestCase;
@@ -149,6 +127,7 @@ export function validateTestAssignments(
149127
}[],
150128
flag: string,
151129
withDetails: boolean,
130+
isObfuscated: boolean,
152131
) {
153132
for (const { subject, assignment } of assignments) {
154133
let assignedVariation = assignment;
@@ -192,7 +171,17 @@ export function validateTestAssignments(
192171
// TODO: below needs to be fixed
193172
//expect(assignmentDetails.configFetchedAt).toBe(subject.evaluationDetails.configFetchedAt);
194173
//expect(assignmentDetails.configPublishedAt).toBe(subject.evaluationDetails.configPublishedAt);
195-
expect(assignmentDetails.matchedRule).toEqual(subject.evaluationDetails.matchedRule);
174+
175+
if (!isObfuscated) {
176+
expect(assignmentDetails.matchedRule).toEqual(subject.evaluationDetails.matchedRule);
177+
} else {
178+
// When obfuscated, rules may be one-way hashed (e.g., for ONE_OF checks) so cannot be unobfuscated
179+
// Thus we'll just check that the number of conditions is equal
180+
expect(assignmentDetails.matchedRule?.conditions || []).toHaveLength(
181+
subject.evaluationDetails.matchedRule?.conditions.length || 0,
182+
);
183+
}
184+
196185
expect(assignmentDetails.matchedAllocation).toEqual(
197186
subject.evaluationDetails.matchedAllocation,
198187
);

0 commit comments

Comments
 (0)