Skip to content

Commit

Permalink
Test #failing_required_builds?
Browse files Browse the repository at this point in the history
  • Loading branch information
cheshire137 committed Nov 26, 2024
1 parent 6e7df2b commit 48feba5
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/lib/project_pull_mover/pull_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,44 @@ module ProjectPullMover
end
end

describe "#failing_required_builds?" do
it "returns true when a required check suite is failing on the last commit" do
pull = PullRequest.new({}, options: @options, project: @project, gh_cli: @gh_cli)
pull.set_graphql_data({"pullRequest" => {"commits" => {"nodes" => [{"commit" => {
"checkSuites" => {"nodes" => [{"checkRuns" => {"nodes" => [{"isRequired" => true}]}}]},
}}]}}})
assert_predicate pull, :failing_required_builds?
end

it "returns true when a required status is failing on the last commit" do
pull = PullRequest.new({}, options: @options, project: @project, gh_cli: @gh_cli)
pull.set_graphql_data({"pullRequest" => {"commits" => {"nodes" => [{"commit" => {
"status" => {"contexts" => [{"isRequired" => true, "state" => "FAILURE"}]},
}}]}}})
assert_predicate pull, :failing_required_builds?
end

it "returns false when last commit check suites have no check runs and status has no contexts" do
pull = PullRequest.new({}, options: @options, project: @project, gh_cli: @gh_cli)
pull.set_graphql_data({"pullRequest" => {"commits" => {"nodes" => [{"commit" => {
"checkSuites" => {"nodes" => [{"checkRuns" => {"nodes" => []}}]},
"status" => {"contexts" => []},
}}]}}})
refute_predicate pull, :failing_required_builds?
end

it "returns false when no last commit is known" do
pull = PullRequest.new({}, options: @options, project: @project, gh_cli: @gh_cli)
pull.set_graphql_data({"pullRequest" => {"commits" => {"nodes" => []}}})
refute_predicate pull, :failing_required_builds?
end

it "returns false when GraphQL data has not been set" do
pull = PullRequest.new({}, options: @options, project: @project, gh_cli: @gh_cli)
refute_predicate pull, :failing_required_builds?
end
end

describe "#failing_required_check_suites?" do
it "returns true when a required check suite is failing on the last commit" do
pull = PullRequest.new({}, options: @options, project: @project, gh_cli: @gh_cli)
Expand Down Expand Up @@ -286,6 +324,14 @@ module ProjectPullMover
refute_predicate pull, :failing_required_statuses?
end

it "returns false when last commit status has no contexts" do
pull = PullRequest.new({}, options: @options, project: @project, gh_cli: @gh_cli)
pull.set_graphql_data({"pullRequest" => {"commits" => {"nodes" => [{"commit" => {
"status" => {"contexts" => []},
}}]}}})
refute_predicate pull, :failing_required_statuses?
end

it "returns false when no last commit is known" do
pull = PullRequest.new({}, options: @options, project: @project, gh_cli: @gh_cli)
pull.set_graphql_data({"pullRequest" => {"commits" => {"nodes" => []}}})
Expand Down

0 comments on commit 48feba5

Please sign in to comment.