gecko-dev/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js
Barret Rennie b94346e8cc Bug 1814965 - Expose Normandy Heartbeat as a Nimbus feature r=Gijs,emcminn
Normandy's Heartbeat is now exposed as a Nimbus feature: legacyHeartbeat. It's
argument structure is almost identical to the Normandy version, except all
arguments are nested under a "survey" property to prevent pollution of
experiments by simultaneous rollouts. (e.g., if an experiment were to omit an
optional parameter but a simultaneous rollout included that parameter, Nimbus
would return the value from the rollout when showing the Hearbeat for the
experiment.)

Differential Revision: https://phabricator.services.mozilla.com/D169409
2023-02-27 17:35:15 +00:00

86 lines
2.2 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { BaseAction } = ChromeUtils.import(
"resource://normandy/actions/BaseAction.jsm"
);
const { ClientEnvironment } = ChromeUtils.import(
"resource://normandy/lib/ClientEnvironment.jsm"
);
const { Heartbeat } = ChromeUtils.import(
"resource://normandy/lib/Heartbeat.jsm"
);
const { Normandy } = ChromeUtils.import("resource://normandy/Normandy.jsm");
const { ExperimentAPI } = ChromeUtils.import(
"resource://nimbus/ExperimentAPI.jsm"
);
const { ExperimentFakes } = ChromeUtils.import(
"resource://testing-common/NimbusTestUtils.jsm"
);
const { RecipeRunner } = ChromeUtils.import(
"resource://normandy/lib/RecipeRunner.jsm"
);
const { RemoteSettings } = ChromeUtils.import(
"resource://services-settings/remote-settings.js"
);
const SURVEY = {
surveyId: "a survey",
message: "test message",
engagementButtonLabel: "",
thanksMessage: "thanks!",
postAnswerUrl: "https://example.com",
learnMoreMessage: "Learn More",
learnMoreUrl: "https://example.com",
repeatOption: "once",
};
function assertSurvey(actual, expected) {
for (const key of Object.keys(actual)) {
if (["postAnswerUrl", "flowId"].includes(key)) {
continue;
}
Assert.equal(
actual[key],
expected[key],
`Heartbeat should receive correct ${key} parameter`
);
}
Assert.ok(actual.postAnswerUrl.startsWith(expected.postAnswerUrl));
}
decorate_task(
withStubbedHeartbeat(),
withClearStorage(),
async function testLegacyHeartbeatTrigger({ heartbeatClassStub }) {
const sandbox = sinon.createSandbox();
const cleanupEnrollment = await ExperimentFakes.enrollWithFeatureConfig({
featureId: "legacyHeartbeat",
value: {
survey: SURVEY,
},
});
const client = RemoteSettings("normandy-recipes-capabilities");
sandbox.stub(client, "get").resolves([]);
try {
await RecipeRunner.run();
Assert.equal(
heartbeatClassStub.args.length,
1,
"Heartbeat should be instantiated once"
);
assertSurvey(heartbeatClassStub.args[0][1], SURVEY);
await cleanupEnrollment();
} finally {
sandbox.restore();
}
}
);