diff options
Diffstat (limited to 'spec/graphql/mutations/incident_management/timeline_event/create_spec.rb')
-rw-r--r-- | spec/graphql/mutations/incident_management/timeline_event/create_spec.rb | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/spec/graphql/mutations/incident_management/timeline_event/create_spec.rb b/spec/graphql/mutations/incident_management/timeline_event/create_spec.rb index 9254d84b29c..aab21776a99 100644 --- a/spec/graphql/mutations/incident_management/timeline_event/create_spec.rb +++ b/spec/graphql/mutations/incident_management/timeline_event/create_spec.rb @@ -6,6 +6,9 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::Create do let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:incident) { create(:incident, project: project) } + let_it_be(:timeline_event_tag) do + create(:incident_management_timeline_event_tag, project: project, name: 'Test tag 1') + end let(:args) { { note: 'note', occurred_at: Time.current } } @@ -39,6 +42,104 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::Create do it_behaves_like 'responding with an incident timeline errors', errors: ["Occurred at can't be blank and Timeline text can't be blank"] end + + context 'when timeline event tags are passed' do + let(:args) do + { + note: 'note', + occurred_at: Time.current, + timeline_event_tag_names: [timeline_event_tag.name.to_s] + } + end + + it_behaves_like 'creating an incident timeline event' + end + + context 'when predefined tags are passed' do + let(:args) do + { + note: 'note', + occurred_at: Time.current, + timeline_event_tag_names: ['Start time'] + } + end + + it_behaves_like 'creating an incident timeline event' + + it 'creates and sets the tag on the event' do + timeline_event = resolve[:timeline_event] + + expect(timeline_event.timeline_event_tags.by_names(['Start time']).count).to eq 1 + end + end + + context 'when predefined tags exist' do + let_it_be(:end_time_tag) do + create(:incident_management_timeline_event_tag, project: project, name: 'End time') + end + + let(:args) do + { + note: 'note', + occurred_at: Time.current, + timeline_event_tag_names: ['End time'] + } + end + + it 'does not create a new tag' do + expect { resolve }.not_to change(IncidentManagement::TimelineEventTag, :count) + end + end + + context 'when same tags are tried to be assigned to same timeline event' do + let(:args) do + { + note: 'note', + occurred_at: Time.current, + timeline_event_tag_names: ['Start time', 'Start time'] + } + end + + it 'only assigns the tag once on the event' do + timeline_event = resolve[:timeline_event] + + expect(timeline_event.timeline_event_tags.by_names(['Start time']).count).to eq(1) + expect(timeline_event.timeline_event_tags.count).to eq(1) + end + end + + context 'with case-insentive tags' do + let(:args) do + { + note: 'note', + occurred_at: Time.current, + timeline_event_tag_names: ['tESt tAg 1'] + } + end + + it 'sets the tag on the event' do + timeline_event = resolve[:timeline_event] + + expect(timeline_event.timeline_event_tags.by_names(['Test tag 1']).count).to eq(1) + end + end + + context 'when non-existing tags are passed' do + let(:args) do + { + note: 'note', + occurred_at: Time.current, + timeline_event_tag_names: ['other time'] + } + end + + it_behaves_like 'responding with an incident timeline errors', + errors: ["Following tags don't exist: [\"other time\"]"] + + it 'does not create the timeline event' do + expect { resolve }.not_to change(IncidentManagement::TimelineEvent, :count) + end + end end it_behaves_like 'failing to create an incident timeline event' |