@@ -22,6 +22,10 @@ func TestOrgRole(t *testing.T) {
2222
2323 githubOrganization , _ , _ , githubUser , _ := mgh .Seed ()
2424
25+ // Add user to org role
26+ roleId := int64 (1 )
27+ mgh .AddUserToOrgRole (roleId , * githubUser .ID )
28+
2529 githubClient := github .NewClient (mgh .Server ())
2630 cache := newOrgNameCache (githubClient )
2731 client := orgRoleBuilder (githubClient , cache )
@@ -39,16 +43,19 @@ func TestOrgRole(t *testing.T) {
3943 Resource : role ,
4044 }
4145
46+ // Grant the role to the user
4247 grantAnnotations , err := client .Grant (ctx , user , & entitlement )
4348 require .Nil (t , err )
4449 require .Empty (t , grantAnnotations )
4550
51+ // Check that we can see both teams and users in the grants list
4652 grants , nextToken , grantsAnnotations , err := client .Grants (ctx , role , & pagination.Token {})
4753 require .Nil (t , err )
4854 test .AssertNoRatelimitAnnotations (t , grantsAnnotations )
49- require .Equal (t , "" , nextToken )
50- require .Len (t , grants , 1 )
55+ require .Empty (t , nextToken ) // No next token since we don't have a full page
56+ require .Len (t , grants , 2 ) // Should get both the team and user
5157
58+ // Revoke the role from the user
5259 grant := v2.Grant {
5360 Entitlement : & entitlement ,
5461 Principal : user ,
@@ -91,4 +98,41 @@ func TestOrgRole(t *testing.T) {
9198 require .Empty (t , nextToken )
9299 test .AssertNoRatelimitAnnotations (t , grantsAnnotations )
93100 })
101+
102+ t .Run ("should handle pagination for teams and users" , func (t * testing.T ) {
103+ mockGithub := mocks .NewMockGitHub ()
104+ githubOrganization , _ , _ , githubUser , _ := mockGithub .Seed ()
105+
106+ // Add more teams to trigger pagination
107+ for i := 0 ; i < 3 ; i ++ {
108+ teamId := int64 (100 + i )
109+ team := github.Team {
110+ ID : & teamId ,
111+ Organization : githubOrganization ,
112+ }
113+ mockGithub .AddTeam (team )
114+ }
115+
116+ // Add user to org role
117+ roleId := int64 (1 )
118+ mockGithub .AddUserToOrgRole (roleId , * githubUser .ID )
119+
120+ githubClient := github .NewClient (mockGithub .Server ())
121+ cache := newOrgNameCache (githubClient )
122+ client := orgRoleBuilder (githubClient , cache )
123+
124+ organization , _ := organizationResource (ctx , githubOrganization , nil )
125+ role , _ := orgRoleResource (ctx , & OrganizationRole {
126+ ID : 1 ,
127+ Name : "Test Role" ,
128+ Description : "Test Role Description" ,
129+ }, organization )
130+
131+ // Test first page (should get all teams and users)
132+ grants , nextToken , annotations , err := client .Grants (ctx , role , & pagination.Token {Size : 5 })
133+ require .Nil (t , err )
134+ require .Empty (t , nextToken ) // No next token since we got all results
135+ require .Len (t , grants , 5 ) // Should get all 4 teams (3 added + 1 from Seed) and 1 user
136+ test .AssertNoRatelimitAnnotations (t , annotations )
137+ })
94138}
0 commit comments