|
1 | 1 | const assert = require('assert');
|
2 |
| -const { TurnContext } = require('botbuilder-core'); |
| 2 | +const { ActivityTypes, TurnContext } = require('botbuilder-core'); |
3 | 3 | const connector = require('botframework-connector');
|
4 |
| -const { AuthenticationConstants, CertificateAppCredentials } = require('botframework-connector'); |
| 4 | +const { AuthenticationConstants, CertificateAppCredentials, ConnectorClient, MicrosoftAppCredentials } = require('botframework-connector'); |
5 | 5 | const { BotFrameworkAdapter } = require('../');
|
6 | 6 |
|
7 | 7 | const reference = {
|
@@ -257,13 +257,25 @@ describe(`BotFrameworkAdapter`, function () {
|
257 | 257 | });
|
258 | 258 | });
|
259 | 259 |
|
260 |
| - it(`should createConnectorClient().`, function (done) { |
261 |
| - const req = new MockRequest(incomingMessage); |
262 |
| - const adapter = new AdapterUnderTest(); |
263 |
| - const client = adapter.testCreateConnectorClient(reference.serviceUrl); |
264 |
| - assert(client, `client not returned.`); |
265 |
| - assert(client.conversations, `invalid client returned.`); |
266 |
| - done(); |
| 260 | + describe('get/create ConnectorClient methods', () => { |
| 261 | + it(`should createConnectorClient().`, function (done) { |
| 262 | + const req = new MockRequest(incomingMessage); |
| 263 | + const adapter = new AdapterUnderTest(); |
| 264 | + const client = adapter.testCreateConnectorClient(reference.serviceUrl); |
| 265 | + assert(client, `client not returned.`); |
| 266 | + assert(client.conversations, `invalid client returned.`); |
| 267 | + done(); |
| 268 | + }); |
| 269 | + |
| 270 | + it('getOrCreateConnectorClient should create a new client if the cached serviceUrl does not match the provided one', () => { |
| 271 | + const adapter = new BotFrameworkAdapter(); |
| 272 | + const context = new TurnContext(adapter, { type: ActivityTypes.Message, text: 'hello', serviceUrl: 'http://bing.com' }); |
| 273 | + const cc = new ConnectorClient(new MicrosoftAppCredentials('', ''), {baseUri: 'http://bing.com'}); |
| 274 | + context.turnState.set(adapter.ConnectorClientKey, cc); |
| 275 | + |
| 276 | + const client = adapter.getOrCreateConnectorClient(context, 'https://botframework.com', adapter.credentials); |
| 277 | + assert.notEqual(client.baseUri, cc.baseUri); |
| 278 | + }); |
267 | 279 | });
|
268 | 280 |
|
269 | 281 | it(`should processActivity().`, function (done) {
|
@@ -732,15 +744,15 @@ describe(`BotFrameworkAdapter`, function () {
|
732 | 744 | });
|
733 | 745 |
|
734 | 746 | // This unit test doesn't work anymore because client.UserAgentInfo was removed, so we can't inspect the user agent string
|
735 |
| - // it(`should create a User-Agent header with the same info as the host machine.`, function (done) { |
736 |
| - // const adapter = new BotFrameworkAdapter(); |
737 |
| - // const client = adapter.createConnectorClient('https://example.com'); |
738 |
| - // //const userAgentHeader = client.userAgentInfo.value; |
739 |
| - // const pjson = require('../package.json'); |
740 |
| - // const userAgent = 'Microsoft-BotFramework/3.1 BotBuilder/' + pjson.version + ' (Node.js,Version=' + process.version + '; ' + os.type() + ' ' + os.release() + '; ' + os.arch() + ')'; |
741 |
| - // // assert(userAgentHeader.includes(userAgent), `ConnectorClient doesn't have user-agent header created by BotFrameworkAdapter or header is incorrect.`); |
742 |
| - // done(); |
743 |
| - // }); |
| 747 | + xit(`should create a User-Agent header with the same info as the host machine.`, function (done) { |
| 748 | + const adapter = new BotFrameworkAdapter(); |
| 749 | + const client = adapter.createConnectorClient('https://example.com'); |
| 750 | + //const userAgentHeader = client.userAgentInfo.value; |
| 751 | + const pjson = require('../package.json'); |
| 752 | + const userAgent = 'Microsoft-BotFramework/3.1 BotBuilder/' + pjson.version + ' (Node.js,Version=' + process.version + '; ' + os.type() + ' ' + os.release() + '; ' + os.arch() + ')'; |
| 753 | + // assert(userAgentHeader.includes(userAgent), `ConnectorClient doesn't have user-agent header created by BotFrameworkAdapter or header is incorrect.`); |
| 754 | + done(); |
| 755 | + }); |
744 | 756 |
|
745 | 757 | it(`should set openIdMetadata property on ChannelValidation`, function (done) {
|
746 | 758 | const testEndpoint = "http://rainbows.com";
|
|
0 commit comments