Skip to content

Commit

Permalink
lint-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sammacbeth committed Jan 17, 2025
1 parent 41cea44 commit 24060d6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
10 changes: 5 additions & 5 deletions shared/js/background/components/abn-experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class PixelMetric {
* Currently intercepts `epbf` pixels and triggers a `brokenSiteReport` metric.
* @param {{
* abnMetrics: AbnExperimentMetrics
* }} opts
* }} opts
*/
constructor({ abnMetrics }) {
browser.webRequest.onCompleted.addListener(
Expand Down Expand Up @@ -144,12 +144,12 @@ export default class AbnExperimentMetrics {

/**
* Triggered when a given metric is triggered.
*
* Checks all active, enrolled subfeature experiments to find matching metrics that should be
*
* Checks all active, enrolled subfeature experiments to find matching metrics that should be
* sent for them. With those that match, their counter is incremented by `value`, and if they
* exceed the threshold, a pixel is sent.
*
* After incrementing counters and potentially sending pixels, the updated cohort state is
*
* After incrementing counters and potentially sending pixels, the updated cohort state is
* written back to settings.
* @param {string} metric
* @param {number} [value]
Expand Down
56 changes: 33 additions & 23 deletions unit-test/background/abn-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ describe('ABN pixels', () => {
expect(pixelIntercept).toHaveBeenCalledTimes(2);
expect(pixelRequests[1]).toContain('conversionWindowDays=0&');
expect(pixelRequests[1]).toContain('value=1&');
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', pixelRequests[1])).toEqual([]);
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', pixelRequests[1])).toEqual(
[],
);
});

it('onMetricTriggered can trigger multiple matching metrics', () => {
Expand All @@ -258,8 +260,12 @@ describe('ABN pixels', () => {
.filter((u) => u.startsWith('/t/experiment_metrics_'))
.map((u) => new URLSearchParams(u.split('?')[1]).get('conversionWindowDays'));
expect(sentConversionWindows).toEqual(['6', '5-7']);
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', pixelRequests[1])).toEqual([]);
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', pixelRequests[2])).toEqual([]);
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', pixelRequests[1])).toEqual(
[],
);
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', pixelRequests[2])).toEqual(
[],
);
});

it('metric conversion window is inclusive of first and last days', () => {
Expand All @@ -283,33 +289,37 @@ describe('ABN pixels', () => {
if (u.startsWith('/t/experiment_metrics_')) {
expect(pixelValidator.validateLivePixels(experimentPixels['experiment.metrics'], 'experiment.metrics', u)).toEqual([]);
}
})
});
});

it('metric value count applies to conversion window only', () => {
const { remoteConfig, abnMetrics } = constructMockComponents();
remoteConfig.updateConfig(mockExperimentConfig);
abnMetrics.markExperimentEnrolled(feature, subFeature, [{
metric: 'search',
conversionWindowStart: 5,
conversionWindowEnd: 7,
value: 4
}, {
metric: 'search',
conversionWindowStart: 5,
conversionWindowEnd: 5,
value: 1
}, {
metric: 'search',
conversionWindowStart: 5,
conversionWindowEnd: 5,
value: 2
}]);
abnMetrics.markExperimentEnrolled(feature, subFeature, [
{
metric: 'search',
conversionWindowStart: 5,
conversionWindowEnd: 7,
value: 4,
},
{
metric: 'search',
conversionWindowStart: 5,
conversionWindowEnd: 5,
value: 1,
},
{
metric: 'search',
conversionWindowStart: 5,
conversionWindowEnd: 5,
value: 2,
},
]);
// modify enrollment to be 7 days ago
const cohort = remoteConfig.getCohort(feature, subFeature);
cohort.enrolledAt = Date.now() - 1000 * 60 * 60 * 25 * 7;
remoteConfig.setCohort(feature, subFeature, cohort);
pixelRequests.pop()
pixelRequests.pop();
// day 1 search
abnMetrics.onMetricTriggered('search', 1, Date.now() - 1000 * 60 * 60 * 25 * 6);
expect(pixelIntercept).toHaveBeenCalledTimes(1);
Expand All @@ -326,7 +336,7 @@ describe('ABN pixels', () => {
abnMetrics.onMetricTriggered('search', 1, Date.now() - 1000 * 60 * 60 * 25 * 2);
// value=1 metric was triggered on day 5
expect(pixelIntercept).toHaveBeenCalledTimes(2);
expect(pixelRequests.pop()).toContain('conversionWindowDays=5&value=1')
expect(pixelRequests.pop()).toContain('conversionWindowDays=5&value=1');
// day 6 search x2
abnMetrics.onMetricTriggered('search', 1, Date.now() - 1000 * 60 * 60 * 25 * 1);
abnMetrics.onMetricTriggered('search', 1, Date.now() - 1000 * 60 * 60 * 25 * 1);
Expand All @@ -335,6 +345,6 @@ describe('ABN pixels', () => {
abnMetrics.onMetricTriggered('search', 1, Date.now());
// value=4 metric triggers now
expect(pixelIntercept).toHaveBeenCalledTimes(3);
expect(pixelRequests.pop()).toContain('conversionWindowDays=5-7&value=4')
expect(pixelRequests.pop()).toContain('conversionWindowDays=5-7&value=4');
});
});
1 change: 0 additions & 1 deletion unit-test/background/remote-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import browser from 'webextension-polyfill';
import RemoteConfig from '../../shared/js/background/components/remote-config';
import messageHandlers from '../../shared/js/background/message-handlers';


class MockSettings {
constructor() {
this.mockSettingData = new Map();
Expand Down

0 comments on commit 24060d6

Please sign in to comment.