@@ -5,6 +5,7 @@ import { isEqual } from 'lodash';
55import { AttributeType , ContextAttributes , IAssignmentDetails , Variation , VariationType } from '../src' ;
66import { IFlagEvaluationDetails } from '../src/flag-evaluation-details-builder' ;
77import { IBanditParametersResponse , IUniversalFlagConfigResponse } from '../src/http-client' ;
8+ import { getMD5Hash } from '../src/obfuscation' ;
89
910export const TEST_DATA_DIR = './test/data/ufc/' ;
1011export 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-
139117export 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