Commit 61d27f92 authored by Desiree Chevalier's avatar Desiree Chevalier

Add GraphQL ability for qa resources

Adds ability to create qa resources with graphql.
Updates iteration resource.
parent deb809c4
...@@ -42,6 +42,38 @@ module QA ...@@ -42,6 +42,38 @@ module QA
new.click_create_iteration_button new.click_create_iteration_button
end end
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 end
end end
......
...@@ -96,15 +96,38 @@ module QA ...@@ -96,15 +96,38 @@ module QA
end end
def api_post def api_post
response = post( if api_post_path == "/graphql"
Runtime::API::Request.new(api_client, api_post_path).url, graphql_response = post(
api_post_body) Runtime::API::Request.new(api_client, api_post_path).url,
query: api_post_body)
unless response.code == HTTP_STATUS_CREATED flattened_response = flatten_hash(parse_body(graphql_response))
raise ResourceFabricationFailedError, "Fabrication of #{self.class.name} using the API failed (#{response.code}) with `#{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
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 end
def api_delete def api_delete
......
...@@ -34,7 +34,11 @@ module QA ...@@ -34,7 +34,11 @@ module QA
# #
# Returns the relative path to the requested API resource # Returns the relative path to the requested API resource
def request_path(path, version: API_VERSION, **query_string) 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? if query_string.any?
full_path << (path.include?('?') ? '&' : '?') full_path << (path.include?('?') ? '&' : '?')
......
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
module QA module QA
RSpec.describe 'Plan' do RSpec.describe 'Plan' do
describe 'Assign Iterations' do describe 'Assign Iterations' do
let!(:iteration) { EE::Resource::GroupIteration.fabricate_via_api! }
let(:project) do let(:project) do
Resource::Project.fabricate_via_api! do |project| Resource::Project.fabricate_via_api! do |project|
project.group = @iteration.group project.group = iteration.group
project.name = "project-to-test-iterations-#{SecureRandom.hex(8)}" project.name = "project-to-test-iterations-#{SecureRandom.hex(8)}"
end end
end end
...@@ -22,14 +24,12 @@ module QA ...@@ -22,14 +24,12 @@ module QA
end end
it 'assigns a group iteration to an existing issue', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/958' do 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! issue.visit!
Page::Project::Issue::Show.perform do |issue| 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 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