Commit a1669a49 authored by Marcos Rocha's avatar Marcos Rocha Committed by Dylan Griffith

Fix issue adding schedule to an existing dast profile

parent cf8bd388
...@@ -99,9 +99,9 @@ module AppSec ...@@ -99,9 +99,9 @@ module AppSec
# params[:dast_profile_schedule] is `Types::Dast::ProfileScheduleInputType` object. # params[:dast_profile_schedule] is `Types::Dast::ProfileScheduleInputType` object.
# Using to_h method to convert object into equivalent hash. # Using to_h method to convert object into equivalent hash.
dast_profile_schedule_params = params[:dast_profile_schedule] dast_profile_schedule_params = params[:dast_profile_schedule]&.to_h
dast_profile_schedule_params[:user_id] = current_user.id unless schedule&.owner_valid? dast_profile_schedule_params[:user_id] = current_user.id unless schedule&.owner_valid?
dast_profile_schedule_params&.to_h dast_profile_schedule_params
end end
def build_auditors! def build_auditors!
......
# frozen_string_literal: true
FactoryBot.define do
factory :dast_profile_schedule_input_type, class: 'Types::Dast::ProfileScheduleInputType' do
context = GraphQL::Query::Context.new(
query: GraphQL::Query.new(GitlabSchema, document: nil, context: {}, variables: {}),
values: {},
object: nil
)
skip_create
arguments = {
active: true,
timezone: ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.identifier }.sample,
startsAt: Time.now,
cadence: { unit: %w(day month year week).sample, duration: 1 }
}
::Types::Dast::ProfileScheduleInputType.to_graphql
initialize_with { ::Types::Dast::ProfileScheduleInputType.new(arguments, defaults_used: [], context: context) }
end
end
...@@ -120,6 +120,29 @@ RSpec.describe Mutations::Dast::Profiles::Update do ...@@ -120,6 +120,29 @@ RSpec.describe Mutations::Dast::Profiles::Update do
end end
end end
context 'when associated dast profile schedule is not present' do
context 'when dast_profile_schedule param is present' do
let(:new_dast_profile_schedule) { create(:dast_profile_schedule_input_type) }
subject do
mutation.resolve(**params.merge(dast_profile_schedule: new_dast_profile_schedule))
end
it 'creates the profile schedule' do
subject
new_schedule = dast_profile.reload.dast_profile_schedule
aggregate_failures do
expect(new_schedule.timezone).to eq(new_dast_profile_schedule[:timezone])
expect(new_schedule.starts_at.to_i).to eq(new_dast_profile_schedule[:starts_at].to_i)
expect(new_schedule.cadence[:duration]).to eq(new_dast_profile_schedule[:cadence].duration)
expect(new_schedule.cadence[:unit]).to eq(new_dast_profile_schedule[:cadence].unit)
end
end
end
end
context 'when run_after_update=true' do context 'when run_after_update=true' do
let(:run_after_update) { true } let(:run_after_update) { true }
......
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