Skip to content

Commit 411b818

Browse files
committed
tests passing
1 parent 19de7c3 commit 411b818

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/http-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface IUniversalFlagConfigResponse {
4343
}
4444

4545
export interface IBanditParametersResponse {
46+
createdAt: string; // ISO formatted string
4647
bandits: Record<string, BanditParameters>;
4748
}
4849

test/testHelpers.ts

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

33
import { isEqual } from 'lodash';
44

5-
import { AttributeType, ContextAttributes, IAssignmentDetails, Variation, VariationType } from '../src';
5+
import { AttributeType, ContextAttributes, IAssignmentDetails, 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';
98

109
export const TEST_DATA_DIR = './test/data/ufc/';
1110
export const ASSIGNMENT_TEST_DATA_DIR = TEST_DATA_DIR + 'tests/';
@@ -114,6 +113,9 @@ export function getTestAssignments(
114113
return assignments;
115114
}
116115

116+
const configCreatedAt = readMockUFCResponse(MOCK_UFC_RESPONSE_FILE).createdAt;
117+
const testHelperInstantiationDate = new Date();
118+
117119
export function validateTestAssignments(
118120
assignments: {
119121
subject: SubjectTestCase;
@@ -168,15 +170,18 @@ export function validateTestAssignments(
168170
expect(assignmentDetails.variationValue?.toString()).toBe(
169171
subject.evaluationDetails.variationValue?.toString(),
170172
);
171-
// TODO: below needs to be fixed
172-
//expect(assignmentDetails.configFetchedAt).toBe(subject.evaluationDetails.configFetchedAt);
173-
//expect(assignmentDetails.configPublishedAt).toBe(subject.evaluationDetails.configPublishedAt);
173+
expect(assignmentDetails.configPublishedAt).toBe(configCreatedAt);
174+
// cannot do an exact match for configFetchedAt because it will change based on fetch
175+
expect(new Date(assignmentDetails.configFetchedAt).getTime()).toBeGreaterThan(
176+
testHelperInstantiationDate.getTime(),
177+
);
174178

175179
if (!isObfuscated) {
176180
expect(assignmentDetails.matchedRule).toEqual(subject.evaluationDetails.matchedRule);
177181
} else {
178182
// 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
183+
// Thus we'll just check that the number of conditions is equal and relay on the unobfuscated
184+
// tests for correctness
180185
expect(assignmentDetails.matchedRule?.conditions || []).toHaveLength(
181186
subject.evaluationDetails.matchedRule?.conditions.length || 0,
182187
);

0 commit comments

Comments
 (0)