diff --git a/app/services/incident_management/timeline_events/update_service.rb b/app/services/incident_management/timeline_events/update_service.rb index 8217c8125c20af1be05bd85e34b7cf6ab3b3db72..5c5de4717bc159d465bb27be925422111985cad5 100644 --- a/app/services/incident_management/timeline_events/update_service.rb +++ b/app/services/incident_management/timeline_events/update_service.rb @@ -34,7 +34,7 @@ def execute attr_reader :timeline_event, :incident, :user, :note, :occurred_at def update_params - { updated_by_user: user, note: note.presence, occurred_at: occurred_at.presence }.compact + { updated_by_user: user, note: note, occurred_at: occurred_at }.compact end def add_system_note(timeline_event) diff --git a/spec/graphql/mutations/incident_management/timeline_event/update_spec.rb b/spec/graphql/mutations/incident_management/timeline_event/update_spec.rb index 8296e5c6c156f491149008d8dffeb7536ad90df3..102d33378c6f083f1c7998270a300e436823e8af 100644 --- a/spec/graphql/mutations/incident_management/timeline_event/update_spec.rb +++ b/spec/graphql/mutations/incident_management/timeline_event/update_spec.rb @@ -57,17 +57,40 @@ end context 'when there is a validation error' do - let(:occurred_at) { 'invalid date' } + context 'when note is blank' do + let(:note) { '' } - it 'does not update the timeline event' do - expect { resolve }.not_to change { timeline_event.reload.updated_at } + it 'does not update the timeline event' do + expect { resolve }.not_to change { timeline_event.reload.updated_at } + end + + it 'responds with error' do + expect(resolve).to eq(timeline_event: nil, errors: ["Note can't be blank"]) + end end - it 'responds with error' do - expect(resolve).to eq( - timeline_event: nil, - errors: ["Occurred at can't be blank"] - ) + context 'when occurred_at is blank' do + let(:occurred_at) { '' } + + it 'does not update the timeline event' do + expect { resolve }.not_to change { timeline_event.reload.updated_at } + end + + it 'responds with error' do + expect(resolve).to eq(timeline_event: nil, errors: ["Occurred at can't be blank"]) + end + end + + context 'when occurred_at is invalid' do + let(:occurred_at) { 'invalid date' } + + it 'does not update the timeline event' do + expect { resolve }.not_to change { timeline_event.reload.updated_at } + end + + it 'responds with error' do + expect(resolve).to eq(timeline_event: nil, errors: ["Occurred at can't be blank"]) + end end end end diff --git a/spec/services/incident_management/timeline_events/update_service_spec.rb b/spec/services/incident_management/timeline_events/update_service_spec.rb index 728f2fa3e9df801818eb0671f7009aa56400d88d..f612c72e2a8649a987893423a7c7223e75c5fd61 100644 --- a/spec/services/incident_management/timeline_events/update_service_spec.rb +++ b/spec/services/incident_management/timeline_events/update_service_spec.rb @@ -32,6 +32,10 @@ expect(execute.message).to eq(message) end + it 'does not update the note' do + expect { execute }.not_to change { timeline_event.reload.note } + end + it_behaves_like 'does not track incident management event', :incident_management_timeline_event_edited end @@ -94,16 +98,7 @@ context 'when note is blank' do let(:params) { { note: '', occurred_at: occurred_at } } - it_behaves_like 'successful response' - it_behaves_like 'passing the correct was_changed value', :occurred_at - - it 'does not update the note' do - expect { execute }.not_to change { timeline_event.reload.note } - end - - it 'updates occurred_at' do - expect { execute }.to change { timeline_event.occurred_at }.to(params[:occurred_at]) - end + it_behaves_like 'error response', "Note can't be blank" end context 'when occurred_at is nil' do @@ -121,6 +116,12 @@ end end + context 'when occurred_at is blank' do + let(:params) { { note: 'Updated note', occurred_at: '' } } + + it_behaves_like 'error response', "Occurred at can't be blank" + end + context 'when both occurred_at and note is nil' do let(:params) { {} }