mno-enterprise-api 3.3.1 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/mno_enterprise/config.js.coffee.erb +1 -0
  3. data/app/controllers/mno_enterprise/impersonate_controller.rb +5 -1
  4. data/app/controllers/mno_enterprise/jpi/v1/admin/impac/dashboard_templates_controller.rb +93 -0
  5. data/app/controllers/mno_enterprise/jpi/v1/admin/impac/kpis_controller.rb +71 -0
  6. data/app/controllers/mno_enterprise/jpi/v1/admin/impac/widgets_controller.rb +70 -0
  7. data/app/controllers/mno_enterprise/jpi/v1/impac/dashboard_templates_controller.rb +5 -0
  8. data/app/views/mno_enterprise/auth/confirmations/_form.html.haml +10 -1
  9. data/app/views/mno_enterprise/jpi/v1/admin/base_resource/_member.json.jbuilder +1 -0
  10. data/app/views/mno_enterprise/jpi/v1/admin/impac/dashboard_templates/_template.json.jbuilder +16 -0
  11. data/app/views/mno_enterprise/jpi/v1/admin/impac/dashboard_templates/index.json.jbuilder +1 -0
  12. data/app/views/mno_enterprise/jpi/v1/admin/impac/dashboard_templates/show.json.jbuilder +1 -0
  13. data/app/views/mno_enterprise/jpi/v1/admin/impac/kpis/_kpi.json.jbuilder +2 -0
  14. data/app/views/mno_enterprise/jpi/v1/admin/impac/kpis/show.json.jbuilder +1 -0
  15. data/app/views/mno_enterprise/jpi/v1/admin/impac/widgets/_widget.json.jbuilder +7 -0
  16. data/app/views/mno_enterprise/jpi/v1/admin/impac/widgets/show.json.jbuilder +1 -0
  17. data/app/views/mno_enterprise/jpi/v1/app_feedbacks/_resource.json.jbuilder +1 -0
  18. data/app/views/mno_enterprise/jpi/v1/app_questions/_resource.json.jbuilder +1 -0
  19. data/app/views/mno_enterprise/jpi/v1/current_users/show.json.jbuilder +1 -0
  20. data/app/views/mno_enterprise/jpi/v1/impac/dashboard_templates/index.json.jbuilder +1 -0
  21. data/app/views/mno_enterprise/jpi/v1/impac/kpis/_kpi.json.jbuilder +1 -1
  22. data/app/views/mno_enterprise/pages/loading.html.erb +1 -1
  23. data/config/routes.rb +12 -0
  24. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboard_templates_controller.rb +20 -0
  25. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb +25 -2
  26. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/kpis_controller.rb +13 -11
  27. data/lib/mno_enterprise/concerns/controllers/jpi/v1/marketplace_controller.rb +1 -1
  28. data/lib/mno_enterprise/concerns/controllers/pages_controller.rb +3 -1
  29. data/spec/controllers/mno_enterprise/impersonate_controller_spec.rb +11 -2
  30. data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/dashboard_templates_controller_spec.rb +225 -0
  31. data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/kpis_controller_spec.rb +134 -0
  32. data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/widgets_controller_spec.rb +150 -0
  33. data/spec/controllers/mno_enterprise/jpi/v1/app_feedbacks_controller_spec.rb +2 -1
  34. data/spec/controllers/mno_enterprise/jpi/v1/app_questions_controller_spec.rb +2 -1
  35. data/spec/controllers/mno_enterprise/jpi/v1/impac/dashboard_templates_controller_spec.rb +97 -0
  36. data/spec/controllers/mno_enterprise/jpi/v1/impac/dashboards_controller_spec.rb +223 -0
  37. data/spec/controllers/mno_enterprise/jpi/v1/marketplace_controller_spec.rb +31 -1
  38. data/spec/controllers/mno_enterprise/pages_controller_spec.rb +13 -2
  39. data/spec/routing/mno_enterprise/jpi/v1/admin/impac/dashboard_templates_controller_routing_spec.rb +28 -0
  40. data/spec/routing/mno_enterprise/jpi/v1/admin/impac/kpis_controller_routing_spec.rb +20 -0
  41. data/spec/routing/mno_enterprise/jpi/v1/admin/impac/widgets_controller_routing_spec.rb +20 -0
  42. data/spec/routing/mno_enterprise/jpi/v1/impac/dashboard_templates_controller_routing_spec.rb +11 -0
  43. metadata +35 -4
