Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit d4ab468

Browse files
authored
Flags with a version of 0 reported as 'unknown' in summary events. (#239)
1 parent 2d86ee7 commit d4ab468

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

event_processor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function EventProcessor(sdkKey, config, errorReporter, diagnosticsManager) {
7676
if (event.variation !== undefined && event.variation !== null) {
7777
out.variation = event.variation;
7878
}
79-
if (event.version) {
79+
if (event.version !== undefined && event.version !== null) {
8080
out.version = event.version;
8181
}
8282
if (event.reason) {

event_summarizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function EventSummarizer() {
5353
if (c.variation !== undefined && c.variation !== null) {
5454
counterOut.variation = c.variation;
5555
}
56-
if (c.version) {
56+
if (c.version !== undefined && c.version !== null) {
5757
counterOut.version = c.version;
5858
} else {
5959
counterOut.unknown = true;

test/event_processor-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,21 @@ describe('EventProcessor', () => {
182182
});
183183
}));
184184

185+
it('handles the version being 0', eventsServerTest(async s => {
186+
await withEventProcessor(defaultConfig, s, async ep => {
187+
const e = { kind: 'feature', creationDate: 1000, user: user, key: 'flagkey',
188+
version: 0, variation: 1, value: 'value', trackEvents: true };
189+
ep.sendEvent(e);
190+
await ep.flush();
191+
192+
const output = await getJsonRequest(s);
193+
expect(output.length).toEqual(3);
194+
checkIndexEvent(output[0], e, user);
195+
checkFeatureEvent(output[1], e, false);
196+
checkSummaryEvent(output[2]);
197+
});
198+
}));
199+
185200
it('queues individual feature event with index event for anonymous user', eventsServerTest(async s => {
186201
await withEventProcessor(defaultConfig, s, async ep => {
187202
const e = { kind: 'feature', creationDate: 1000, user: anonUser, key: 'flagkey',

test/event_summarizer-test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,24 @@ describe('EventSummarizer', function() {
4444
variation: 1, value: 100, default: 111 };
4545
var event5 = { kind: 'feature', creationDate: 1000, key: 'badkey', user: user,
4646
value: 333, default: 333 };
47+
var event6 = { kind: 'feature', creationDate: 1000, key: 'zero-version', version: 0, user: user,
48+
variation: 1, value: 100, default: 444 };
4749
es.summarizeEvent(event1);
4850
es.summarizeEvent(event2);
4951
es.summarizeEvent(event3);
5052
es.summarizeEvent(event4);
5153
es.summarizeEvent(event5);
54+
es.summarizeEvent(event6);
5255
var data = es.getSummary();
5356

5457
data.features.key1.counters.sort(function(a, b) { return a.value - b.value; });
5558
var expectedFeatures = {
59+
'zero-version': {
60+
default: 444,
61+
counters: [
62+
{ variation: 1, value: 100, version: 0, count: 1}
63+
]
64+
},
5665
key1: {
5766
default: 111,
5867
counters: [
@@ -67,7 +76,7 @@ describe('EventSummarizer', function() {
6776
badkey: {
6877
default: 333,
6978
counters: [ { value: 333, unknown: true, count: 1 }]
70-
}
79+
},
7180
};
7281
expect(data.features).toEqual(expectedFeatures);
7382
});

0 commit comments

Comments
 (0)