Skip to content

Commit

Permalink
Merge branch 'main' into fix/export-typings
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
  • Loading branch information
kyle-ssg committed Jul 22, 2022
2 parents 780b881 + de2224a commit 485d7f5
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 70 deletions.
67 changes: 24 additions & 43 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 68 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sdk/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export class AnalyticsProcessor {
this.lastFlushed = Date.now();
}

trackFeature(featureId: number) {
this.analyticsData[featureId] = (this.analyticsData[featureId] || 0) + 1;
trackFeature(featureName: string) {
this.analyticsData[featureName] = (this.analyticsData[featureName] || 0) + 1;
if (Date.now() - this.lastFlushed > ANALYTICS_TIMER * 1000) {
this.flush();
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class Flags {
}

if (this.analyticsProcessor && flag.featureId) {
this.analyticsProcessor.trackFeature(flag.featureId);
this.analyticsProcessor.trackFeature(flag.featureName);
}

return flag;
Expand Down
20 changes: 10 additions & 10 deletions tests/sdk/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ afterEach(() => {

test('test_analytics_processor_track_feature_updates_analytics_data', () => {
const aP = analyticsProcessor();
aP.trackFeature(1);
expect(aP.analyticsData[1]).toBe(1);
aP.trackFeature("myFeature");
expect(aP.analyticsData["myFeature"]).toBe(1);

aP.trackFeature(1);
expect(aP.analyticsData[1]).toBe(2);
aP.trackFeature("myFeature");
expect(aP.analyticsData["myFeature"]).toBe(2);
});

test('test_analytics_processor_flush_clears_analytics_data', async () => {
const aP = analyticsProcessor();
aP.trackFeature(1);
aP.trackFeature("myFeature");
await aP.flush();
expect(aP.analyticsData).toStrictEqual({});
});

test('test_analytics_processor_flush_post_request_data_match_ananlytics_data', async () => {
const aP = analyticsProcessor();
aP.trackFeature(1);
aP.trackFeature(2);
aP.trackFeature("myFeature1");
aP.trackFeature("myFeature2");
await aP.flush();
expect(fetch).toHaveBeenCalledTimes(1);
expect(fetch).toHaveBeenCalledWith('http://testUrlanalytics/flags/', {
body: '{"1":1,"2":1}',
body: '{"myFeature1":1,"myFeature2":1}',
headers: { 'Content-Type': 'application/json', 'X-Environment-Key': 'test-key' },
method: 'POST',
timeout: 3
Expand All @@ -39,9 +39,9 @@ test('test_analytics_processor_flush_post_request_data_match_ananlytics_data', a
jest.useFakeTimers()
test('test_analytics_processor_flush_post_request_data_match_ananlytics_data_test', async () => {
const aP = analyticsProcessor();
aP.trackFeature(1);
aP.trackFeature("myFeature1");
setTimeout(() => {
aP.trackFeature(2);
aP.trackFeature("myFeature2");
expect(fetch).toHaveBeenCalledTimes(1);
}, 15000);
jest.runOnlyPendingTimers();
Expand Down

0 comments on commit 485d7f5

Please sign in to comment.