Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return http state #1755

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion libraries/botbuilder/src/botFrameworkHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export class BotFrameworkHttpClient {
throw new Error('BotFrameworkHttpClient.postActivity(): Unable to get appCredentials to connect to the skill');
}

if (activity.conversation === undefined) {
throw new Error('BotFrameworkHttpClient.postActivity(): Activity must have a ConversationReference');
}

// Get token for the skill call
const token = appCredentials.appId === '' && appCredentials.appPassword === '' ? null : await appCredentials.getToken();

Expand All @@ -72,7 +76,8 @@ export class BotFrameworkHttpClient {
Accept: 'application/json',
'Content-Type': 'application/json',
'User-Agent': USER_AGENT
}
},
validateStatus: function () { return true; }
};

if (token) {
Expand Down
27 changes: 27 additions & 0 deletions libraries/botbuilder/tests/botFrameworkHttpClient.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { strictEqual } = require('assert');
const { BotFrameworkHttpClient } = require('../');
const { AuthenticationConstants, SimpleCredentialProvider } = require('botframework-connector');
const nock = require('nock');

describe('BotFrameworkHttpClient', function() {
this.timeout(3000);
Expand Down Expand Up @@ -29,5 +30,31 @@ describe('BotFrameworkHttpClient', function() {
strictEqual(e.message, 'BotFrameworkHttpClient(): missing credentialProvider');
}
});

it('should succeed to make call', async () => {

nock('http://skillUrl')
.post('/api/good')
.reply(200, { id: 'some-id' });

const credentialProvider = new SimpleCredentialProvider('', '');
const client = new BotFrameworkHttpClient(credentialProvider, 'channels');
const fromBotId = null;
const response = await client.postActivity(fromBotId, 'toBotId', 'http://skillUrl/api/good', 'serviceUrl', 'conversationId', { type: 'message', conversation: { } });
strictEqual(response.status, 200);
});

it('should return status code for a failed call', async () => {

nock('http://skillUrl')
.post('/api/bad')
.reply(404, { id: 'some-id' });

const credentialProvider = new SimpleCredentialProvider('', '');
const client = new BotFrameworkHttpClient(credentialProvider, 'channels');
const fromBotId = null;
const response = await client.postActivity(fromBotId, 'toBotId', 'http://skillUrl/api/bad', 'serviceUrl', 'conversationId', { type: 'message', conversation: { } });
strictEqual(response.status, 404);
});
});
});