Skip to content

Commit

Permalink
WIP: in Team, switched members to membership, incomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbloss committed Nov 2, 2023
1 parent 8274902 commit 79fe96a
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 87 deletions.
54 changes: 27 additions & 27 deletions actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,30 +345,30 @@ func TestDeleteTriggerDefinition(t *testing.T) {
autopilot.Assert(t, err3 != nil, "Expected error was not thrown")
}

func TestListExtendedTeamAccess(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
`{{ template "extended_team_access_get_vars_1" }}`,
`{{ template "extended_team_access_response_1" }}`,
)
testRequestTwo := NewTestRequest(
`"query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
`{{ template "extended_team_access_get_vars_2" }}`,
`{{ template "extended_team_access_response_2" }}`,
)
requests := []TestRequest{testRequestOne, testRequestTwo}

client := BestTestClient(t, "custom_actions/list_extended_team_access", requests...)
id1 := *ol.NewID(string(id1))
trigger := ol.CustomActionsTriggerDefinition{Id: id1}

// Act
resp, err := trigger.ExtendedTeamAccess(client, nil)
result := resp.Nodes

// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, "example", result[0].Alias)
autopilot.Equals(t, id1, result[0].TeamId.Id)
}
// func TestListExtendedTeamAccess(t *testing.T) {
// // Arrange
// testRequestOne := NewTestRequest(
// `"query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},memberships{nodes{team{alias,id},role,user{id,email}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
// `{{ template "extended_team_access_get_vars_1" }}`,
// `{{ template "extended_team_access_response_1" }}`,
// )
// testRequestTwo := NewTestRequest(
// `"query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},memberships{nodes{team{alias,id},role,user{id,email}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
// `{{ template "extended_team_access_get_vars_2" }}`,
// `{{ template "extended_team_access_response_2" }}`,
// )
// requests := []TestRequest{testRequestOne, testRequestTwo}

// client := BestTestClient(t, "custom_actions/list_extended_team_access", requests...)
// id1 := *ol.NewID(string(id1))
// trigger := ol.CustomActionsTriggerDefinition{Id: id1}

// // Act
// resp, err := trigger.ExtendedTeamAccess(client, nil)
// result := resp.Nodes

// // Assert
// autopilot.Ok(t, err)
// autopilot.Equals(t, "example", result[0].Alias)
// autopilot.Equals(t, id1, result[0].TeamId.Id)
// }
2 changes: 1 addition & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestCache(t *testing.T) {
`{"data":{"account":{ "lifecycles":[{{ template "lifecycle_1" }}] }}}`,
)
testRequestThree := NewTestRequest(
`"query TeamList($after:String!$first:Int!){account{teams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}"`,
`"query TeamList($after:String!$first:Int!){account{teams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},memberships{nodes{id,email,htmlUrl,name,role},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}"`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "teams":{ "nodes":[{{ template "team_1" }}] } }}}`,
)
Expand Down
8 changes: 4 additions & 4 deletions group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func TestDeleteGroupWithAlias(t *testing.T) {
func TestChildTeams(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query GroupChildTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){childTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
`"query GroupChildTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){childTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},memberships{nodes{team{alias,id},role,user{id,email}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}"`,
`{ {{ template "first_page_variables" }}, "group": "123456789" }`,
`{ "data": { "account": { "group": { "childTeams": { "nodes": [ {{ template "team_1" }}, {{ template "team_2" }} ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}}`,
)
testRequestTwo := NewTestRequest(
`"query GroupChildTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){childTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
`"query GroupChildTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){childTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},memberships{nodes{team{alias,id},role,user{id,email}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}"`,
`{ {{ template "second_page_variables" }}, "group": "123456789" }`,
`{ "data": { "account": { "group": { "childTeams": { "nodes": [ {{ template "team_3" }} ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
Expand All @@ -80,12 +80,12 @@ func TestChildTeams(t *testing.T) {
func TestDescendantTeams(t *testing.T) {
// Arrange
testRequestOne := NewTestRequest(
`"query GroupDescendantTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
`"query GroupDescendantTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},memberships{nodes{team{alias,id},role,user{id,email}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},{{ template "pagination_request" }},totalCount}}}}"`,
`{ {{ template "first_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "descendantTeams": { "nodes": [ {{ template "team_1" }}, {{ template "team_2" }} ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}}`,
)
testRequestTwo := NewTestRequest(
`"query GroupDescendantTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}"`,
`"query GroupDescendantTeamsList($after:String!$first:Int!$group:ID!){account{group(id: $group){descendantTeams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},memberships{nodes{team{alias,id},role,user{id,email}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},{{ template "pagination_request" }},totalCount}}}}"`,
`{ {{ template "second_page_variables" }}, "group": "{{ template "id4_string" }}" }`,
`{ "data": { "account": { "group": { "descendantTeams": { "nodes": [ {{ template "team_3" }} ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
Expand Down
56 changes: 31 additions & 25 deletions team.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Team struct {
Group GroupId
HTMLUrl string
Manager User
Members *UserConnection
Memberships *TeamMembershipConnection
Name string
ParentTeam TeamId
Responsibilities string
Expand Down Expand Up @@ -101,8 +101,15 @@ type TeamMembership struct {
User UserId `graphql:"user"`
}

type TeamMembershipConnection struct {
Nodes []TeamMembership
PageInfo PageInfo
TotalCount int
}

type TeamMembershipUserInput struct {
User UserIdentifierInput `json:"user"`
Role string `json:"role"`
}

type TeamMembershipCreateInput struct {
Expand All @@ -128,12 +135,12 @@ func (t *Team) ResourceType() TaggableResource {
func (self *Team) Hydrate(client *Client) error {
self.Responsibilities = html.UnescapeString(self.Responsibilities)

if self.Members == nil {
self.Members = &UserConnection{}
if self.Memberships == nil {
self.Memberships = &TeamMembershipConnection{}
}
if self.Members.PageInfo.HasNextPage {
if self.Memberships.PageInfo.HasNextPage {
variables := client.InitialPageVariablesPointer()
(*variables)["after"] = self.Members.PageInfo.End
(*variables)["after"] = self.Memberships.PageInfo.End
_, err := self.GetMembers(client, variables)
if err != nil {
return err
Expand All @@ -154,39 +161,39 @@ func (self *Team) Hydrate(client *Client) error {
return nil
}

func (t *Team) GetMembers(client *Client, variables *PayloadVariables) (*UserConnection, error) {
func (t *Team) GetMembers(client *Client, variables *PayloadVariables) (*TeamMembershipConnection, error) {
if t.Id == "" {
return nil, fmt.Errorf("Unable to get Memberships, invalid team id: '%s'", t.Id)
}
var q struct {
Account struct {
Team struct {
Members UserConnection `graphql:"members(after: $after, first: $first)"`
Memberships TeamMembershipConnection `graphql:"memberships(after: $after, first: $first)"`
} `graphql:"team(id: $team)"`
}
}
if t.Id == "" {
return nil, fmt.Errorf("Unable to get Members, invalid team id: '%s'", t.Id)
}
if variables == nil {
variables = client.InitialPageVariablesPointer()
}
(*variables)["team"] = t.Id
if err := client.Query(&q, *variables, WithName("TeamMembersList")); err != nil {
if err := client.Query(&q, *variables, WithName("TeamMembershipsList")); err != nil {
return nil, err
}
if t.Members == nil {
members := UserConnection{}
t.Members = &members
if t.Memberships == nil {
memberships := TeamMembershipConnection{}
t.Memberships = &memberships
}
t.Members.Nodes = append(t.Members.Nodes, q.Account.Team.Members.Nodes...)
t.Members.PageInfo = q.Account.Team.Members.PageInfo
t.Members.TotalCount += q.Account.Team.Members.TotalCount
for t.Members.PageInfo.HasNextPage {
(*variables)["after"] = t.Members.PageInfo.End
t.Memberships.Nodes = append(t.Memberships.Nodes, q.Account.Team.Memberships.Nodes...)
t.Memberships.PageInfo = q.Account.Team.Memberships.PageInfo
t.Memberships.TotalCount += q.Account.Team.Memberships.TotalCount
for t.Memberships.PageInfo.HasNextPage {
(*variables)["after"] = t.Memberships.PageInfo.End
_, err := t.GetMembers(client, variables)
if err != nil {
return nil, err
}
}
return t.Members, nil
return t.Memberships, nil
}

func (t *Team) GetTags(client *Client, variables *PayloadVariables) (*TagConnection, error) {
Expand Down Expand Up @@ -299,7 +306,7 @@ func (client *Client) CreateTeam(input TeamCreateInput) (*Team, error) {
return &m.Payload.Team, FormatErrors(m.Payload.Errors)
}

func (client *Client) AddMembers(team *TeamId, emails []string) ([]TeamMembership, error) {
func (client *Client) AddMembers(team *TeamId, memberships ...TeamMembershipUserInput) ([]TeamMembership, error) {
var m struct {
Payload struct {
Members []TeamMembership `graphql:"memberships"`
Expand All @@ -309,16 +316,15 @@ func (client *Client) AddMembers(team *TeamId, emails []string) ([]TeamMembershi
v := PayloadVariables{
"input": TeamMembershipCreateInput{
TeamId: team.Id,
Members: BuildMembershipInput(emails),
Members: memberships,
},
}
err := client.Mutate(&m, v, WithName("TeamMembershipCreate"))
return m.Payload.Members, HandleErrors(err, m.Payload.Errors)
}

func (client *Client) AddMember(team *TeamId, email string) ([]TeamMembership, error) {
emails := []string{email}
return client.AddMembers(team, emails)
func (client *Client) AddMember(team *TeamId, membership TeamMembershipUserInput) ([]TeamMembership, error) {
return client.AddMembers(team, membership)
}

func (client *Client) AddContact(team string, contact ContactInput) (*Contact, error) {
Expand Down
Loading

0 comments on commit 79fe96a

Please sign in to comment.