Skip to content

Commit e2e5714

Browse files
Trim experiments without a cohort from reports (#3181)
1 parent 48ca8e7 commit e2e5714

File tree

2 files changed

+66
-1
lines changed
  • shared/js/background/classes
  • unit-test/background/classes

2 files changed

+66
-1
lines changed

shared/js/background/classes/tab.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class Tab {
5959
// turn into an object
6060
this.contentScopeExperiments = {};
6161
for (const experiment of experiments) {
62-
this.contentScopeExperiments[experiment.subfeature] = experiment.cohort || '';
62+
if (!experiment.cohort) continue;
63+
this.contentScopeExperiments[experiment.subfeature] = experiment.cohort;
6364
}
6465
}
6566

unit-test/background/classes/tab.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,70 @@ const config = require('../../data/extension-config.json');
1212
let tab;
1313

1414
describe('Tab', () => {
15+
describe('initExperiments()', () => {
16+
it('should skip experiments without cohorts', () => {
17+
const mockAbnMetrics = {
18+
automaticallyEnrollCurrentContentScopeExperiments: jasmine.createSpy('automaticallyEnrollCurrentContentScopeExperiments'),
19+
getCurrentCohorts: jasmine.createSpy('getCurrentCohorts').and.returnValue([
20+
{ feature: 'contentScopeExperiments', subfeature: 'feature1', cohort: 'treatment' },
21+
{ feature: 'contentScopeExperiments', subfeature: 'feature2', cohort: null },
22+
{ feature: 'contentScopeExperiments', subfeature: 'feature3', cohort: 'control' },
23+
{ feature: 'contentScopeExperiments', subfeature: 'feature4', cohort: undefined },
24+
]),
25+
};
26+
27+
tab = new Tab(
28+
{
29+
id: 123,
30+
requestId: 123,
31+
url: 'http://example.com',
32+
status: 200,
33+
},
34+
mockAbnMetrics,
35+
);
36+
37+
expect(mockAbnMetrics.automaticallyEnrollCurrentContentScopeExperiments).toHaveBeenCalled();
38+
expect(mockAbnMetrics.getCurrentCohorts).toHaveBeenCalled();
39+
expect(tab.contentScopeExperiments).toEqual({
40+
feature1: 'treatment',
41+
feature3: 'control',
42+
});
43+
});
44+
45+
it('should handle empty experiments array', () => {
46+
const mockAbnMetrics = {
47+
automaticallyEnrollCurrentContentScopeExperiments: jasmine.createSpy('automaticallyEnrollCurrentContentScopeExperiments'),
48+
getCurrentCohorts: jasmine.createSpy('getCurrentCohorts').and.returnValue([]),
49+
};
50+
51+
tab = new Tab(
52+
{
53+
id: 123,
54+
requestId: 123,
55+
url: 'http://example.com',
56+
status: 200,
57+
},
58+
mockAbnMetrics,
59+
);
60+
61+
expect(tab.contentScopeExperiments).toEqual({});
62+
});
63+
64+
it('should handle null abnMetrics', () => {
65+
tab = new Tab(
66+
{
67+
id: 123,
68+
requestId: 123,
69+
url: 'http://example.com',
70+
status: 200,
71+
},
72+
null,
73+
);
74+
75+
expect(tab.contentScopeExperiments).toEqual({});
76+
});
77+
});
78+
1579
describe('updateSite()', () => {
1680
beforeEach(() => {
1781
tab = new Tab({

0 commit comments

Comments
 (0)