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

fix: enable TeamsInfo methods to work with CloudAdapter #3830

Merged
merged 5 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions libraries/botbuilder/src/teamsInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,12 @@ export class TeamsInfo {
* @private
*/
private static getConnectorClient(context: TurnContext): ConnectorClient {
if (!context.adapter || !('createConnectorClient' in context.adapter)) {
const client = context.turnState?.get<ConnectorClient>(context.adapter.ConnectorClientKey);
if (!client) {
mdrichardson marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('This method requires a connector client.');
}

return (context.adapter as BotFrameworkAdapter).createConnectorClient(context.activity.serviceUrl);
return client;
}

/**
Expand Down
28 changes: 20 additions & 8 deletions libraries/botbuilder/tests/teamsInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const nock = require('nock');
const sinon = require('sinon');
const { BotFrameworkAdapter, TeamsInfo, CloudAdapter } = require('../');
const { Conversations } = require('botframework-connector/lib/connectorApi/operations');
const { MicrosoftAppCredentials, ConnectorClient } = require('botframework-connector');
const { MicrosoftAppCredentials, ConnectorClient, ServiceClientCredentialsFactory, PasswordServiceClientCredentialFactory } = require('botframework-connector');
const { TurnContext, MessageFactory, ActionTypes, BotAdapter, Channels } = require('botbuilder-core');

class TeamsInfoAdapter extends BotFrameworkAdapter {
Expand Down Expand Up @@ -182,6 +182,8 @@ const teamActivity = {
};

describe('TeamsInfo', function () {
const connectorClient = new ConnectorClient(new MicrosoftAppCredentials('abc', '123'), { baseUri: 'https://smba.trafficmanager.net/amer' });

beforeEach(function () {
nock.cleanAll();
});
Expand Down Expand Up @@ -342,6 +344,7 @@ describe('TeamsInfo', function () {
.reply(200, { conversations });

const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const channels = await TeamsInfo.getTeamChannels(context);

assert(fetchOauthToken.isDone());
Expand Down Expand Up @@ -381,6 +384,7 @@ describe('TeamsInfo', function () {
.reply(200, { conversations });

const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const channels = await TeamsInfo.getTeamChannels(context, '19:ChannelIdgeneralChannelId@thread.skype');

assert(fetchOauthToken.isDone());
Expand Down Expand Up @@ -431,6 +435,7 @@ describe('TeamsInfo', function () {
.reply(200, teamDetails);

const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const fetchedTeamDetails = await TeamsInfo.getTeamDetails(context);

assert(fetchOauthToken.isDone());
Expand All @@ -457,6 +462,7 @@ describe('TeamsInfo', function () {
.reply(200, teamDetails);

const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const fetchedTeamDetails = await TeamsInfo.getTeamDetails(
context,
'19:ChannelIdgeneralChannelId@thread.skype'
Expand Down Expand Up @@ -495,6 +501,7 @@ describe('TeamsInfo', function () {
.reply(200, members);

const context = new TestContext(oneOnOneActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const fetchedMembers = await TeamsInfo.getMembers(context);

assert(fetchOauthToken.isDone());
Expand Down Expand Up @@ -548,6 +555,7 @@ describe('TeamsInfo', function () {
.reply(200, members);

const context = new TestContext(groupChatActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const fetchedMembers = await TeamsInfo.getMembers(context);

assert(fetchOauthToken.isDone());
Expand Down Expand Up @@ -591,6 +599,7 @@ describe('TeamsInfo', function () {
.reply(200, members);

const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const fetchedMembers = await TeamsInfo.getMembers(context);

assert(fetchOauthToken.isDone());
Expand All @@ -604,6 +613,7 @@ describe('TeamsInfo', function () {

it('should not work if conversationId is falsey', async function () {
const context = new TestContext(oneOnOneActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
context.activity.conversation.id = undefined;

await assert.rejects(TeamsInfo.getMembers(context), (err) => {
Expand Down Expand Up @@ -635,6 +645,7 @@ describe('TeamsInfo', function () {
.reply(200, member);

const context = new TestContext(oneOnOneActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const fetchedMember = await TeamsInfo.getMember(context, oneOnOneActivity.from.id);

assert(fetchOauthToken.isDone());
Expand Down Expand Up @@ -663,6 +674,7 @@ describe('TeamsInfo', function () {
.reply(200, member);

const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const fetchedMember = await TeamsInfo.getMember(context, teamActivity.from.id);

assert(fetchOauthToken.isDone());
Expand All @@ -685,6 +697,7 @@ describe('TeamsInfo', function () {

describe('getMeetingParticipant', function () {
const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);

it('should work with correct arguments', async function () {
const participant = {
Expand Down Expand Up @@ -729,6 +742,7 @@ describe('TeamsInfo', function () {

describe('getMeetingInfo', function () {
const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);

it('should work with correct arguments-meetingId in context', async function () {
const details = {
Expand Down Expand Up @@ -772,6 +786,9 @@ describe('TeamsInfo', function () {
});

it('should work with correct arguments-meetingId passed in', async function () {
const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);

const details = {
organizer: {
id: teamActivity.from.id,
Expand Down Expand Up @@ -872,6 +889,7 @@ describe('TeamsInfo', function () {
.reply(200, members);

const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const fetchedMembers = await TeamsInfo.getTeamMembers(context);

assert(fetchOauthToken.isDone());
Expand Down Expand Up @@ -915,6 +933,7 @@ describe('TeamsInfo', function () {
.reply(200, members);

const context = new TestContext(teamActivity);
context.turnState.set(context.adapter.ConnectorClientKey, connectorClient);
const fetchedMembers = await TeamsInfo.getTeamMembers(context, '19:ChannelIdgeneralChannelId@thread.skype');

assert(fetchOauthToken.isDone());
Expand All @@ -935,13 +954,6 @@ describe('TeamsInfo', function () {
new Error('This method requires a connector client.')
);
});

it(`should error if the adapter doesn't have a createConnectorClient method`, function () {
joshgummersall marked this conversation as resolved.
Show resolved Hide resolved
assert.throws(
() => TeamsInfo.getConnectorClient({ adapter: {} }),
new Error('This method requires a connector client.')
);
});
});

describe('getMembersInternal()', function () {
Expand Down