Adding new call to services middleware (#4823)

As the tittle suggests. Adding this call to the middleware used by clients.

---

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [x] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E - added CI test
This commit is contained in:
jules 2023-12-08 12:28:02 -08:00 committed by GitHub
parent 8af0e31e4e
commit 66ff1efc47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -41,6 +41,23 @@ func (c client) GroupByID(
return parseGroup(ctx, g)
}
// TeamById retrieves a specific group.
// when the caller knows the group is a team.
// will fail if the group is not a team.
func (c client) TeamByID(
ctx context.Context,
id string,
) (*Group, error) {
cc := api.CallConfig{}
g, err := c.ac.Groups().GetTeamByID(ctx, id, cc)
if err != nil {
return nil, clues.Stack(err)
}
return parseGroupFromTeamable(ctx, g)
}
// GroupsCompat returns a list of groups in the specified M365 tenant.
func (c client) GroupsCompat(ctx context.Context) ([]*Group, error) {
errs := fault.New(true)
@ -123,6 +140,22 @@ func parseGroup(ctx context.Context, mg models.Groupable) (*Group, error) {
return u, nil
}
// parseGroup extracts information from `models.Teamable` we care about
func parseGroupFromTeamable(ctx context.Context, mg models.Teamable) (*Group, error) {
if mg.GetDisplayName() == nil {
return nil, clues.New("group missing display name").
With("group_id", ptr.Val(mg.GetId()))
}
u := &Group{
ID: ptr.Val(mg.GetId()),
DisplayName: ptr.Val(mg.GetDisplayName()),
IsTeam: true,
}
return u, nil
}
// GroupsMap retrieves an id-name cache of all groups in the tenant.
func (c client) GroupsMap(
ctx context.Context,

View File

@ -84,6 +84,22 @@ func (suite *GroupsIntgSuite) TestGroupByID_ByEmail() {
assert.Equal(t, groupByEmail, group, "must be the same group as the one gotten by id")
}
func (suite *GroupsIntgSuite) TestTeamByID() {
t := suite.T()
ctx, flush := tester.NewContext(t)
defer flush()
gid := tconfig.M365TeamID(t)
group, err := suite.cli.TeamByID(ctx, gid)
require.NoError(t, err, clues.ToCore(err))
require.NotNil(t, group)
assert.Equal(t, gid, group.ID, "must match expected id")
assert.NotEmpty(t, group.DisplayName)
}
func (suite *GroupsIntgSuite) TestGroupByID_notFound() {
t := suite.T()