/spec/octokit/client/organizations_spec.rb
Ruby | 413 lines | 359 code | 54 blank | 0 comment | 19 complexity | 1546629d960adc576a3e1d0fdeccc61a MD5 | raw file
1require 'helper' 2 3describe Octokit::Client::Organizations do 4 5 before do 6 Octokit.reset! 7 @client = oauth_client 8 end 9 10 describe ".organization", :vcr do 11 it "returns an organization" do 12 organization = @client.organization("codeforamerica") 13 expect(organization.name).to eq("Code for America") 14 assert_requested :get, github_url("/orgs/codeforamerica") 15 end 16 end # .organization 17 18 describe ".update_organization", :vcr do 19 it "updates an organization" do 20 organization = @client.update_organization(test_github_org, {:name => "API Playground"}) 21 expect(organization.login).to eq test_github_org 22 assert_requested :patch, github_url("/orgs/#{test_github_org}") 23 end 24 end # .update_organization 25 26 describe ".organizations", :vcr do 27 it "returns all organizations for a user" do 28 organizations = @client.organizations(test_github_login) 29 expect(organizations).to be_kind_of Array 30 assert_requested :get, github_url("/users/#{test_github_login}/orgs") 31 end 32 it "returns all organizations for the authenticated user" do 33 organizations = @client.organizations 34 expect(organizations).to be_kind_of Array 35 assert_requested :get, github_url("/user/orgs") 36 end 37 end # .organizations 38 39 describe ".all_organizations", :vcr do 40 it "paginates organizations on GitHub" do 41 orgs = Octokit.all_organizations 42 expect(orgs).to be_kind_of Array 43 assert_requested :get, github_url("organizations") 44 end 45 end # .all_organizations 46 47 describe ".organization_repositories", :vcr do 48 it "returns all public repositories for an organization" do 49 repositories = @client.organization_repositories("codeforamerica") 50 expect(repositories).to be_kind_of Array 51 assert_requested :get, github_url("/orgs/codeforamerica/repos") 52 end 53 end # .organization_repositories 54 55 describe ".organization_members", :vcr do 56 it "returns all public members of an organization" do 57 users = @client.organization_members("codeforamerica") 58 expect(users).to be_kind_of Array 59 assert_requested :get, github_url("/orgs/codeforamerica/members") 60 end 61 end # .organization_members 62 63 describe ".organization_member?", :vcr do 64 it "checks organization membership" do 65 is_member = @client.organization_member?(test_github_org, test_github_login) 66 assert_requested :get, github_url("/orgs/#{test_github_org}/members/#{test_github_login}") 67 expect(is_member).to be true 68 end 69 end # .organization_member? 70 71 describe ".organization_public_members", :vcr do 72 it "lists public members" do 73 users = @client.organization_public_members("codeforamerica") 74 expect(users).to be_kind_of Array 75 assert_requested :get, github_url("/orgs/codeforamerica/public_members") 76 end 77 end 78 79 describe ".organization_invitations", :vcr do 80 it "lists pending organization invitations" do 81 @client.organization_invitations(test_github_org) 82 assert_requested :get, github_url("/orgs/#{test_github_org}/invitations") 83 end 84 end # .organization_invitations 85 86 describe ".outside_collaborators", :vcr do 87 it "lists outside collaborators for an organization" do 88 @client.outside_collaborators(test_github_org) 89 assert_requested :get, github_url("/orgs/#{test_github_org}/outside_collaborators") 90 end 91 end # .outside_collaborators 92 93 describe ".remove_outside_collaborator", :vcr do 94 it "removes the outside collaborator from an organization" do 95 stub_delete github_url("/orgs/#{test_github_org}/outside_collaborators/#{test_github_login}") 96 @client.remove_outside_collaborator(test_github_org, test_github_login) 97 assert_requested :delete, github_url("/orgs/#{test_github_org}/outside_collaborators/#{test_github_login}") 98 end 99 end # .remove_outside_collaborator 100 101 describe ".convert_to_outside_collaborator", :vcr do 102 it "converts an organization member to an outside collaborator" do 103 stub_put github_url("orgs/#{test_github_org}/outside_collaborators/#{test_github_login}") 104 @client.convert_to_outside_collaborator(test_github_org, test_github_login) 105 assert_requested :put, github_url("orgs/#{test_github_org}/outside_collaborators/#{test_github_login}") 106 end 107 end # .convert_to_outside_collaborator 108 109 describe ".organization_teams", :vcr do 110 it "returns all teams for an organization" do 111 teams = @client.organization_teams(test_github_org) 112 expect(teams).to be_kind_of Array 113 assert_requested :get, github_url("/orgs/#{test_github_org}/teams") 114 end 115 end # .organization_teams 116 117 describe ".child_teams", :vcr do 118 it "returns all child teams for the team" do 119 child_teams = @client.child_teams(test_github_team_id, accept: Octokit::Preview::PREVIEW_TYPES[:nested_teams]) 120 expect(child_teams).to be_kind_of Array 121 assert_requested :get, github_url("/teams/#{test_github_team_id}/teams") 122 end 123 end # .child_teams 124 125 context "with team", :order => :defined do 126 before(:each) do 127 @team_name = "Test Team #{Time.now.to_i}" 128 @team = @client.create_team(test_github_org, {:name => @team_name}) 129 use_vcr_placeholder_for(@team.id, "<GITHUB_TEST_ORG_TEAM_ID>") 130 end 131 132 after(:each) do 133 @client.delete_team(@team.id) 134 end 135 136 describe ".create_team", :vcr do 137 it "creates a team" do 138 assert_requested :post, github_url("/orgs/#{test_github_org}/teams") 139 end 140 end # .create_team 141 142 describe ".team", :vcr do 143 it "returns a team" do 144 team = @client.team(@team.id) 145 expect(team.id).to eq(@team.id) 146 assert_requested :get, github_url("/teams/#{@team.id}") 147 end 148 end # .team 149 150 describe ".team_by_name", :vcr do 151 it "returns a team found by name" do 152 team = @client.team_by_name(test_github_org, @team.slug) 153 expect(team.id).to eq(@team.id) 154 assert_requested :get, github_url("/orgs/#{test_github_org}/teams/#{@team.slug}") 155 end 156 end # .team_by_name 157 158 describe ".update_team", :vcr do 159 it "updates a team" do 160 @client.update_team(@team.id, :name => "API Jedi") 161 assert_requested :patch, github_url("/teams/#{@team.id}") 162 end 163 end # .update_team 164 165 describe ".team_members", :vcr do 166 it "returns team members" do 167 users = @client.team_members(@team.id) 168 expect(users).to be_kind_of Array 169 assert_requested :get, github_url("/teams/#{@team.id}/members") 170 end 171 end # .team_members 172 173 describe ".add_team_member", :vcr do 174 it "adds a team member" do 175 @client.add_team_member(@team.id, test_github_repository) 176 assert_requested :put, github_url("/teams/#{@team.id}/members/#{test_github_repository}") 177 end 178 end # .add_team_member 179 180 describe ".remove_team_member", :vcr do 181 it "removes a team member" do 182 @client.remove_team_member(@team.id, "api-padawan") 183 assert_requested :delete, github_url("/teams/#{@team.id}/members/api-padawan") 184 end 185 end # .remove_team_member 186 187 describe ".team_member?", :vcr do 188 it "checks if a user is member of a team" do 189 @client.team_member?(@team.id, 'api-padawan') 190 assert_requested :get, github_url("/teams/#{@team.id}/members/api-padawan") 191 end 192 end # .team_member? 193 194 describe ".team_invitations", :vcr do 195 it "lists pending team invitations" do 196 @client.team_invitations(@team.id) 197 assert_requested :get, github_url("/teams/#{@team.id}/invitations") 198 end 199 end # .team_invitations 200 201 describe ".team_repositories", :vcr do 202 it "returns team repositories" do 203 repositories = @client.team_repositories(@team.id) 204 expect(repositories).to be_kind_of Array 205 assert_requested :get, github_url("/teams/#{@team.id}/repos") 206 end 207 end # .team_repositories 208 209 describe ".add_team_repository", :vcr do 210 it "adds a team repository" do 211 @client.add_team_repository(@team.id, @test_org_repo) 212 assert_requested :put, github_url("/teams/#{@team.id}/repos/#{@test_org_repo}") 213 end 214 end # .add_team_repository 215 216 describe ".team_repository?", :vcr do 217 it "checks if a repo is managed by a specific team" do 218 is_team_repo = @client.team_repository?(@team.id, "#{test_github_org}/notateamrepository") 219 expect(is_team_repo).to be false 220 assert_requested :get, github_url("/teams/#{@team.id}/repos/#{test_github_org}/notateamrepository") 221 end 222 end 223 224 describe ".remove_team_repository", :vcr do 225 it "removes a team repository" do 226 @client.remove_team_repository @team.id, @test_org_repo 227 assert_requested :delete, github_url("/teams/#{@team.id}/repos/#{@test_org_repo}") 228 end 229 end #.remove_team_repository 230 231 describe ".delete_team", :vcr do 232 it "deletes a team" do 233 @client.delete_team(@team.id) 234 assert_requested :delete, github_url("/teams/#{@team.id}") 235 end 236 end # .delete_team 237 end # with team 238 239 context "public org members", :order => :defined do 240 describe ".unpublicize_membership", :vcr do 241 it "unpublicizes membership" do 242 @client.unpublicize_membership test_github_org, test_github_login 243 assert_requested :delete, github_url("/orgs/#{test_github_org}/public_members/#{test_github_login}") 244 end 245 end # .unpublicize_membership 246 247 describe ".publicize_membership", :vcr do 248 it "publicizes membership" do 249 @client.publicize_membership test_github_org, test_github_login 250 assert_requested :put, github_url("/orgs/#{test_github_org}/public_members/#{test_github_login}") 251 end 252 end # .publicize_membership 253 254 describe ".organization_public_member?", :vcr do 255 it "checks publicized org membership" do 256 is_member = @client.organization_public_member?(test_github_org, test_github_login) 257 expect(is_member).to be true 258 assert_requested :get, github_url("/orgs/#{test_github_org}/public_members/#{test_github_login}") 259 end 260 end # .organization_public_member? 261 end # public org members 262 263 describe ".remove_organization_member" do 264 it "removes a member from an organization" do 265 stub_delete github_url("/orgs/api-playground/members/api-padawan") 266 @client.remove_organization_member("api-playground", "api-padawan") 267 assert_requested :delete, github_url("/orgs/api-playground/members/api-padawan") 268 end 269 end # .remove_organization_member 270 271 describe ".user_teams", :vcr do 272 it "lists all teams for the authenticated user" do 273 teams = @client.user_teams 274 assert_requested :get, github_url("/user/teams") 275 expect(teams).to be_kind_of(Array) 276 end 277 end # .user_teams 278 279 describe ".add_team_membership", :vcr do 280 it "invites a user to a team" do 281 membership = @client.add_team_membership(test_github_team_id, test_github_login) 282 assert_requested :put, github_url("teams/#{test_github_team_id}/memberships/#{test_github_login}") 283 expect(membership.state).to eq("active") 284 end 285 end # .add_team_membership 286 287 describe ".team_membership", :vcr do 288 it "gets a user's team membership" do 289 membership = @client.team_membership(test_github_team_id, test_github_login) 290 assert_requested :get, github_url("teams/#{test_github_team_id}/memberships/#{test_github_login}") 291 expect(membership.state).to eq("active") 292 end 293 end # .team_membership 294 295 describe ".remove_team_membership", :vcr do 296 it "removes a user's membership for a team" do 297 result = @client.remove_team_membership(test_github_team_id, test_github_login) 298 assert_requested :delete, github_url("teams/#{test_github_team_id}/memberships/#{test_github_login}") 299 expect(result).to be true 300 end 301 end # .remove_team_membership 302 303 describe ".organization_memberships", :vcr do 304 it "returns all organization memberships for the user" do 305 memberships = @client.organization_memberships 306 expect(memberships).to be_kind_of Array 307 assert_requested :get, github_url("/user/memberships/orgs") 308 end 309 end # .organization_memberships 310 311 describe ".remove_organization_membership", :vcr do 312 it "removes an organization membership for a given user" do 313 stub_delete github_url("orgs/#{test_github_org}/memberships/#{test_github_login}") 314 @client.remove_organization_membership( 315 test_github_org, 316 :user => test_github_login, 317 :accept => "application/vnd.github.moondragon+json" 318 ) 319 assert_requested :delete, github_url("/orgs/#{test_github_org}/memberships/#{test_github_login}") 320 end 321 end 322 323 describe ".organization_membership", :vcr do 324 it "returns an organization membership" do 325 stub_get github_url("/user/memberships/orgs/#{test_github_org}") 326 membership = @client.organization_membership(test_github_org) 327 assert_requested :get, github_url("/user/memberships/orgs/#{test_github_org}") 328 end 329 330 it "returns an organization membership for a given user" do 331 stub_get github_url("orgs/#{test_github_org}/memberships/#{test_github_login}") 332 @client.organization_membership( 333 test_github_org, 334 :user => test_github_login, 335 :accept => "application/vnd.github.moondragon+json" 336 ) 337 assert_requested :get, github_url("/orgs/#{test_github_org}/memberships/#{test_github_login}") 338 end 339 340 it "returns an organization membership for a given user by the orgs id" do 341 org_id = 42 342 stub_get github_url("organizations/#{org_id}/memberships/#{test_github_login}") 343 @client.organization_membership( 344 org_id, 345 :user => test_github_login, 346 :accept => "application/vnd.github.moondragon+json" 347 ) 348 assert_requested :get, github_url("/organizations/#{org_id}/memberships/#{test_github_login}") 349 end 350 end # .organization_membership 351 352 describe ".update_organization_membership", :vcr do 353 it "updates an organization membership" do 354 membership = @client.update_organization_membership(test_github_org, {:state => 'active'}) 355 assert_requested :patch, github_url("/user/memberships/orgs/#{test_github_org}") 356 end 357 358 it "adds or updates an organization membership for a given user" do 359 @client.update_organization_membership( 360 test_github_org, 361 :user => test_github_collaborator_login, 362 :role => "member", 363 ) 364 assert_requested :put, github_url("/orgs/#{test_github_org}/memberships/#{test_github_collaborator_login}") 365 end 366 end # .update_organization_membership 367 368 describe ".migrations", :vcr do 369 it "starts a migration for an organization" do 370 result = @client.start_migration(test_github_org, ["github-api/api-playground"], accept: preview_header) 371 expect(result).to be_kind_of Sawyer::Resource 372 assert_requested :post, github_url("/orgs/#{test_github_org}/migrations") 373 end 374 375 it "lists migrations for an organization" do 376 result = @client.migrations(test_github_org, accept: preview_header) 377 expect(result).to be_kind_of Array 378 assert_requested :get, github_url("/orgs/#{test_github_org}/migrations") 379 end 380 381 it "gets the status of a migration" do 382 result = @client.migration_status(test_github_org, 97, accept: preview_header) 383 expect(result).to be_kind_of Sawyer::Resource 384 assert_requested :get, github_url("/orgs/#{test_github_org}/migrations/97") 385 end 386 387 it "downloads a migration archive" do 388 result = @client.migration_archive_url(test_github_org, 97, accept: preview_header) 389 expect(result).to be_kind_of String 390 assert_requested :get, github_url("/orgs/#{test_github_org}/migrations/97/archive") 391 end 392 393 it "unlocks a migrated repository" do 394 @client.unlock_repository(test_github_org, 97, 'api-playground', accept: preview_header) 395 expect(@client.last_response.status).to eq(204) 396 assert_requested :delete, github_url("/orgs/#{test_github_org}/migrations/97/repos/api-playground/lock") 397 end 398 end # .migrations 399 400 describe ".billing_actions", :vcr do 401 it "returns github actions billing for organization" do 402 billing_actions = @client.billing_actions(test_github_org) 403 expect(billing_actions.total_minutes_used).to be_kind_of(Integer) 404 assert_requested :get, github_url("/orgs/#{test_github_org}/settings/billing/actions") 405 end 406 end 407 408 private 409 410 def preview_header 411 Octokit::Preview::PREVIEW_TYPES[:migrations] 412 end 413end