Skip to content

Commit c4998e1

Browse files
authored
Merge pull request #1035 from microsoft/Zerryth/QnAMakerServiceHostname
QnAMakerService correctly builds hostname URL & throws error w/o URL
2 parents 3dcc4fc + ece3485 commit c4998e1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

libraries/botframework-config/src/models/qnaMakerService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ export class QnaMakerService extends ConnectedService implements IQnAService {
3939
*/
4040
constructor(source: IQnAService = {} as IQnAService) {
4141
super(source, ServiceTypes.QnA);
42+
43+
if (!source.hostname) {
44+
throw TypeError('QnAMakerService requires source parameter to have a hostname.')
45+
}
4246

43-
this.hostname = new URL('/qnamaker', this.hostname).href;
47+
if (!this.hostname.endsWith('/qnamaker')) {
48+
this.hostname = new URL('/qnamaker', this.hostname).href;
49+
}
4450
}
4551

4652
// encrypt keys in service

libraries/botframework-config/tests/service.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,22 @@ describe("Service Tests", () => {
2929
});
3030
assert.equal(qna.hostname, "https://myservice.azurewebsites.net/qnamaker");
3131
});
32+
33+
it("QnAMaker correctly does not add suffix when already hostname endind with \/qnamaker", () => {
34+
let qnaWithQnamakerHostname = new bf.QnaMakerService({
35+
hostname: "https://MyServiceThatDoesntNeedAppending.azurewebsites.net/qnamaker"
36+
});
37+
assert.equal(qnaWithQnamakerHostname.hostname, "https://MyServiceThatDoesntNeedAppending.azurewebsites.net/qnamaker");
38+
});
39+
40+
it("QnAMaker should throw error without hostname", () => {
41+
function createQnaWithoutHostname() {
42+
new bf.QnaMakerService({});
43+
}
44+
45+
let noHostnameError = new TypeError('QnAMakerService requires source parameter to have a hostname.')
46+
47+
assert.throws(() => createQnaWithoutHostname(), noHostnameError)
48+
});
3249
});
3350

0 commit comments

Comments
 (0)