Skip to content

Commit

Permalink
Test #graphql_field
Browse files Browse the repository at this point in the history
  • Loading branch information
cheshire137 committed Nov 26, 2024
1 parent 02b3b66 commit ad9877e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test/lib/project_pull_mover/pull_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module ProjectPullMover
@project_number = 123
@project_owner = "someUser"
@failing_test_label = "testfailure"
argv = ["-p", @project_number.to_s, "-o", @project_owner, "-t", "user", "-s", "StatusField", "-i",
@status_field = "StatusField"
argv = ["-p", @project_number.to_s, "-o", @project_owner, "-t", "user", "-s", @status_field, "-i",
"MyInProgressID", "-h", "gh", "-f", @failing_test_label, "-a", "notAgainstMainId", "-n", "needsReviewId",
"-r", "ReadyToDeployId", "-c", "Conflicting_id", "-g", "ignoredId1,ignoredId2", "-m"]
@options = Options.parse(file: "project_pull_mover.rb", argv: argv, logger: @logger)
Expand Down Expand Up @@ -198,5 +199,29 @@ module ProjectPullMover
assert_equal "pull1", pull.graphql_field_alias
end
end

describe "#graphql_field" do
it "returns a field for a GraphQL query using repo details and number" do
initial_data = {"content" => {"repository" => "someone/some-repo", "number" => 123}}
pull = PullRequest.new(initial_data, options: @options, project: @project, gh_cli: @gh_cli)

result = pull.graphql_field

assert_includes result, "pullSomeoneSomeRepo123: repository(owner: \"someone\", name: \"some-repo\") {"
assert_includes result, "pullRequest(number: 123) {"
assert_includes result, "isRequired(pullRequestNumber: 123)"
assert_includes result, "fieldValueByName(name: \"#{@status_field}\") {"
end

it "raises error when repo details or number are missing" do
pull = PullRequest.new({}, options: @options, project: @project, gh_cli: @gh_cli)

error = assert_raises(PullRequest::MissingRequiredDataError) do
pull.graphql_field
end

assert_equal "Unable to build GraphQL field for pull request, missing required data", error.message
end
end
end
end

0 comments on commit ad9877e

Please sign in to comment.