Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
[Botskills] Implement tests for connect functionality (#1488)
Browse files Browse the repository at this point in the history
* Refactor connectSkill functionality to export Class instead of functions

* Continue implementing connect tests

* Add tests for connectSkill functionality, update validations, remove 'process.exit(1)'

* Refactor authenticationUtils to export class instead of function for ease to mock it

* Add more tests for connect command

* Add reporters for publishing test and coverage results
  • Loading branch information
David Favretto authored and darrenj committed Jun 5, 2019
1 parent b7422a7 commit ca5d4f3
Show file tree
Hide file tree
Showing 24 changed files with 903 additions and 425 deletions.
3 changes: 2 additions & 1 deletion lib/typescript/botskills/.nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"reporter": [
"html",
"text"
"text",
"cobertura"
],
"sourceMap": true,
"cache": true
Expand Down
4 changes: 2 additions & 2 deletions lib/typescript/botskills/src/botskills-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as program from 'commander';
import { existsSync } from 'fs';
import { extname, isAbsolute, join, resolve } from 'path';
import { connectSkill } from './functionality';
import { ConnectSkill } from './functionality';
import { ConsoleLogger, ILogger } from './logger';
import { ICognitiveModelFile, IConnectConfiguration } from './models';
import { validatePairOfArgs } from './utils';
Expand Down Expand Up @@ -163,4 +163,4 @@ configuration.logger = logger;

// End of arguments validation

connectSkill(<IConnectConfiguration> configuration);
new ConnectSkill(logger).connectSkill(<IConnectConfiguration> configuration);
414 changes: 214 additions & 200 deletions lib/typescript/botskills/src/functionality/connectSkill.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/typescript/botskills/src/functionality/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
* Licensed under the MIT License.
*/

export { connectSkill } from './connectSkill';
export { ConnectSkill } from './connectSkill';
export { DisconnectSkill } from './disconnectSkill';
export { ListSkill } from './listSkill';
418 changes: 212 additions & 206 deletions lib/typescript/botskills/src/utils/authenticationUtils.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/typescript/botskills/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
*/

export { ChildProcessUtils } from './childProcessUtils';
export { authenticate } from './authenticationUtils';
export { AuthenticationUtils } from './authenticationUtils';
export { validatePairOfArgs } from './validationUtils';
359 changes: 359 additions & 0 deletions lib/typescript/botskills/test/flow/connectTest.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions lib/typescript/botskills/test/flow/disconnectTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("The disconnect command", function () {
})

describe("should show an error", function () {
it("when there's no skills File", async function () {
it("when there is no skills File", async function () {
const config = {
skillId : "",
skillsFile : "",
Expand Down Expand Up @@ -121,7 +121,7 @@ describe("The disconnect command", function () {
assert.strictEqual(ErrorList[ErrorList.length - 1], `Could not find file ${config.dispatchName}.dispatch. Please provide the 'dispatchName' and 'dispatchFolder' parameters.`);
});

it("when the 'dispatch refresh' fails to create the Dispatch JSON file", async function () {
it("when the dispatch refresh fails to create the Dispatch JSON file", async function () {
const config = {
skillId : "testDispatch",
skillsFile: path.resolve(__dirname, '../mockedFiles/filledSkillsArray.json'),
Expand All @@ -144,7 +144,7 @@ describe("The disconnect command", function () {
assert.strictEqual(ErrorList[ErrorList.length - 1], `There was an error while disconnecting the Skill ${config.skillId} from the Assistant:\nError: An error ocurred while updating the Dispatch model:\nError: Path to ${config.dispatchName}.json (${path.join(config.dispatchFolder, config.dispatchName)}.json) leads to a nonexistent file. Make sure the dispatch refresh command is being executed successfully`);
});

it("when the 'lgOutFolder' argument is invalid ", async function () {
it("when the lgOutFolder argument is invalid ", async function () {
const config = {
skillId : "testDispatch",
skillsFile: path.resolve(__dirname, '../mockedFiles/filledSkillsArray.json'),
Expand All @@ -167,7 +167,7 @@ describe("The disconnect command", function () {
assert.strictEqual(ErrorList[ErrorList.length - 1], `The 'lgOutFolder' argument is absent or leads to a non-existing folder.\nPlease make sure to provide a valid path to your LUISGen output folder.`);
});

it("when the 'lgLanguage' argument is invalid", async function () {
it("when the lgLanguage argument is invalid", async function () {
const config = {
skillId : "testDispatch",
skillsFile: path.resolve(__dirname, '../mockedFiles/filledSkillsArray.json'),
Expand Down
8 changes: 4 additions & 4 deletions lib/typescript/botskills/test/flow/listTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("The list command", function () {
describe("should show an error", function () {


it("when there's no skills File", async function () {
it("when there is no skills File", async function () {
const config = {
skillsFile: '',
logger: this.logger
Expand Down Expand Up @@ -61,7 +61,7 @@ describe("The list command", function () {
});

describe("should show a message", function () {
it("when there's no skills connected to the assistant", async function () {
it("when there is no skills connected to the assistant", async function () {
const config = {
skillsFile: path.resolve(__dirname, '../mockedFiles/emptySkillsArray.json'),
logger: this.logger
Expand All @@ -72,7 +72,7 @@ describe("The list command", function () {
assert.strictEqual(MessageList[MessageList.length - 1], `There are no Skills connected to the assistant.`);
});

it("when there's no skills array defined in the Assistant Skills configuration file", async function () {
it("when there is no skills array defined in the Assistant Skills configuration file", async function () {
const config = {
skillsFile: path.resolve(__dirname, '../mockedFiles/undefinedSkillsArray.json'),
logger: this.logger
Expand All @@ -83,7 +83,7 @@ describe("The list command", function () {
assert.strictEqual(MessageList[MessageList.length - 1], `There are no Skills connected to the assistant.`);
});

it("when there's a skill in the Assistant Skills configuration file", async function () {
it("when there is a skill in the Assistant Skills configuration file", async function () {
const config = {
skillsFile: path.resolve(__dirname, '../mockedFiles/filledSkillsArray.json'),
logger: this.logger
Expand Down
1 change: 1 addition & 0 deletions lib/typescript/botskills/test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--reporter mocha-junit-reporter
--timeout 50000
--colors
--recursive
Expand Down
27 changes: 27 additions & 0 deletions lib/typescript/botskills/test/mockedFiles/connectableSkill.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"id": "connectableSkill",
"msaAppId": "00000000-0000-0000-0000-000000000000",
"name": "Test Skill",
"endpoint": "https://bftestskill.azurewebsites.net/api/skill/messages",
"description": "This is a test skill to use for testing purpose.",
"authenticationConnections": [],
"actions": [
{
"id": "connectableSkill_testAction",
"definition": {
"description": "Test Action",
"slots": [],
"triggers": {
"utteranceSources": [
{
"locale": "en",
"source": [
"connectableSkill#Test"
]
}
]
}
}
}
]
}
4 changes: 4 additions & 0 deletions lib/typescript/botskills/test/mockedFiles/invalidSkill.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"msaAppId": "00000000-0000-0000-0000-000000000000",
"description": "This is a test skill to use for testing purpose."
}
27 changes: 27 additions & 0 deletions lib/typescript/botskills/test/mockedFiles/invalidSkillid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"id": "test-./Skill",
"msaAppId": "00000000-0000-0000-0000-000000000000",
"name": "Test Skill",
"endpoint": "https://bftestskill.azurewebsites.net/api/skill/messages",
"description": "This is a test skill to use for testing purpose.",
"authenticationConnections": [],
"actions": [
{
"id": "testSkill_testAction",
"definition": {
"description": "Test Action",
"slots": [],
"triggers": {
"utteranceSources": [
{
"locale": "en",
"source": [
"test#Test"
]
}
]
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a mocked .lu file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a mocked .lu file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a mocked .luis file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a mocked .lu file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a mocked .luis file
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"skills": [
{
"id": "testSkill"
},
{
"id": "testDispatch"
}
]
}
27 changes: 27 additions & 0 deletions lib/typescript/botskills/test/mockedFiles/testSkill.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"id": "testSkill",
"msaAppId": "00000000-0000-0000-0000-000000000000",
"name": "Test Skill",
"endpoint": "https://bftestskill.azurewebsites.net/api/skill/messages",
"description": "This is a test skill to use for testing purpose.",
"authenticationConnections": [],
"actions": [
{
"id": "testSkill_testAction",
"definition": {
"description": "Test Action",
"slots": [],
"triggers": {
"utteranceSources": [
{
"locale": "en",
"source": [
"test#Test"
]
}
]
}
}
}
]
}
9 changes: 3 additions & 6 deletions lib/typescript/botskills/test/models/testLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class TestLogger {
this._success = new Array();
this._warning = new Array();
this._command = new Array();
this._isError = false;
this._isVerbose = false;
this.isError = false;
this.isVerbose = false;
}
error(message) {
this._error.push(message);
this._isError = true;
this.isError = true;
}
message(message) {
this._message.push(message);
Expand All @@ -37,9 +37,6 @@ class TestLogger {
this.message(message);
}
}
get isVerbose() { return this._isVerbose; }
set isVerbose(value) { this._isVerbose = value || false; }
isError() { return this._isError; }
getMessage() { return this._message; }
getError() { return this._error; }
getSuccess() { return this._success; }
Expand Down

0 comments on commit ca5d4f3

Please sign in to comment.