@@ -0,0 +1,150 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe Jpi::V1::Admin::Impac::WidgetsController, type: :controller do
5
+ # include MnoEnterprise::TestingSupport::JpiV1TestHelper
6
+ include MnoEnterprise::TestingSupport::SharedExamples::JpiV1Admin
7
+ render_views
8
+ routes { MnoEnterprise::Engine.routes }
9
+ before { request.env["HTTP_ACCEPT"] = 'application/json' }
10
+
11
+ let(:user) { build(:user, :admin, :with_organizations) }
12
+ let(:org) { build(:organization, users: [user]) }
13
+ let(:template) { build(:impac_dashboard, dashboard_type: 'template') }
14
+ let(:metadata) { { hist_parameters: { from: '2015-01-01', to: '2015-03-31', period: 'MONTHLY' } } }
15
+ let(:widget) { build(:impac_widget, dashboard: template, settings: metadata) }
16
+ let(:kpi) { build(:impac_kpi, widget: widget) }
17
+
18
+ let(:hash_for_kpi) do
19
+ {
20
+ "id" => kpi.id,
21
+ "element_watched" => kpi.element_watched,
22
+ "endpoint" => kpi.endpoint
23
+ }
24
+ end
25
+ let(:hash_for_widget) do
26
+ {
27
+ "id" => widget.id,
28
+ "name" => widget.name,
29
+ 'metadata' => metadata.deep_stringify_keys,
30
+ "endpoint" => widget.widget_category,
31
+ "width" => widget.width,
32
+ "kpis" => [hash_for_kpi]
33
+ }
34
+ end
35
+
36
+ before do
37
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
38
+ sign_in user
39
+ end
40
+
41
+ describe '#create' do
42
+ let(:widget_params) do
43
+ {
44
+ endpoint: widget.endpoint,
45
+ name: widget.name,
46
+ width: widget.width,
47
+ metadata: metadata,
48
+ forbidden: 'param'
49
+ }
50
+ end
51
+
52
+ subject { post :create, dashboard_template_id: template.id, widget: widget_params }
53
+
54
+ before do
55
+ api_stub_for(
56
+ get: "/dashboards/#{template.id}",
57
+ params: { filter: { 'dashboard_type' => 'template' } },
58
+ response: from_api(template)
59
+ )
60
+ api_stub_for(
61
+ post: "dashboards/#{template.id}/widgets",
62
+ response: from_api(widget)
63
+ )
64
+ # Why is Her doing a GET /widgets after doing a POST /widgets?
65
+ api_stub_for(
66
+ get: "dashboards/#{template.id}/widgets",
67
+ response: from_api([widget])
68
+ )
69
+ api_stub_for(
70
+ get: "/widgets/#{widget.id}/kpis",
71
+ response: from_api([kpi])
72
+ )
73
+ end
74
+
75
+ it_behaves_like "a jpi v1 admin action"
76
+
77
+ it 'returns a widget' do
78
+ subject
79
+ expect(JSON.parse(response.body)).to eq(hash_for_widget)
80
+ end
81
+
82
+ # api_stub should be modified to allow this case to be stubbed
83
+ context 'when the template cannot be found' do
84
+ xit 'spec to be described'
85
+ end
86
+ end
87
+
88
+ describe '#update' do
89
+ let(:widget_params) do
90
+ {
91
+ name: widget.name,
92
+ width: widget.width,
93
+ metadata: metadata,
94
+ forbidden: 'param'
95
+ }
96
+ end
97
+
98
+ subject { put :update, id: widget.id, widget: widget_params }
99
+
100
+ before do
101
+ api_stub_for(
102
+ get: "widgets/#{widget.id}",
103
+ response: from_api(widget)
104
+ )
105
+ api_stub_for(
106
+ put: "/widgets/#{widget.id}",
107
+ response: from_api(widget)
108
+ )
109
+ api_stub_for(
110
+ get: "/widgets/#{widget.id}/kpis",
111
+ response: from_api([kpi])
112
+ )
113
+ end
114
+
115
+ it_behaves_like "a jpi v1 admin action"
116
+
117
+ it 'returns a widget' do
118
+ subject
119
+ expect(JSON.parse(response.body)).to eq(hash_for_widget)
120
+ end
121
+
122
+ # api_stub should be modified to allow this case to be stubbed
123
+ context 'when the widget update is unsuccessful' do
124
+ xit 'spec to be described'
125
+ end
126
+ end
127
+
128
+ describe '#destroy' do
129
+ subject { delete :destroy, id: widget.id }
130
+
131
+ before do
132
+ api_stub_for(
133
+ get: "widgets/#{widget.id}",
134
+ response: from_api(widget)
135
+ )
136
+ api_stub_for(
137
+ delete: "/widgets/#{widget.id}",
138
+ response: from_api(nil)
139
+ )
140
+ end
141
+
142
+ it_behaves_like "a jpi v1 admin action"
143
+
144
+ # api_stub should be modified to allow this case to be stubbed
145
+ context 'when the widget destruction is invalidunsuccessful' do
146
+ xit 'spec to be described'
147
+ end
148
+ end
149
+ end
150
+ end
@@ -18,7 +18,8 @@ module MnoEnterprise
18
18
  let(:app) { build(:app) }
