Skip to content

Commit

Permalink
Add option validation to setDebug command. (#1209)
Browse files Browse the repository at this point in the history
  • Loading branch information
shammowla authored Nov 4, 2024
1 parent 332340d commit 84ac54f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/core/injectExecuteCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ governing permissions and limitations under the License.

import { isFunction, isObject } from "../utils/index.js";
import { CONFIGURE, SET_DEBUG } from "../constants/coreCommands.js";
import { objectOf, boolean } from "../utils/validation/index.js";

export default ({
logger,
Expand Down Expand Up @@ -44,7 +45,18 @@ export default ({
);
}
if (commandName === SET_DEBUG) {
executor = () => setDebugCommand(options);
executor = () => {
const optionsValidator = objectOf({
enabled: boolean().required(),
}).noUnknownFields();

const validatedOptions = validateCommandOptions({
command: { commandName: SET_DEBUG, optionsValidator },
options,
});

setDebugCommand(validatedOptions);
};
} else {
executor = () => {
return configurePromise.then(
Expand Down
7 changes: 6 additions & 1 deletion test/unit/specs/core/injectExecuteCommand.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,24 @@ describe("injectExecuteCommand", () => {
.createSpy()
.and.returnValue(Promise.resolve(componentRegistry));
const setDebugCommand = jasmine.createSpy();
const validateCommandOptions = jasmine
.createSpy()
.and.returnValue({ enabled: true });

const executeCommand = injectExecuteCommand({
logger,
configureCommand,
setDebugCommand,
handleError,
validateCommandOptions,
});

return Promise.all([
executeCommand("configure", { foo: "bar" }),
executeCommand("setDebug", { baz: "qux" }),
]).then(([configureResult, setDebugResult]) => {
expect(configureCommand).toHaveBeenCalledWith({ foo: "bar" });
expect(setDebugCommand).toHaveBeenCalledWith({ baz: "qux" });
expect(setDebugCommand).toHaveBeenCalledWith({ enabled: true });
expect(configureResult).toEqual({});
expect(setDebugResult).toEqual({});
});
Expand Down

0 comments on commit 84ac54f

Please sign in to comment.