/spec/octokit/client/organizations_spec.rb

http://github.com/pengwynn/octokit · Ruby · 413 lines · 359 code · 54 blank · 0 comment · 19 complexity · 1546629d960adc576a3e1d0fdeccc61a MD5 · raw file

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