Commit 8288a511 authored by Dan Davison's avatar Dan Davison

Merge branch 'qa-add-assign-iteration-spec' into 'master'

Add ability to use GraphQL for QA resource creation

See merge request gitlab-org/gitlab!39266
parents b19da3b1 61d27f92
......@@ -42,6 +42,38 @@ module QA
new.click_create_iteration_button
end
end
def api_get_path
"gid://gitlab/Iteration/#{id}"
end
def api_post_path
"/graphql"
end
def api_post_body
<<~GQL
mutation {
createIteration(input: {
groupPath: "#{group.full_path}"
title: "#{@title}"
description: "#{@description}"
startDate: "#{@start_date}"
dueDate: "#{@due_date}"
}) {
iteration {
id
title
description
startDate
dueDate
webUrl
}
errors
}
}
GQL
end
end
end
end
......
......@@ -96,15 +96,38 @@ module QA
end
def api_post
response = post(
Runtime::API::Request.new(api_client, api_post_path).url,
api_post_body)
if api_post_path == "/graphql"
graphql_response = post(
Runtime::API::Request.new(api_client, api_post_path).url,
query: api_post_body)
unless response.code == HTTP_STATUS_CREATED
raise ResourceFabricationFailedError, "Fabrication of #{self.class.name} using the API failed (#{response.code}) with `#{response}`."
flattened_response = flatten_hash(parse_body(graphql_response))
unless graphql_response.code == HTTP_STATUS_OK && flattened_response[:errors].empty?
raise ResourceFabricationFailedError, "Fabrication of #{self.class.name} using the API failed (#{graphql_response.code}) with `#{graphql_response}`."
end
flattened_response[:web_url] = flattened_response.delete(:webUrl)
flattened_response[:id] = flattened_response.fetch(:id).split('/')[-1]
process_api_response(flattened_response)
else
response = post(
Runtime::API::Request.new(api_client, api_post_path).url,
api_post_body)
unless response.code == HTTP_STATUS_CREATED
raise ResourceFabricationFailedError, "Fabrication of #{self.class.name} using the API failed (#{response.code}) with `#{response}`."
end
process_api_response(parse_body(response))
end
end
process_api_response(parse_body(response))
def flatten_hash(param)
param.each_pair.reduce({}) do |a, (k, v)|
v.is_a?(Hash) ? a.merge(flatten_hash(v)) : a.merge(k.to_sym => v)
end
end
def api_delete
......
......@@ -34,7 +34,11 @@ module QA
#
# Returns the relative path to the requested API resource
def request_path(path, version: API_VERSION, **query_string)
full_path = ::File.join('/api', version, path)
full_path = if path == '/graphql'
::File.join('/api', path)
else
::File.join('/api', version, path)
end
if query_string.any?
full_path << (path.include?('?') ? '&' : '?')
......
......@@ -3,9 +3,11 @@
module QA
RSpec.describe 'Plan' do
describe 'Assign Iterations' do
let!(:iteration) { EE::Resource::GroupIteration.fabricate_via_api! }
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.group = @iteration.group
project.group = iteration.group
project.name = "project-to-test-iterations-#{SecureRandom.hex(8)}"
end
end
......@@ -22,14 +24,12 @@ module QA
end
it 'assigns a group iteration to an existing issue', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/958' do
@iteration = EE::Resource::GroupIteration.fabricate_via_browser_ui!
issue.visit!
Page::Project::Issue::Show.perform do |issue|
issue.assign_iteration(@iteration)
issue.assign_iteration(iteration)
expect(issue).to have_iteration(@iteration.title)
expect(issue).to have_iteration(iteration.title)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment