spec/bugsnag/api/client/projects_spec.rb in bugsnag-api-1.0.3 vs spec/bugsnag/api/client/projects_spec.rb in bugsnag-api-2.0.0
- old
+ new
@@ -1,87 +1,63 @@
require "spec_helper"
describe Bugsnag::Api::Client::Projects do
before do
+ @client = auth_token_client
+ @org_id = test_bugsnag_org_id
Bugsnag::Api.reset!
- @client = basic_auth_client
end
- describe ".account_projects", :vcr do
- context "when using account credentials" do
- it "returns all projects" do
- client = auth_token_client
- projects = client.account_projects
- expect(projects).to be_kind_of(Array)
- expect(projects.first.name).not_to be_nil
-
- assert_requested :get, bugsnag_url("/account/projects")
- end
- end
-
- context "when using user credentials" do
- it "raises an error" do
- expect { @client.account_projects }.to raise_error Bugsnag::Api::AccountCredentialsRequired
-
- assert_not_requested :get, basic_bugsnag_url("/account/projects")
- end
- end
-
- it "returns all projects on an account" do
- projects = @client.account_projects(test_bugsnag_account)
- expect(projects).to be_kind_of(Array)
- expect(projects.first.name).not_to be_nil
-
- assert_requested :get, basic_bugsnag_url("/accounts/#{test_bugsnag_account}/projects")
- end
- end
-
- describe ".user_projects", :vcr do
- it "returns all projects for a user" do
- projects = @client.user_projects(test_bugsnag_user)
- expect(projects).to be_kind_of(Array)
- expect(projects.first.name).not_to be_nil
-
- assert_requested :get, basic_bugsnag_url("/users/#{test_bugsnag_user}/projects")
- end
- end
-
describe ".create_project", :vcr do
- it "creates a project on an account" do
- project = @client.create_project(test_bugsnag_account, :name => "Example")
- expect(project.name).to eq("Example")
+ it "creates a new project" do
+ new_project = @client.create_project @org_id, "testProject", "other"
+ expect(new_project.name).to eq("testProject")
- assert_requested :post, basic_bugsnag_url("/accounts/#{test_bugsnag_account}/projects")
+ assert_requested :post, bugsnag_url("/organizations/#{@org_id}/projects")
end
end
- context "with project", :vcr do
+ context "given a project", :vcr do
before do
- @project = @client.create_project(test_bugsnag_account, :name => "Example")
+ @project = @client.create_project @org_id, "testProject", "other"
end
- describe ".project" do
- it "returns a project" do
- project = @client.project(@project.id)
+ describe ".project", :vcr do
+ it "returns the requested project" do
+ project = @client.project @project.id
expect(project.id).to eq(@project.id)
+ expect(project.name).to eq("testProject")
- assert_requested :get, basic_bugsnag_url("/projects/#{@project.id}")
+ assert_requested :get, bugsnag_url("/projects/#{@project.id}")
end
end
- describe ".update_project" do
- it "updates an existing project" do
- updated_project = @client.update_project(@project.id, :name => "New project name")
+ describe ".update_project", :vcr do
+ it "updates and returns the project" do
+ updated_project = @client.update_project @project.id, {:name => "otherName"}
expect(updated_project.id).to eq(@project.id)
- assert_requested :patch, basic_bugsnag_url("/projects/#{@project.id}")
+ expect(updated_project.name).to eq("otherName")
+
+ assert_requested :patch, bugsnag_url("/projects/#{@project.id}")
end
end
- describe ".delete_project" do
- it "deletes an existing project" do
- response = @client.delete_project(@project.id)
- expect(response).to be true
- assert_requested :delete, basic_bugsnag_url("/projects/#{@project.id}")
+ describe ".regenerate_api_key", :vcr do
+ it "removes the current api key and replaces it with a new api key" do
+ updated_project = @client.regenerate_api_key @project.id
+ expect(updated_project.id).to eq(@project.id)
+ expect(updated_project.api_key).not_to eq(@project.api_key)
+
+ assert_requested :delete, bugsnag_url("/projects/#{@project.id}/api_key")
+ end
+ end
+
+ describe ".delete_project", :vcr do
+ it "deletes the project" do
+ deleted_project = @client.delete_project @project.id
+ expect(deleted_project).to be true
+
+ assert_requested :delete, bugsnag_url("/projects/#{@project.id}")
end
end
end
end