19
19
  let(:feedback_comment_1) { build(:app_comment) }
20
20
  let(:feedback_comment_2) { build(:app_comment) }
21
- let(:app_feedback) { build(:app_feedback, comments: [feedback_comment_1, feedback_comment_2]) }
21
+ let(:rejected_feedback_comment) { build(:app_comment, status: 'rejected') }
22
+ let(:app_feedback) { build(:app_feedback, comments: [feedback_comment_1, feedback_comment_2, rejected_feedback_comment]) }
22
23
  let(:expected_hash_for_comment_1) do
23
24
  attrs = %w(id description status user_id user_name organization_id organization_name app_id feedback_id app_name user_admin_role edited edited_by_name edited_by_admin_role edited_by_id)
24
25
  feedback_comment_1.attributes.slice(*attrs).merge({'created_at' => feedback_comment_1.created_at.as_json, 'updated_at' => feedback_comment_1.updated_at.as_json})
@@ -18,7 +18,8 @@ module MnoEnterprise
18
18
  let(:app) { build(:app) }
19
19
  let(:question_answer_1) { build(:app_answer) }
20
20
  let(:question_answer_2) { build(:app_answer) }
21
- let(:app_question) { build(:app_question, answers: [question_answer_1, question_answer_2]) }
21
+ let(:rejected_answer) { build(:app_answer, status: 'rejected') }
22
+ let(:app_question) { build(:app_question, answers: [question_answer_1, question_answer_2, rejected_answer]) }
22
23
  let(:expected_hash_for_answer_1) do
23
24
  attrs = %w(id description status user_id user_name organization_id organization_name app_id question_id app_name user_admin_role edited edited_by_name edited_by_admin_role edited_by_id)
24
25
  question_answer_1.attributes.slice(*attrs).merge({'created_at' => question_answer_1.created_at.as_json, 'updated_at' => question_answer_1.updated_at.as_json})
