fune/toolkit/components/normandy/test/browser/browser_actions_ConsoleLogAction.js
Mike Cooper 49425f6a65 Bug 1440782 Part 2 - Add preference-rollout action to Normandy r=Gijs
MozReview-Commit-ID: 2ItLoSxlbC

--HG--
rename : toolkit/components/normandy/actions/ConsoleLog.jsm => toolkit/components/normandy/actions/ConsoleLogAction.jsm
rename : toolkit/components/normandy/test/browser/browser_action_ConsoleLog.js => toolkit/components/normandy/test/browser/browser_actions_ConsoleLogAction.js
extra : rebase_source : d07892f47eb952170088f3f96044ac0aae99f7ce
2018-04-19 15:37:11 -07:00

45 lines
1.4 KiB
JavaScript

"use strict";
ChromeUtils.import("resource://normandy/actions/ConsoleLogAction.jsm", this);
ChromeUtils.import("resource://normandy/lib/Uptake.jsm", this);
// Test that logging works
add_task(async function logging_works() {
const action = new ConsoleLogAction();
const infoStub = sinon.stub(action.log, "info");
try {
const recipe = {id: 1, arguments: {message: "Hello, world!"}};
await action.runRecipe(recipe);
Assert.deepEqual(infoStub.args, ["Hello, world!"], "the message should be logged");
} finally {
infoStub.restore();
}
});
// test that argument validation works
decorate_task(
withStub(Uptake, "reportRecipe"),
async function arguments_are_validated(reportRecipeStub) {
const action = new ConsoleLogAction();
const infoStub = sinon.stub(action.log, "info");
try {
// message is required
let recipe = {id: 1, arguments: {}};
await action.runRecipe(recipe);
Assert.deepEqual(infoStub.args, [], "no message should be logged");
Assert.deepEqual(reportRecipeStub.args, [[recipe.id, Uptake.RECIPE_EXECUTION_ERROR]]);
reportRecipeStub.reset();
// message must be a string
recipe = {id: 1, arguments: {message: 1}};
await action.runRecipe(recipe);
Assert.deepEqual(infoStub.args, [], "no message should be logged");
Assert.deepEqual(reportRecipeStub.args, [[recipe.id, Uptake.RECIPE_EXECUTION_ERROR]]);
} finally {
infoStub.restore();
}
},
);