Commit 0568c5e3 authored by Philip Cunningham's avatar Philip Cunningham Committed by Ash McKenzie

Add editPath to DastSiteProfileType for GraphQL

Allows frontend to get relative path to edit page.
parent ad6947bb
...@@ -2746,6 +2746,11 @@ type DastScannerProfileEdge { ...@@ -2746,6 +2746,11 @@ type DastScannerProfileEdge {
Represents a DAST Site Profile. Represents a DAST Site Profile.
""" """
type DastSiteProfile { type DastSiteProfile {
"""
Relative web path to the edit page of a site profile
"""
editPath: String
""" """
ID of the site profile ID of the site profile
""" """
......
...@@ -7395,6 +7395,20 @@ ...@@ -7395,6 +7395,20 @@
"name": "DastSiteProfile", "name": "DastSiteProfile",
"description": "Represents a DAST Site Profile.", "description": "Represents a DAST Site Profile.",
"fields": [ "fields": [
{
"name": "editPath",
"description": "Relative web path to the edit page of a site profile",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "id", "name": "id",
"description": "ID of the site profile", "description": "ID of the site profile",
...@@ -453,6 +453,7 @@ Represents a DAST Site Profile. ...@@ -453,6 +453,7 @@ Represents a DAST Site Profile.
| Name | Type | Description | | Name | Type | Description |
| --- | ---- | ---------- | | --- | ---- | ---------- |
| `editPath` | String | Relative web path to the edit page of a site profile |
| `id` | DastSiteProfileID! | ID of the site profile | | `id` | DastSiteProfileID! | ID of the site profile |
| `profileName` | String | The name of the site profile | | `profileName` | String | The name of the site profile |
| `targetUrl` | String | The URL of the target to be scanned | | `targetUrl` | String | The URL of the target to be scanned |
......
...@@ -20,6 +20,12 @@ module Types ...@@ -20,6 +20,12 @@ module Types
description: 'The URL of the target to be scanned', description: 'The URL of the target to be scanned',
resolve: -> (obj, _args, _ctx) { obj.dast_site.url } resolve: -> (obj, _args, _ctx) { obj.dast_site.url }
field :edit_path, GraphQL::STRING_TYPE, null: true,
description: 'Relative web path to the edit page of a site profile',
resolve: -> (obj, _args, _ctx) do
Rails.application.routes.url_helpers.edit_project_dast_site_profile_path(obj.project, obj)
end
field :validation_status, Types::DastSiteProfileValidationStatusEnum, null: true, field :validation_status, Types::DastSiteProfileValidationStatusEnum, null: true,
description: 'The current validation status of the site profile', description: 'The current validation status of the site profile',
resolve: -> (_obj, _args, _ctx) { Types::DastSiteProfileValidationStatusEnum.enum['pending_validation'] } resolve: -> (_obj, _args, _ctx) { Types::DastSiteProfileValidationStatusEnum.enum['pending_validation'] }
......
...@@ -6,7 +6,7 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do ...@@ -6,7 +6,7 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do
let_it_be(:dast_site_profile) { create(:dast_site_profile) } let_it_be(:dast_site_profile) { create(:dast_site_profile) }
let_it_be(:project) { dast_site_profile.project } let_it_be(:project) { dast_site_profile.project }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:fields) { %i[id profileName targetUrl validationStatus userPermissions] } let_it_be(:fields) { %i[id profileName targetUrl editPath validationStatus userPermissions] }
subject do subject do
GitlabSchema.execute( GitlabSchema.execute(
...@@ -44,6 +44,7 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do ...@@ -44,6 +44,7 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do
id id
profileName profileName
targetUrl targetUrl
editPath
validationStatus validationStatus
} }
} }
...@@ -74,10 +75,28 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do ...@@ -74,10 +75,28 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do
end end
end end
describe 'edit_path field' do
it 'is the relative path to edit the dast_site_profile' do
path = "/#{project.full_path}/-/on_demand_scans/profiles/dast_site_profiles/#{dast_site_profile.id}/edit"
expect(first_dast_site_profile['editPath']).to eq(path)
end
end
describe 'validation_status field' do describe 'validation_status field' do
it 'is a placeholder validation status' do it 'is a placeholder validation status' do
expect(first_dast_site_profile['validationStatus']).to eq('PENDING_VALIDATION') expect(first_dast_site_profile['validationStatus']).to eq('PENDING_VALIDATION')
end end
end end
context 'when there are no dast_site_profiles' do
let(:project) { create(:project) }
it 'has no nodes' do
nodes = subject.dig('data', 'project', 'dastSiteProfiles', 'nodes')
expect(nodes).to be_empty
end
end
end end
end end
...@@ -21,6 +21,7 @@ RSpec.describe 'Query.project(fullPath).dastSiteProfiles' do ...@@ -21,6 +21,7 @@ RSpec.describe 'Query.project(fullPath).dastSiteProfiles' do
id id
profileName profileName
targetUrl targetUrl
editPath
validationStatus validationStatus
} }
} }
......
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