@@ -0,0 +1,97 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe MnoEnterprise::Jpi::V1::Impac::DashboardTemplatesController, type: :controller do
5
+ include MnoEnterprise::TestingSupport::JpiV1TestHelper
6
+ render_views
7
+ routes { MnoEnterprise::Engine.routes }
8
+ before { request.env["HTTP_ACCEPT"] = 'application/json' }
9
+ before { Rails.cache.clear }
10
+
11
+ let(:user) { build(:user, :with_organizations) }
12
+ let(:org) { build(:organization, users: [user]) }
13
+ let(:metadata) { { hist_parameters: { from: '2015-01-01', to: '2015-03-31', period: 'MONTHLY' } } }
14
+ let(:template) { build(:impac_dashboard, dashboard_type: 'template', organization_ids: [org.uid], currency: 'EUR', settings: metadata) }
15
+ let(:widget) { build(:impac_widget, dashboard: template, owner: user) }
16
+ let(:d_kpi) { build(:impac_kpi, dashboard: template) }
17
+ let(:w_kpi) { build(:impac_kpi, widget: widget) }
18
+
19
+ def hash_for_kpi(kpi)
20
+ {
21
+ "id" => kpi.id,
22
+ "element_watched" => kpi.element_watched,
23
+ "endpoint" => kpi.endpoint
24
+ }
25
+ end
26
+ let(:hash_for_widget) do
27
+ {
28
+ "id" => widget.id,
29
+ "name" => widget.name,
30
+ "endpoint" => widget.widget_category,
31
+ "width" => widget.width,
32
+ "kpis" => [hash_for_kpi(w_kpi)],
33
+ 'owner' => from_api(user)[:data]
34
+ }
35
+ end
36
+ let(:hash_for_template) do
37
+ {
38
+ "id" => template.id,
39
+ "name" => template.name,
40
+ "full_name" => template.full_name,
41
+ "currency" => 'EUR',
42
+ "metadata" => metadata.deep_stringify_keys,
43
+ "data_sources" => [{ "id" => org.id, "uid" => org.uid, "label" => org.name}],
44
+ "kpis" => [hash_for_kpi(d_kpi)],
45
+ "widgets" => [hash_for_widget]
46
+ }
47
+ end
48
+
49
+ before do
50
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
51
+ sign_in user
52
+ end
53
+
54
+ describe 'GET #index' do
55
+ subject { get :index }
56
+
57
+ before do
58
+ api_stub_for(
59
+ get: '/dashboards',
60
+ params: { filter: { 'dashboard_type' => 'template', 'published' => true } },
61
+ response: from_api([template])
62
+ )
63
+ api_stub_for(
64
+ get: "/users/#{user.id}/organizations",
65
+ response: from_api([org])
66
+ )
67
+ api_stub_for(
68
+ get: "/dashboards/#{template.id}/widgets",
69
+ response: from_api([widget])
70
+ )
71
+ api_stub_for(
72
+ get: "/dashboards/#{template.id}/kpis",
73
+ response: from_api([d_kpi])
74
+ )
75
+ api_stub_for(
76
+ get: "/widgets/#{widget.id}/kpis",
77
+ response: from_api([w_kpi])
78
+ )
79
+ api_stub_for(
80
+ get: "/kpis/#{w_kpi.id}/alerts",
81
+ response: from_api([])
82
+ )
83
+ api_stub_for(
84
+ get: "/kpis/#{d_kpi.id}/alerts",
85
+ response: from_api([])
86
+ )
87
+ end
88
+
89
+ it_behaves_like "jpi v1 protected action"
90
+
91
+ it 'returns a list of dashboard templates' do
92
+ subject
93
+ expect(JSON.parse(response.body)).to eq([hash_for_template])
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,223 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe MnoEnterprise::Jpi::V1::Impac::DashboardsController, type: :controller do
5
+ include MnoEnterprise::TestingSupport::JpiV1TestHelper
6
+ render_views
7
+ routes { MnoEnterprise::Engine.routes }
8
+ before { request.env["HTTP_ACCEPT"] = 'application/json' }
9
+ before { Rails.cache.clear }
10
+
11
+ RSpec.shared_context "#{described_class}: dashboard dependencies stubs" do
12
+ before do
13
+ api_stub_for(
14
+ get: "/users/#{user.id}/organizations",
15
+ response: from_api([org])
16
+ )
17
+ api_stub_for(
18
+ get: "/dashboards/#{dashboard.id}/widgets",
19
+ response: from_api([widget])
20
+ )
21
+ api_stub_for(
22
+ get: "/dashboards/#{dashboard.id}/kpis",
23
+ response: from_api([d_kpi])
24
+ )
25
+ api_stub_for(
26
+ get: "/widgets/#{widget.id}/kpis",
27
+ response: from_api([w_kpi])
28
+ )
29
+ api_stub_for(
30
+ get: "/kpis/#{w_kpi.id}/alerts",
31
+ response: from_api([])
32
+ )
33
+ api_stub_for(
34
+ get: "/kpis/#{d_kpi.id}/alerts",
35
+ response: from_api([])
36
+ )
37
+ end
38
+ end
39
+
40
+ let(:user) { build(:user, :with_organizations) }
41
+ let(:org) { build(:organization, users: [user]) }
42
+ let(:metadata) { { hist_parameters: { from: '2015-01-01', to: '2015-03-31', period: 'MONTHLY' } } }
43
+ let(:dashboard) { build(:impac_dashboard, dashboard_type: 'dashboard', organization_ids: [org.uid], currency: 'EUR', settings: metadata) }
44
+ let(:widget) { build(:impac_widget, dashboard: dashboard, owner: user) }
45
+ let(:d_kpi) { build(:impac_kpi, dashboard: dashboard) }
46
+ let(:w_kpi) { build(:impac_kpi, widget: widget) }
47
+
48
+ let(:dashboard_params) do
49
+ {
50
+ name: dashboard.name,
51
+ currency: dashboard.currency,
52
+ widgets_order: [3, 2, 1],
53
+ organization_ids: [4, 5],
54
+ metadata: metadata,
55
+ forbidden: 'param'
56
+ }
57
+ end
58
+
59
+ def hash_for_kpi(kpi)
60
+ {
61
+ "id" => kpi.id,
62
+ "element_watched" => kpi.element_watched,
63
+ "endpoint" => kpi.endpoint
64
+ }
65
+ end
66
+ let(:hash_for_widget) do
67
+ {
68
+ "id" => widget.id,
69
+ "name" => widget.name,
70
+ "endpoint" => widget.widget_category,
71
+ "width" => widget.width,
72
+ "kpis" => [hash_for_kpi(w_kpi)],
73
+ 'owner' => from_api(user)[:data]
74
+ }
75
+ end
76
+ let(:hash_for_dashboard) do
77
+ {
78
+ "id" => dashboard.id,
79
+ "name" => dashboard.name,
80
+ "full_name" => dashboard.full_name,
81
+ "currency" => 'EUR',
82
+ "metadata" => metadata.deep_stringify_keys,
83
+ "data_sources" => [{ "id" => org.id, "uid" => org.uid, "label" => org.name}],
84
+ "kpis" => [hash_for_kpi(d_kpi)],
85
+ "widgets" => [hash_for_widget]
86
+ }
87
+ end
88
+
89
+ before do
90
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
91
+ sign_in user
92
+ end
93
+
94
+ describe 'GET #index' do
95
+ subject { get :index }
96
+
97
+ before do
98
+ api_stub_for(
99
+ get: "users/#{user.id}/dashboards",
100
+ response: from_api([dashboard])
101
+ )
102
+ end
103
+ include_context "#{described_class}: dashboard dependencies stubs"
104
+
105
+ it_behaves_like "jpi v1 protected action"
106
+
107
+ it 'returns a list of dashboards' do
108
+ subject
109
+ expect(JSON.parse(response.body)).to eq([hash_for_dashboard])
110
+ end
111
+ end
112
+
113
+ describe 'GET #show' do
114
+ before do
115
+ api_stub_for(
116
+ get: "users/#{user.id}/dashboards/#{dashboard.id}",
117
+ response: from_api(dashboard)
118
+ )
119
+ end
120
+ include_context "#{described_class}: dashboard dependencies stubs"
121
+
122
+ subject { get :show, id: dashboard.id }
123
+
124
+ it_behaves_like "jpi v1 protected action"
125
+
126
+ it 'returns a dashboard' do
127
+ subject
128
+ expect(JSON.parse(response.body)).to eq(hash_for_dashboard)
129
+ end
130
+ end
131
+
132
+ describe 'POST #create' do
133
+ before do
134
+ api_stub_for(
135
+ post: "users/#{user.id}/dashboards",
136
+ response: from_api(dashboard)
137
+ )
138
+ # Her calling GET /dashboards after a POST...
139
+ api_stub_for(
140
+ get: "users/#{user.id}/dashboards",
141
+ response: from_api([dashboard])
142
+ )
143
+ end
144
+ include_context "#{described_class}: dashboard dependencies stubs"
145
+
146
+ subject { post :create, user_id: user.id, dashboard: dashboard_params }
147
+
148
+ it_behaves_like "jpi v1 protected action"
149
+
150
+ it 'returns a dashboard' do
151
+ subject
152
+ expect(JSON.parse(response.body)).to eq(hash_for_dashboard)
153
+ end
154
+ end
155
+
156
+ describe 'PUT #update' do
157
+ before do
158
+ api_stub_for(
159
+ get: "users/#{user.id}/dashboards/#{dashboard.id}",
160
+ response: from_api(dashboard)
161
+ )
162
+ api_stub_for(
163
+ put: "dashboards/#{dashboard.id}",
164
+ response: from_api(dashboard)
165
+ )
166
+ end
167
+ include_context "#{described_class}: dashboard dependencies stubs"
168
+
169
+ subject { put :update, id: dashboard.id, dashboard: dashboard_params }
170
+
171
+ it_behaves_like "jpi v1 protected action"
172
+
173
+ it 'returns a dashboard' do
174
+ subject
175
+ expect(JSON.parse(response.body)).to eq(hash_for_dashboard)
176
+ end
177
+ end
178
+
179
+ describe "DELETE destroy" do
180
+ before do
181
+ api_stub_for(
182
+ get: "users/#{user.id}/dashboards/#{dashboard.id}",
183
+ response: from_api(dashboard)
184
+ )
185
+ api_stub_for(
186
+ delete: "dashboards/#{dashboard.id}",
187
+ response: from_api(dashboard)
188
+ )
189
+ end
190
+ include_context "#{described_class}: dashboard dependencies stubs"
191
+
192
+ subject { delete :destroy, id: dashboard.id }
193
+
194
+ it_behaves_like "jpi v1 protected action"
195
+ end
196
+
197
+ describe 'POST copy' do
198
+ let(:template) { build(:impac_dashboard, dashboard_type: 'template') }
199
+
200
+ before do
201
+ api_stub_for(
202
+ get: "/dashboards/#{template.id}",
203
+ params: { filter: { 'dashboard_type' => 'template' } },
204
+ response: from_api(template)
205
+ )
206
+ api_stub_for(
207
+ post: "/dashboards/#{template.id}/copy",
208
+ response: from_api(dashboard)
209
+ )
210
+ end
211
+ include_context "#{described_class}: dashboard dependencies stubs"
212
+
213
+ subject { post :copy, id: template.id, dashboard: dashboard_params }
214
+
215
+ it_behaves_like "jpi v1 protected action"
216
+
217
+ it 'returns a dashboard' do
218
+ subject
219
+ expect(JSON.parse(response.body)).to eq(hash_for_dashboard)
220
+ end
221
+ end
222
+ end
223
+ end