spec/bugsnag/api/client/comments_spec.rb in bugsnag-api-1.0.3 vs spec/bugsnag/api/client/comments_spec.rb in bugsnag-api-2.0.0

- old
+ new

@@ -1,58 +1,70 @@ require "spec_helper" describe Bugsnag::Api::Client::Comments do before do + @client = auth_token_client + @project_id = test_bugsnag_project_id + @error_id = test_bugsnag_error_id Bugsnag::Api.reset! - @client = basic_auth_client end - describe ".comments", :vcr do - it "returns all comments on an error" do - comments = @client.comments(test_bugsnag_error) - expect(comments).to be_kind_of(Array) - expect(comments.first.message).not_to be_nil - - assert_requested :get, basic_bugsnag_url("/errors/#{test_bugsnag_error}/comments") - end - end - describe ".create_comment", :vcr do - it "created a comment" do - comment = @client.create_comment(test_bugsnag_error, "Comment message") - expect(comment.message).to eq("Comment message") + it "creates a comment on the error" do + comment = @client.create_comment @project_id, @error_id, "test_message" + expect(comment.message).to eq("test_message") + expect(comment.id).to_not be_nil - assert_requested :post, basic_bugsnag_url("/errors/#{test_bugsnag_error}/comments") + assert_requested :post, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}/comments") end end - context "with comment", :vcr do + context "given a comment has been created" do before do - @comment = @client.create_comment(test_bugsnag_error, "Comment message") + @comment = @client.create_comment @project_id, @error_id, "message" end - describe ".comment" do - it "returns a comment" do - comment = @client.comment(@comment.id) + describe ".comments", :vcr do + it "retrieves all comments on an error" do + comments = @client.comments @project_id, @error_id + + expect(comments).to be_kind_of(Array) + expect(comments.first.message).to_not be_nil + + assert_requested :get, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}/comments") + end + end + + describe ".comment", :vcr do + it "retrieves the comment specified" do + comment = @client.comment @comment.id + + expect(comment.message).to eq("message") expect(comment.id).to eq(@comment.id) - assert_requested :get, basic_bugsnag_url("/comments/#{@comment.id}") + assert_requested :get, bugsnag_url("/comments/#{@comment.id}") end end - describe ".update_comment" do - it "updates an existing comment" do - updated_comment = @client.update_comment(@comment.id, "Example new message") - expect(updated_comment.id).to eq(@comment.id) - assert_requested :patch, basic_bugsnag_url("/comments/#{@comment.id}") + describe ".update_comment", :vcr do + it "updates the message on a comment" do + comment = @client.update_comment @comment.id, "updated" + + expect(comment.message).to eq("updated") + expect(comment.id).to eq(@comment.id) + + assert_requested :patch, bugsnag_url("/comments/#{@comment.id}") end end - describe ".delete_comment" do - it "deletes an existing comment" do - response = @client.delete_comment(@comment.id) + describe ".delete_comment", :vcr do + it "deletes the comment and returns true" do + stub_request(:delete, bugsnag_url("/comments/#{@comment.id}")).to_return(:status => [204, "No Content"]) + + response = @client.delete_comment @comment.id expect(response).to be true - assert_requested :delete, basic_bugsnag_url("/comments/#{@comment.id}") + + assert_requested :delete, bugsnag_url("/comments/#{@comment.id}") end end end end