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

Commit

Permalink
Flags with a version of 0 reported as 'unknown' in summary events. (#239
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kinyoklion authored Mar 2, 2022
1 parent 2d86ee7 commit d4ab468
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion event_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function EventProcessor(sdkKey, config, errorReporter, diagnosticsManager) {
if (event.variation !== undefined && event.variation !== null) {
out.variation = event.variation;
}
if (event.version) {
if (event.version !== undefined && event.version !== null) {
out.version = event.version;
}
if (event.reason) {
Expand Down
2 changes: 1 addition & 1 deletion event_summarizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function EventSummarizer() {
if (c.variation !== undefined && c.variation !== null) {
counterOut.variation = c.variation;
}
if (c.version) {
if (c.version !== undefined && c.version !== null) {
counterOut.version = c.version;
} else {
counterOut.unknown = true;
Expand Down
15 changes: 15 additions & 0 deletions test/event_processor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ describe('EventProcessor', () => {
});
}));

it('handles the version being 0', eventsServerTest(async s => {
await withEventProcessor(defaultConfig, s, async ep => {
const e = { kind: 'feature', creationDate: 1000, user: user, key: 'flagkey',
version: 0, variation: 1, value: 'value', trackEvents: true };
ep.sendEvent(e);
await ep.flush();

const output = await getJsonRequest(s);
expect(output.length).toEqual(3);
checkIndexEvent(output[0], e, user);
checkFeatureEvent(output[1], e, false);
checkSummaryEvent(output[2]);
});
}));

it('queues individual feature event with index event for anonymous user', eventsServerTest(async s => {
await withEventProcessor(defaultConfig, s, async ep => {
const e = { kind: 'feature', creationDate: 1000, user: anonUser, key: 'flagkey',
Expand Down
11 changes: 10 additions & 1 deletion test/event_summarizer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,24 @@ describe('EventSummarizer', function() {
variation: 1, value: 100, default: 111 };
var event5 = { kind: 'feature', creationDate: 1000, key: 'badkey', user: user,
value: 333, default: 333 };
var event6 = { kind: 'feature', creationDate: 1000, key: 'zero-version', version: 0, user: user,
variation: 1, value: 100, default: 444 };
es.summarizeEvent(event1);
es.summarizeEvent(event2);
es.summarizeEvent(event3);
es.summarizeEvent(event4);
es.summarizeEvent(event5);
es.summarizeEvent(event6);
var data = es.getSummary();

data.features.key1.counters.sort(function(a, b) { return a.value - b.value; });
var expectedFeatures = {
'zero-version': {
default: 444,
counters: [
{ variation: 1, value: 100, version: 0, count: 1}
]
},
key1: {
default: 111,
counters: [
Expand All @@ -67,7 +76,7 @@ describe('EventSummarizer', function() {
badkey: {
default: 333,
counters: [ { value: 333, unknown: true, count: 1 }]
}
},
};
expect(data.features).toEqual(expectedFeatures);
});
Expand Down

0 comments on commit d4ab468

Please sign in to comment.