Skip to content

Commit

Permalink
feat: add ASK_FORCE_ENABLE to allow skipping domain validation during…
Browse files Browse the repository at this point in the history
… enablement (#500)

Co-authored-by: Mario Doiron <[email protected]>
  • Loading branch information
doiron and Mario Doiron authored Dec 11, 2023
1 parent d9a0cc6 commit 8c297bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/controllers/skill-metadata-controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ module.exports = class SkillMetadataController {
* Validates domain info
*/
validateDomain() {
if (process.env.ASK_FORCE_ENABLE) {
Messenger.getInstance().warn("The ASK_FORCE_ENABLE environment variable is set. Skipping domain validation.\n");
return;
}

const domainInfo = Manifest.getInstance().getApis();
if (!domainInfo || R.isEmpty(domainInfo)) {
throw new CLiError('Skill information is not valid. Please make sure "apis" field in the skill.json is not empty.');
Expand Down
23 changes: 23 additions & 0 deletions test/unit/controller/skill-metadata-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe("Controller test - skill metadata controller test", () => {
});

afterEach(() => {
delete process.env.ASK_FORCE_ENABLE;
ResourcesConfig.dispose();
Manifest.dispose();
sinon.restore();
Expand Down Expand Up @@ -263,6 +264,28 @@ describe("Controller test - skill metadata controller test", () => {
expect(() => skillMetaController.validateDomain()).to.throw(CliWarn, expectedErrMessage);
});

it("| skips validation when ASK_FORCE_ENABLE is set", () => {
// setup
process.env.ASK_FORCE_ENABLE = 1;
Manifest.getInstance().setApis({
custom: {},
unknownApi: {},
smartHome: {},
});
const getApisSpy = sinon.spy(Manifest.prototype, "getApis");
const warnStub = sinon.stub();
sinon.stub(Messenger, "getInstance").returns({
warn: warnStub,
});
const expectedWarningMessage = "The ASK_FORCE_ENABLE environment variable is set. Skipping domain validation.\n"
// call
skillMetaController.validateDomain();
// verify
expect(getApisSpy.callCount).eq(0);
expect(warnStub.callCount).equal(1);
expect(warnStub.args[0][0]).equal(expectedWarningMessage);
});

it("| callback error when getSkillEnablement return error", (done) => {
// setup
sinon.stub(httpClient, "request").callsArgWith(3, "getSkillEnablementError"); // stub smapi request
Expand Down

0 comments on commit 8c297bf

Please sign in to comment.