1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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"
);
}
);
|