Commit 9b4291a5 authored by Philip Cunningham's avatar Philip Cunningham

Use enriched id type in on-demand scan mutation

Swaps ID for DastSiteProfileID in create mutation.
parent 2acd7ff3
......@@ -2319,7 +2319,7 @@ input DastOnDemandScanCreateInput {
"""
ID of the site profile to be used for the scan.
"""
dastSiteProfileId: ID!
dastSiteProfileId: DastSiteProfileID!
"""
The project the site profile belongs to.
......
......@@ -6212,7 +6212,7 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"name": "DastSiteProfileID",
"ofType": null
}
},
mutation dastOnDemandScanCreate($fullPath: ID!, $dastSiteProfileId: ID!) {
mutation dastOnDemandScanCreate($fullPath: ID!, $dastSiteProfileId: DastSiteProfileID!) {
dastOnDemandScanCreate(input: { fullPath: $fullPath, dastSiteProfileId: $dastSiteProfileId }) {
pipelineUrl
errors
......
......@@ -17,7 +17,7 @@ module Mutations
required: true,
description: 'The project the site profile belongs to.'
argument :dast_site_profile_id, GraphQL::ID_TYPE,
argument :dast_site_profile_id, ::Types::GlobalIDType[::DastSiteProfile],
required: true,
description: 'ID of the site profile to be used for the scan.'
......@@ -47,14 +47,10 @@ module Mutations
end
def find_dast_site_profile(project:, dast_site_profile_id:)
global_id = GlobalID.parse(dast_site_profile_id)
raise InvalidGlobalID.new('Incorrect class') unless global_id.model_class == DastSiteProfile
project
.dast_site_profiles
.with_dast_site
.find(global_id.model_id)
.find(dast_site_profile_id.model_id)
end
def success_response(project:, pipeline:)
......
......@@ -90,14 +90,6 @@ RSpec.describe Mutations::DastOnDemandScans::Create do
expect(actual_url).to eq(expected_url)
end
context 'when the wrong type of gid is used' do
let(:dast_site_profile_id) { project.to_global_id }
it 'raises an exception' do
expect { subject }.to raise_error(described_class::InvalidGlobalID)
end
end
context 'when the dast_site_profile does not exist' do
it 'raises an exception' do
dast_site_profile.destroy!
......
......@@ -53,6 +53,26 @@ RSpec.describe 'Running a DAST Scan' do
expect(mutation_response['pipelineUrl']).to eq(expected_url)
end
context 'when wrong type of global id is passed' do
let(:mutation) do
graphql_mutation(
:dast_on_demand_scan_create,
full_path: full_path,
dast_site_profile_id: dast_site_profile.dast_site.to_global_id.to_s
)
end
it_behaves_like 'a mutation that returns top-level errors' do
let(:match_errors) do
gid = dast_site_profile.dast_site.to_global_id
eq(["Variable $dastOnDemandScanCreateInput of type DastOnDemandScanCreateInput! " \
"was provided invalid value for dastSiteProfileId (\"#{gid}\" does not " \
"represent an instance of DastSiteProfile)"])
end
end
end
context 'when pipeline creation fails' do
before do
allow_any_instance_of(Ci::Pipeline).to receive(:created_successfully?).and_return(false)
......
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