@@ -67,9 +67,9 @@ func TestAPITeam(t *testing.T) {
67
67
resp = session .MakeRequest (t , req , http .StatusCreated )
68
68
DecodeJSON (t , resp , & apiTeam )
69
69
checkTeamResponse (t , & apiTeam , teamToCreate .Name , teamToCreate .Description , teamToCreate .IncludesAllRepositories ,
70
- teamToCreate .Permission , teamToCreate .Units )
70
+ teamToCreate .Permission , teamToCreate .Units , nil )
71
71
checkTeamBean (t , apiTeam .ID , teamToCreate .Name , teamToCreate .Description , teamToCreate .IncludesAllRepositories ,
72
- teamToCreate .Permission , teamToCreate .Units )
72
+ teamToCreate .Permission , teamToCreate .Units , nil )
73
73
teamID := apiTeam .ID
74
74
75
75
// Edit team.
@@ -87,9 +87,9 @@ func TestAPITeam(t *testing.T) {
87
87
resp = session .MakeRequest (t , req , http .StatusOK )
88
88
DecodeJSON (t , resp , & apiTeam )
89
89
checkTeamResponse (t , & apiTeam , teamToEdit .Name , * teamToEdit .Description , * teamToEdit .IncludesAllRepositories ,
90
- teamToEdit .Permission , teamToEdit .Units )
90
+ teamToEdit .Permission , teamToEdit .Units , nil )
91
91
checkTeamBean (t , apiTeam .ID , teamToEdit .Name , * teamToEdit .Description , * teamToEdit .IncludesAllRepositories ,
92
- teamToEdit .Permission , teamToEdit .Units )
92
+ teamToEdit .Permission , teamToEdit .Units , nil )
93
93
94
94
// Edit team Description only
95
95
editDescription = "first team"
@@ -98,38 +98,108 @@ func TestAPITeam(t *testing.T) {
98
98
resp = session .MakeRequest (t , req , http .StatusOK )
99
99
DecodeJSON (t , resp , & apiTeam )
100
100
checkTeamResponse (t , & apiTeam , teamToEdit .Name , * teamToEditDesc .Description , * teamToEdit .IncludesAllRepositories ,
101
- teamToEdit .Permission , teamToEdit .Units )
101
+ teamToEdit .Permission , teamToEdit .Units , nil )
102
102
checkTeamBean (t , apiTeam .ID , teamToEdit .Name , * teamToEditDesc .Description , * teamToEdit .IncludesAllRepositories ,
103
- teamToEdit .Permission , teamToEdit .Units )
103
+ teamToEdit .Permission , teamToEdit .Units , nil )
104
104
105
105
// Read team.
106
106
teamRead := unittest .AssertExistsAndLoadBean (t , & models.Team {ID : teamID }).(* models.Team )
107
+ assert .NoError (t , teamRead .GetUnits ())
107
108
req = NewRequestf (t , "GET" , "/api/v1/teams/%d?token=" + token , teamID )
108
109
resp = session .MakeRequest (t , req , http .StatusOK )
109
110
DecodeJSON (t , resp , & apiTeam )
110
111
checkTeamResponse (t , & apiTeam , teamRead .Name , * teamToEditDesc .Description , teamRead .IncludesAllRepositories ,
111
- teamRead .Authorize .String (), teamRead .GetUnitNames ())
112
+ teamRead .Authorize .String (), teamRead .GetUnitNames (), teamRead .GetUnitsMap ())
113
+
114
+ panic ("" )
115
+ // Delete team.
116
+ req = NewRequestf (t , "DELETE" , "/api/v1/teams/%d?token=" + token , teamID )
117
+ session .MakeRequest (t , req , http .StatusNoContent )
118
+ unittest .AssertNotExistsBean (t , & models.Team {ID : teamID })
119
+
120
+ // create team again via UnitsMap
121
+ // Create team.
122
+ teamToCreate = & api.CreateTeamOption {
123
+ Name : "team2" ,
124
+ Description : "team two" ,
125
+ IncludesAllRepositories : true ,
126
+ Permission : "write" ,
127
+ UnitsMap : map [string ]string {"repo.code" : "read" , "repo.issues" : "write" , "repo.wiki" : "none" },
128
+ }
129
+ req = NewRequestWithJSON (t , "POST" , fmt .Sprintf ("/api/v1/orgs/%s/teams?token=%s" , org .Name , token ), teamToCreate )
130
+ resp = session .MakeRequest (t , req , http .StatusCreated )
131
+ DecodeJSON (t , resp , & apiTeam )
132
+ checkTeamResponse (t , & apiTeam , teamToCreate .Name , teamToCreate .Description , teamToCreate .IncludesAllRepositories ,
133
+ teamToCreate .Permission , nil , teamToCreate .UnitsMap )
134
+ checkTeamBean (t , apiTeam .ID , teamToCreate .Name , teamToCreate .Description , teamToCreate .IncludesAllRepositories ,
135
+ teamToCreate .Permission , nil , teamToCreate .UnitsMap )
136
+ teamID = apiTeam .ID
137
+
138
+ // Edit team.
139
+ editDescription = "team 1"
140
+ editFalse = false
141
+ teamToEdit = & api.EditTeamOption {
142
+ Name : "teamtwo" ,
143
+ Description : & editDescription ,
144
+ Permission : "write" ,
145
+ IncludesAllRepositories : & editFalse ,
146
+ UnitsMap : map [string ]string {"repo.code" : "read" , "repo.pulls" : "read" , "repo.releases" : "write" },
147
+ }
148
+
149
+ req = NewRequestWithJSON (t , "PATCH" , fmt .Sprintf ("/api/v1/teams/%d?token=%s" , teamID , token ), teamToEdit )
150
+ resp = session .MakeRequest (t , req , http .StatusOK )
151
+ DecodeJSON (t , resp , & apiTeam )
152
+ checkTeamResponse (t , & apiTeam , teamToEdit .Name , * teamToEdit .Description , * teamToEdit .IncludesAllRepositories ,
153
+ teamToEdit .Permission , nil , teamToEdit .UnitsMap )
154
+ checkTeamBean (t , apiTeam .ID , teamToEdit .Name , * teamToEdit .Description , * teamToEdit .IncludesAllRepositories ,
155
+ teamToEdit .Permission , nil , teamToEdit .UnitsMap )
156
+
157
+ // Edit team Description only
158
+ editDescription = "second team"
159
+ teamToEditDesc = api.EditTeamOption {Description : & editDescription }
160
+ req = NewRequestWithJSON (t , "PATCH" , fmt .Sprintf ("/api/v1/teams/%d?token=%s" , teamID , token ), teamToEditDesc )
161
+ resp = session .MakeRequest (t , req , http .StatusOK )
162
+ DecodeJSON (t , resp , & apiTeam )
163
+ checkTeamResponse (t , & apiTeam , teamToEdit .Name , * teamToEditDesc .Description , * teamToEdit .IncludesAllRepositories ,
164
+ teamToEdit .Permission , nil , teamToEdit .UnitsMap )
165
+ checkTeamBean (t , apiTeam .ID , teamToEdit .Name , * teamToEditDesc .Description , * teamToEdit .IncludesAllRepositories ,
166
+ teamToEdit .Permission , nil , teamToEdit .UnitsMap )
167
+
168
+ // Read team.
169
+ teamRead = unittest .AssertExistsAndLoadBean (t , & models.Team {ID : teamID }).(* models.Team )
170
+ req = NewRequestf (t , "GET" , "/api/v1/teams/%d?token=" + token , teamID )
171
+ resp = session .MakeRequest (t , req , http .StatusOK )
172
+ DecodeJSON (t , resp , & apiTeam )
173
+ checkTeamResponse (t , & apiTeam , teamRead .Name , * teamToEditDesc .Description , teamRead .IncludesAllRepositories ,
174
+ teamRead .Authorize .String (), teamRead .GetUnitNames (), teamRead .GetUnitsMap ())
112
175
113
176
// Delete team.
114
177
req = NewRequestf (t , "DELETE" , "/api/v1/teams/%d?token=" + token , teamID )
115
178
session .MakeRequest (t , req , http .StatusNoContent )
116
179
unittest .AssertNotExistsBean (t , & models.Team {ID : teamID })
117
180
}
118
181
119
- func checkTeamResponse (t * testing.T , apiTeam * api.Team , name , description string , includesAllRepositories bool , permission string , units []string ) {
120
- assert .Equal (t , name , apiTeam .Name , "name" )
121
- assert .Equal (t , description , apiTeam .Description , "description" )
122
- assert .Equal (t , includesAllRepositories , apiTeam .IncludesAllRepositories , "includesAllRepositories" )
123
- assert .Equal (t , permission , apiTeam .Permission , "permission" )
124
- sort .StringSlice (units ).Sort ()
125
- sort .StringSlice (apiTeam .Units ).Sort ()
126
- assert .EqualValues (t , units , apiTeam .Units , "units" )
182
+ func checkTeamResponse (t * testing.T , apiTeam * api.Team , name , description string , includesAllRepositories bool , permission string , units []string , unitsMap map [string ]string ) {
183
+ t .Run (name + description , func (t * testing.T ) {
184
+ assert .Equal (t , name , apiTeam .Name , "name" )
185
+ assert .Equal (t , description , apiTeam .Description , "description" )
186
+ assert .Equal (t , includesAllRepositories , apiTeam .IncludesAllRepositories , "includesAllRepositories" )
187
+ assert .Equal (t , permission , apiTeam .Permission , "permission" )
188
+ if units != nil {
189
+ sort .StringSlice (units ).Sort ()
190
+ sort .StringSlice (apiTeam .Units ).Sort ()
191
+ assert .EqualValues (t , units , apiTeam .Units , "units" )
192
+ }
193
+ if unitsMap != nil {
194
+ assert .EqualValues (t , unitsMap , apiTeam .UnitsMap , "unitsMap" )
195
+ }
196
+ })
127
197
}
128
198
129
- func checkTeamBean (t * testing.T , id int64 , name , description string , includesAllRepositories bool , permission string , units []string ) {
199
+ func checkTeamBean (t * testing.T , id int64 , name , description string , includesAllRepositories bool , permission string , units []string , unitsMap map [ string ] string ) {
130
200
team := unittest .AssertExistsAndLoadBean (t , & models.Team {ID : id }).(* models.Team )
131
201
assert .NoError (t , team .GetUnits (), "GetUnits" )
132
- checkTeamResponse (t , convert .ToTeam (team ), name , description , includesAllRepositories , permission , units )
202
+ checkTeamResponse (t , convert .ToTeam (team ), name , description , includesAllRepositories , permission , units , unitsMap )
133
203
}
134
204
135
205
type TeamSearchResults struct {
0 commit comments