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_actions_MessagingExperimentAction.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_actions_MessagingExperimentAction.js')
-rw-r--r-- | toolkit/components/normandy/test/browser/browser_actions_MessagingExperimentAction.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/toolkit/components/normandy/test/browser/browser_actions_MessagingExperimentAction.js b/toolkit/components/normandy/test/browser/browser_actions_MessagingExperimentAction.js new file mode 100644 index 0000000000..0f16ff1436 --- /dev/null +++ b/toolkit/components/normandy/test/browser/browser_actions_MessagingExperimentAction.js @@ -0,0 +1,67 @@ +"use strict"; + +const { BaseAction } = ChromeUtils.importESModule( + "resource://normandy/actions/BaseAction.sys.mjs" +); +const { Uptake } = ChromeUtils.importESModule( + "resource://normandy/lib/Uptake.sys.mjs" +); +const { MessagingExperimentAction } = ChromeUtils.importESModule( + "resource://normandy/actions/MessagingExperimentAction.sys.mjs" +); + +const { _ExperimentManager, ExperimentManager } = ChromeUtils.importESModule( + "resource://nimbus/lib/ExperimentManager.sys.mjs" +); + +decorate_task( + withStudiesEnabled(), + withStub(Uptake, "reportRecipe"), + async function arguments_are_validated({ reportRecipeStub }) { + const action = new MessagingExperimentAction(); + + is( + action.manager, + ExperimentManager, + "should set .manager to ExperimentManager singleton" + ); + // Override this for the purposes of the test + action.manager = new _ExperimentManager(); + await action.manager.onStartup(); + const onRecipeStub = sinon.spy(action.manager, "onRecipe"); + + const recipe = { + id: 1, + arguments: { + slug: "foo", + isEnrollmentPaused: false, + branches: [ + { + slug: "control", + ratio: 1, + groups: ["green"], + value: { title: "hello" }, + }, + { + slug: "variant", + ratio: 1, + groups: ["green"], + value: { title: "world" }, + }, + ], + }, + }; + + ok(action.validateArguments(recipe.arguments), "should validate arguments"); + + await action.processRecipe(recipe, BaseAction.suitability.FILTER_MATCH); + await action.finalize(); + + Assert.deepEqual(reportRecipeStub.args, [[recipe, Uptake.RECIPE_SUCCESS]]); + Assert.deepEqual( + onRecipeStub.args, + [[recipe.arguments, "normandy"]], + "should call onRecipe with recipe args and 'normandy' source" + ); + } +); |