diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js')
-rw-r--r-- | toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js b/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js new file mode 100644 index 0000000000..465e5c1040 --- /dev/null +++ b/toolkit/components/normandy/test/browser/browser_LegacyHeartbeat.js @@ -0,0 +1,88 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { BaseAction } = ChromeUtils.importESModule( + "resource://normandy/actions/BaseAction.sys.mjs" +); +const { ClientEnvironment } = ChromeUtils.importESModule( + "resource://normandy/lib/ClientEnvironment.sys.mjs" +); +const { Heartbeat } = ChromeUtils.importESModule( + "resource://normandy/lib/Heartbeat.sys.mjs" +); +const { Normandy } = ChromeUtils.importESModule( + "resource://normandy/Normandy.sys.mjs" +); +const { ExperimentAPI } = ChromeUtils.importESModule( + "resource://nimbus/ExperimentAPI.sys.mjs" +); +const { ExperimentFakes } = ChromeUtils.importESModule( + "resource://testing-common/NimbusTestUtils.sys.mjs" +); +const { RecipeRunner } = ChromeUtils.importESModule( + "resource://normandy/lib/RecipeRunner.sys.mjs" +); +const { RemoteSettings } = ChromeUtils.importESModule( + "resource://services-settings/remote-settings.sys.mjs" +); + +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(); + } + } +); |