Skip to content

Commit 6ae8a6f

Browse files
committed
skip tracking if no entityId
1 parent 111bb08 commit 6ae8a6f

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

src/assignment-logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface IAssignmentEvent {
4444
evaluationDetails: IFlagEvaluationDetails | null;
4545

4646
/** * The entity ID of the subject, if present. */
47-
entityId?: number;
47+
entityId?: number | null;
4848
}
4949

5050
/**

src/eppo-assignment-logger.spec.ts

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ describe('EppoAssignmentLogger', () => {
2525
subject: 'user-123',
2626
experiment: 'experiment-abc',
2727
variant: 'control',
28-
entityId: 456, // Changed to number
28+
entityId: 456,
2929
holdoutKey: 'holdout-xyz',
3030
holdoutVariation: 'holdout-variant-1',
31-
// Add required properties based on the IAssignmentEvent interface
3231
allocation: 'allocation-1',
3332
featureFlag: 'feature-flag-1',
3433
variation: 'variation-1',
3534
timestamp: new Date().toISOString(),
3635
subjectAttributes: {},
37-
flagKey: 'flag-key-1',
3836
format: 'json',
3937
evaluationDetails: null,
4038
};
@@ -60,13 +58,12 @@ describe('EppoAssignmentLogger', () => {
6058
subject: 'user-123',
6159
experiment: 'experiment-abc',
6260
variant: 'control',
63-
// Add required properties based on the IAssignmentEvent interface
61+
entityId: 789,
6462
allocation: 'allocation-1',
6563
featureFlag: 'feature-flag-1',
6664
variation: 'variation-1',
6765
timestamp: new Date().toISOString(),
6866
subjectAttributes: {},
69-
flagKey: 'flag-key-1',
7067
format: 'json',
7168
evaluationDetails: null,
7269
};
@@ -80,9 +77,54 @@ describe('EppoAssignmentLogger', () => {
8077
subject_id: 'user-123',
8178
experiment: 'experiment-abc',
8279
variant: 'control',
83-
entity_id: undefined,
80+
entity_id: 789,
8481
holdout: undefined,
8582
holdout_variant: undefined,
8683
});
8784
});
85+
86+
it('should skip tracking when entityId is null', () => {
87+
// Arrange
88+
const assignmentEvent: IAssignmentEvent = {
89+
subject: 'user-123',
90+
experiment: 'experiment-abc',
91+
variant: 'control',
92+
entityId: null,
93+
allocation: 'allocation-1',
94+
featureFlag: 'feature-flag-1',
95+
variation: 'variation-1',
96+
timestamp: new Date().toISOString(),
97+
subjectAttributes: {},
98+
format: 'json',
99+
evaluationDetails: null,
100+
};
101+
102+
// Act
103+
logger.logAssignment(assignmentEvent);
104+
105+
// Assert
106+
expect(mockEppoClient.track).not.toHaveBeenCalled();
107+
});
108+
109+
it('should skip tracking when entityId is undefined', () => {
110+
// Arrange
111+
const assignmentEvent: IAssignmentEvent = {
112+
subject: 'user-123',
113+
experiment: 'experiment-abc',
114+
variant: 'control',
115+
allocation: 'allocation-1',
116+
featureFlag: 'feature-flag-1',
117+
variation: 'variation-1',
118+
timestamp: new Date().toISOString(),
119+
subjectAttributes: {},
120+
format: 'json',
121+
evaluationDetails: null,
122+
};
123+
124+
// Act
125+
logger.logAssignment(assignmentEvent);
126+
127+
// Assert
128+
expect(mockEppoClient.track).not.toHaveBeenCalled();
129+
});
88130
});

src/eppo-assignment-logger.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ export class EppoAssignmentLogger implements IAssignmentLogger {
1212
const {
1313
entityId: entity_id,
1414
experiment,
15+
// holdout and holdout_variant come from `extraLogging` in FlagEvaluation
1516
holdoutKey: holdout,
1617
holdoutVariation: holdout_variant,
1718
subject: subject_id,
1819
variant,
1920
} = event;
21+
22+
// Skip tracking if no entityId
23+
if (!entity_id) {
24+
return;
25+
}
26+
2027
const payload = {
2128
entity_id,
2229
experiment,

0 commit comments

Comments
 (0)