1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'getting incident timeline events' do
include GraphqlHelpers
let_it_be(:project) { create(:project) }
let_it_be(:private_project) { create(:project, :private) }
let_it_be(:issue) { create(:issue, project: private_project) }
let_it_be(:current_user) { create(:user) }
let_it_be(:updated_by_user) { create(:user) }
let_it_be(:incident) { create(:incident, project: project) }
let_it_be(:another_incident) { create(:incident, project: project) }
let_it_be(:promoted_from_note) { create(:note, project: project, noteable: incident) }
let_it_be(:issue_url) { project_issue_url(private_project, issue) }
let_it_be(:issue_ref) { "#{private_project.full_path}##{issue.iid}" }
let_it_be(:issue_link) { %Q(<a href="#{issue_url}">#{issue_url}</a>) }
let_it_be(:timeline_event) do
create(
:incident_management_timeline_event,
incident: incident,
project: project,
updated_by_user: updated_by_user,
promoted_from_note: promoted_from_note,
note: "Referencing #{issue.to_reference(full: true)} - Full URL #{issue_url}"
)
end
let_it_be(:second_timeline_event) do
create(:incident_management_timeline_event, incident: incident, project: project)
end
let_it_be(:another_timeline_event) do
create(:incident_management_timeline_event, incident: another_incident, project: project)
end
let(:params) { { incident_id: incident.to_global_id.to_s } }
let(:timeline_event_fields) do
<<~QUERY
nodes {
id
author { id username }
updatedByUser { id username }
incident { id title }
note
noteHtml
promotedFromNote { id body }
editable
action
occurredAt
createdAt
updatedAt
}
QUERY
end
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
query_graphql_field('incidentManagementTimelineEvents', params, timeline_event_fields)
)
end
let(:timeline_events) do
graphql_data.dig('project', 'incidentManagementTimelineEvents', 'nodes')
end
before do
project.add_guest(current_user)
post_graphql(query, current_user: current_user)
end
it_behaves_like 'a working graphql query'
it 'returns the correct number of timeline events' do
expect(timeline_events.count).to eq(2)
end
it 'returns the correct properties of the incident timeline events' do
expect(timeline_events.first).to include(
'author' => {
'id' => timeline_event.author.to_global_id.to_s,
'username' => timeline_event.author.username
},
'updatedByUser' => {
'id' => updated_by_user.to_global_id.to_s,
'username' => updated_by_user.username
},
'incident' => {
'id' => incident.to_global_id.to_s,
'title' => incident.title
},
'note' => timeline_event.note,
'noteHtml' => "<p>Referencing #{issue_ref} - Full URL #{issue_link}</p>",
'promotedFromNote' => {
'id' => promoted_from_note.to_global_id.to_s,
'body' => promoted_from_note.note
},
'editable' => true,
'action' => timeline_event.action,
'occurredAt' => timeline_event.occurred_at.iso8601,
'createdAt' => timeline_event.created_at.iso8601,
'updatedAt' => timeline_event.updated_at.iso8601
)
end
context 'when filtering by id' do
let(:params) { { incident_id: incident.to_global_id.to_s, id: timeline_event.to_global_id.to_s } }
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
query_graphql_field('incidentManagementTimelineEvent', params, 'id occurredAt')
)
end
it_behaves_like 'a working graphql query'
it 'returns a single timeline event', :aggregate_failures do
single_timeline_event = graphql_data.dig('project', 'incidentManagementTimelineEvent')
expect(single_timeline_event).to include(
'id' => timeline_event.to_global_id.to_s,
'occurredAt' => timeline_event.occurred_at.iso8601
)
end
end
end
|