Skip to content

Commit

Permalink
Merge pull request #1035 from microsoft/Zerryth/QnAMakerServiceHostname
Browse files Browse the repository at this point in the history
QnAMakerService correctly builds hostname URL & throws error w/o URL
  • Loading branch information
cleemullins authored Jul 3, 2019
2 parents 3dcc4fc + ece3485 commit c4998e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libraries/botframework-config/src/models/qnaMakerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ export class QnaMakerService extends ConnectedService implements IQnAService {
*/
constructor(source: IQnAService = {} as IQnAService) {
super(source, ServiceTypes.QnA);

if (!source.hostname) {
throw TypeError('QnAMakerService requires source parameter to have a hostname.')
}

this.hostname = new URL('/qnamaker', this.hostname).href;
if (!this.hostname.endsWith('/qnamaker')) {
this.hostname = new URL('/qnamaker', this.hostname).href;
}
}

// encrypt keys in service
Expand Down
17 changes: 17 additions & 0 deletions libraries/botframework-config/tests/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,22 @@ describe("Service Tests", () => {
});
assert.equal(qna.hostname, "https://myservice.azurewebsites.net/qnamaker");
});

it("QnAMaker correctly does not add suffix when already hostname endind with \/qnamaker", () => {
let qnaWithQnamakerHostname = new bf.QnaMakerService({
hostname: "https://MyServiceThatDoesntNeedAppending.azurewebsites.net/qnamaker"
});
assert.equal(qnaWithQnamakerHostname.hostname, "https://MyServiceThatDoesntNeedAppending.azurewebsites.net/qnamaker");
});

it("QnAMaker should throw error without hostname", () => {
function createQnaWithoutHostname() {
new bf.QnaMakerService({});
}

let noHostnameError = new TypeError('QnAMakerService requires source parameter to have a hostname.')

assert.throws(() => createQnaWithoutHostname(), noHostnameError)
});
});

0 comments on commit c4998e1

Please sign in to comment.