Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iangmaia committed Feb 2, 2024
1 parent 399fa42 commit 32e4ed7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/lib/danger/danger_core/executor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def swiftweekly_issue_89_comments_as_json
allow(fake_client).to receive(:pull_request) { swiftweekly_pr_89_as_json(head_sha, base_sha) }
allow(fake_client).to receive(:get) { swiftweekly_issues_89_as_json }
allow(fake_client).to receive(:issue_comments) { swiftweekly_issue_89_comments_as_json }
allow(fake_client).to receive(:pull_request_comments) { swiftweekly_issue_89_comments_as_json }
allow(fake_client).to receive(:delete_comment) { true }
allow(fake_client).to receive(:create_status) { true }

Expand Down
14 changes: 14 additions & 0 deletions spec/lib/danger/request_sources/github_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@
end

it "creates a comment if no danger comments exist" do
allow(@g.client).to receive(:pull_request_comments).with("artsy/eigen", "800").and_return([])

comments = []
allow(@g.client).to receive(:issue_comments).with("artsy/eigen", "800").and_return(comments)

Expand All @@ -308,6 +310,8 @@
end

it "updates the issue if no danger comments exist" do
allow(@g.client).to receive(:pull_request_comments).with("artsy/eigen", "800").and_return([])

comments = [{ "body" => '"generated_by_danger"', "id" => "12" }]
allow(@g.client).to receive(:issue_comments).with("artsy/eigen", "800").and_return(comments)

Expand All @@ -318,6 +322,8 @@
end

it "creates a new comment instead of updating the issue if --new-comment is provided" do
allow(@g.client).to receive(:pull_request_comments).with("artsy/eigen", "800").and_return([])

comments = [{ "body" => '"generated_by_danger"', "id" => "12" }]
allow(@g.client).to receive(:issue_comments).with("artsy/eigen", "800").and_return(comments)

Expand All @@ -328,6 +334,8 @@
end

it "updates the issue if no danger comments exist and a custom danger_id is provided" do
allow(@g.client).to receive(:pull_request_comments).with("artsy/eigen", "800").and_return([])

comments = [{ "body" => '"generated_by_another_danger"', "id" => "12" }]
allow(@g.client).to receive(:issue_comments).with("artsy/eigen", "800").and_return(comments)

Expand All @@ -338,6 +346,8 @@
end

it "deletes existing comments if danger doesnt need to say anything" do
allow(@g.client).to receive(:pull_request_comments).with("artsy/eigen", "800").and_return([])

comments = [{ "body" => '"generated_by_danger"', "id" => "12" }]
allow(@g.client).to receive(:issue_comments).with("artsy/eigen", "800").and_return(comments)

Expand All @@ -348,6 +358,8 @@
end

it "deletes existing comments if danger doesnt need to say anything and a custom danger_id is provided" do
allow(@g.client).to receive(:pull_request_comments).with("artsy/eigen", "800").and_return([])

comments = [{ "body" => '"generated_by_another_danger"', "id" => "12" }]
allow(@g.client).to receive(:issue_comments).with("artsy/eigen", "800").and_return(comments)
expect(@g.client).to receive(:delete_comment).with("artsy/eigen", "12").and_return({})
Expand Down Expand Up @@ -402,6 +414,8 @@
end

it "deletes all inline comments if there are no violations at all" do
allow(@g.client).to receive(:pull_request_comments).with("artsy/eigen", "800").and_return([])

allow(@g.client).to receive(:delete_comment).with("artsy/eigen", main_issue_id)
allow(@g.client).to receive(:delete_comment).with("artsy/eigen", inline_issue_id_1)
allow(@g.client).to receive(:delete_comment).with("artsy/eigen", inline_issue_id_2)
Expand Down

0 comments on commit 32e4ed7

Please sign in to comment.