summaryrefslogtreecommitdiffstats
path: root/toolkit/components/normandy/test/browser/browser_ActionsManager.js
blob: 2667a085cfd565ca2dc5d27c52523306fae31640 (plain)
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
68
"use strict";

const { BaseAction } = ChromeUtils.importESModule(
  "resource://normandy/actions/BaseAction.sys.mjs"
);
const { ActionsManager } = ChromeUtils.importESModule(
  "resource://normandy/lib/ActionsManager.sys.mjs"
);
const { Uptake } = ChromeUtils.importESModule(
  "resource://normandy/lib/Uptake.sys.mjs"
);
const { ActionSchemas } = ChromeUtils.importESModule(
  "resource://normandy/actions/schemas/index.sys.mjs"
);

// Test life cycle methods for actions
decorate_task(async function () {
  let manager = new ActionsManager();
  const recipe = { id: 1, action: "test-local-action-used" };

  let actionUsed = {
    processRecipe: sinon.stub(),
    finalize: sinon.stub(),
  };
  let actionUnused = {
    processRecipe: sinon.stub(),
    finalize: sinon.stub(),
  };
  manager.localActions = {
    "test-local-action-used": actionUsed,
    "test-local-action-unused": actionUnused,
  };

  await manager.processRecipe(recipe, BaseAction.suitability.FILTER_MATCH);
  await manager.finalize();

  Assert.deepEqual(
    actionUsed.processRecipe.args,
    [[recipe, BaseAction.suitability.FILTER_MATCH]],
    "used action should be called with the recipe"
  );
  ok(
    actionUsed.finalize.calledOnce,
    "finalize should be called on used action"
  );
  Assert.deepEqual(
    actionUnused.processRecipe.args,
    [],
    "unused action should not be called with the recipe"
  );
  ok(
    actionUnused.finalize.calledOnce,
    "finalize should be called on the unused action"
  );
});

decorate_task(async function () {
  for (const [name, Constructor] of Object.entries(
    ActionsManager.actionConstructors
  )) {
    const action = new Constructor();
    Assert.deepEqual(
      ActionSchemas[name],
      action.schema,
      "action name should map to a schema"
    );
  }
});