Skip to content

Commit

Permalink
Add aadGroupId to TeamInfo (#2370)
Browse files Browse the repository at this point in the history
* Add aadGroupId to TeamInfo

* add new line at end of teamsActivityHelper.ts

Co-authored-by: Steven Gum <[email protected]>
  • Loading branch information
Eric Dahlvang and stevengum authored Jun 22, 2020
1 parent 804ade0 commit a7e4f82
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
10 changes: 10 additions & 0 deletions libraries/botbuilder/src/teamsActivityHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,13 @@ export function teamsNotifyUser(activity: Activity): void {
const channelData: TeamsChannelData = activity.channelData as TeamsChannelData;
channelData.notification = { alert: true } as NotificationInfo;
}

export function teamsGetTeamInfo(activity: Activity): TeamInfo {
if (!activity) {
throw new Error('Missing activity parameter');
}

const channelData: TeamsChannelData = activity.channelData as TeamsChannelData;
const team: TeamInfo = channelData ? channelData.team : null;
return team;
}
40 changes: 38 additions & 2 deletions libraries/botbuilder/tests/teamsHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const {
BotFrameworkAdapter,
teamsGetChannelId,
teamsGetTeamId,
teamsNotifyUser
teamsNotifyUser,
teamsGetTeamInfo
} = require('../');


Expand Down Expand Up @@ -125,6 +126,41 @@ describe('TeamsActivityHelpers method', function() {
}
});
});

describe('teamsGetTeamInfo()', () => {
it('should return team id', async function() {
const activity = createActivityTeamId();
const teamInfo = teamsGetTeamInfo(activity);
assert(teamInfo.id === 'myId');
});

it('should return undefined with no team id', async function() {
const activity = createActivityNoTeamId();
const teamInfo = teamsGetTeamInfo(activity);
assert(teamInfo.id === undefined);
});

it('should return null with no channelData', async function() {
const activity = createActivityNoChannelData();
const teamInfo = teamsGetTeamInfo(activity);
assert(teamInfo === null);
});

it('should return aadGroupId', async function() {
const activity = createActivityTeamId();
const teamInfo = teamsGetTeamInfo(activity);
assert(teamInfo.aadGroupId === 'myaadGroupId');
});

it('should throw an error if no activity is passed in', () => {
try {
teamsGetTeamInfo(undefined);
} catch (err) {
assert.strictEqual(err.message, 'Missing activity parameter');
}
});
});

});

function createActivityNoTeamId() {
Expand Down Expand Up @@ -163,7 +199,7 @@ function createActivityTeamId() {
text: "testMessage",
channelId: 'teams',
from: { id: `User1` },
channelData: { team: { id: 'myId'}},
channelData: { team: { id: 'myId', aadGroupId: 'myaadGroupId'}},
conversation: { id: 'conversationId' },
recipient: { id: 'Bot1', name: '2' },
serviceUrl: 'http://foo.com/api/messages'
Expand Down
6 changes: 6 additions & 0 deletions libraries/botframework-connector/src/teams/models/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export const TeamInfo: msRest.CompositeMapper = {
type: {
name: 'String'
}
},
aadGroupId: {
serializedName: 'aadGroupId',
type: {
name: 'String'
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ export interface TeamDetails {
export interface TeamInfo {
id?: string;
name?: string;
aadGroupId?: string;
}

// @public (undocumented)
Expand Down

0 comments on commit a7e4f82

Please sign in to comment.