mno-enterprise-api 3.3.3 → 3.4.0

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 (41) hide show
  1. checksums.yaml +5 -5
  2. data/app/controllers/mno_enterprise/jpi/v1/admin/impac/dashboards_controller.rb +105 -0
  3. data/app/controllers/mno_enterprise/jpi/v1/admin/impac/widgets_controller.rb +20 -8
  4. data/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb +1 -1
  5. data/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +1 -140
  6. data/app/controllers/mno_enterprise/jpi/v1/admin/sub_tenants_controller.rb +64 -0
  7. data/app/controllers/mno_enterprise/jpi/v1/admin/users_controller.rb +30 -20
  8. data/app/views/mno_enterprise/jpi/v1/admin/impac/dashboards/_dashboard.json.jbuilder +12 -0
  9. data/app/views/mno_enterprise/jpi/v1/admin/impac/dashboards/index.json.jbuilder +1 -0
  10. data/app/views/mno_enterprise/jpi/v1/admin/impac/dashboards/show.json.jbuilder +1 -0
  11. data/app/views/mno_enterprise/jpi/v1/admin/impac/widgets/_widget.json.jbuilder +1 -0
  12. data/app/views/mno_enterprise/jpi/v1/admin/organizations/_organization.json.jbuilder +1 -1
  13. data/app/views/mno_enterprise/jpi/v1/admin/sub_tenants/_sub_tenant.json.jbuilder +1 -0
  14. data/app/views/mno_enterprise/jpi/v1/admin/sub_tenants/index.json.jbuilder +2 -0
  15. data/app/views/mno_enterprise/jpi/v1/admin/sub_tenants/show.json.jbuilder +12 -0
  16. data/app/views/mno_enterprise/jpi/v1/admin/users/_user.json.jbuilder +1 -1
  17. data/app/views/mno_enterprise/jpi/v1/admin/users/show.json.jbuilder +5 -5
  18. data/app/views/mno_enterprise/jpi/v1/current_users/show.json.jbuilder +4 -2
  19. data/app/views/mno_enterprise/jpi/v1/impac/widgets/_widget.json.jbuilder +1 -0
  20. data/app/views/mno_enterprise/jpi/v1/organizations/_organization.json.jbuilder +1 -1
  21. data/config/routes.rb +9 -1
  22. data/lib/mno_enterprise/concerns/controllers/jpi/v1/admin/organizations_controller.rb +159 -0
  23. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/alerts_controller.rb +3 -6
  24. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb +29 -38
  25. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/kpis_controller.rb +7 -8
  26. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/widgets_controller.rb +14 -2
  27. data/lib/mno_enterprise/concerns/controllers/jpi/v1/organizations_controller.rb +1 -1
  28. data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/dashboard_controller_spec.rb +149 -0
  29. data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/dashboard_templates_controller_spec.rb +151 -139
  30. data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/kpis_controller_spec.rb +95 -69
  31. data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/widgets_controller_spec.rb +169 -81
  32. data/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb +1 -1
  33. data/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb +2 -1
  34. data/spec/controllers/mno_enterprise/jpi/v1/admin/sub_tenants_controller_spec.rb +172 -0
  35. data/spec/controllers/mno_enterprise/jpi/v1/admin/users_controller_spec.rb +29 -12
  36. data/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb +4 -2
  37. data/spec/controllers/mno_enterprise/jpi/v1/impac/dashboards_controller_spec.rb +26 -15
  38. data/spec/controllers/mno_enterprise/jpi/v1/impac/kpis_controller_spec.rb +11 -7
  39. data/spec/routing/mno_enterprise/jpi/v1/admin/impac/dashboards_controller_routing_spec.rb +28 -0
  40. data/spec/routing/mno_enterprise/jpi/v1/impac/dashboards_controller_routing_spec.rb +4 -0
  41. metadata +85 -70
@@ -1,12 +1,9 @@
1
1
  require 'rails_helper'
2
+ require 'mno_enterprise/testing_support/shared_contexts/jpi_v1_admin_controller'
2
3
 
3
4
  module MnoEnterprise
4
5
  describe Jpi::V1::Admin::Impac::KpisController, 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' }
6
+ include_context MnoEnterprise::Jpi::V1::Admin::BaseResourceController
10
7
 
11
8
  let(:user) { build(:user, :admin, :with_organizations) }
12
9
  let(:org) { build(:organization, users: [user]) }
@@ -23,11 +20,6 @@ module MnoEnterprise
23
20
  }
24
21
  end
25
22
 
26
- before do
27
- api_stub_for(get: "/users/#{user.id}", response: from_api(user))
28
- sign_in user
29
- end
30
-
31
23
  describe '#create' do
32
24
  let(:kpi_params) do
33
25
  {
@@ -42,34 +34,46 @@ module MnoEnterprise
42
34
  end
43
35
 
44
36
  subject { post :create, dashboard_template_id: template.id, kpi: kpi_params }
45
-
46
- before do
47
- api_stub_for(
48
- get: "/dashboards/#{template.id}",
49
- params: { filter: { 'dashboard_type' => 'template' } },
50
- response: from_api(template)
51
- )
52
- api_stub_for(
53
- post: "dashboards/#{template.id}/kpis",
54
- response: from_api(kpi)
55
- )
56
- # Why is Her doing a GET /kpis after doing a POST /kpis?
57
- api_stub_for(
58
- get: "dashboards/#{template.id}/kpis",
59
- response: from_api([kpi])
60
- )
61
- end
62
-
63
- it_behaves_like "a jpi v1 admin action"
64
37
 
65
- it 'returns a kpi' do
66
- subject
67
- expect(JSON.parse(response.body)).to eq(hash_for_kpi)
38
+ context 'when the template exists' do
39
+ before do
40
+ api_stub_for(
41
+ get: "/dashboards/#{template.id}",
42
+ params: { filter: { 'dashboard_type' => 'template' } },
43
+ response: from_api(template)
44
+ )
45
+ api_stub_for(
46
+ post: "dashboards/#{template.id}/kpis",
47
+ response: from_api(kpi)
48
+ )
49
+ # Why is Her doing a GET /kpis after doing a POST /kpis?
50
+ api_stub_for(
51
+ get: "dashboards/#{template.id}/kpis",
52
+ response: from_api([kpi])
53
+ )
54
+ end
55
+
56
+ it_behaves_like "a jpi v1 admin action"
57
+
58
+ it 'returns a kpi' do
59
+ subject
60
+ expect(JSON.parse(response.body)).to eq(hash_for_kpi)
61
+ end
68
62
  end
69
63
 
70
- # api_stub should be modified to allow this case to be stubbed
71
- context 'when the template cannot be found' do
72
- xit 'spec to be described'
64
+ context 'when the template does not exist' do
65
+ before do
66
+ api_stub_for(
67
+ get: "/dashboards/#{template.id}",
68
+ params: { filter: { 'dashboard_type' => 'template' } },
69
+ code: 404
70
+ )
71
+ end
72
+
73
+ it 'returns an error message' do
74
+ subject
75
+ expect(JSON.parse(response.body)).to eq({ 'errors' => { 'message' => 'Dashboard template not found' } })
76
+ end
73
77
  end
74
78
  end
75
79
 
@@ -84,50 +88,72 @@ module MnoEnterprise
84
88
  end
85
89
 
86
90
  subject { put :update, id: kpi.id, kpi: kpi_params }
87
-
88
- before do
89
- api_stub_for(
90
- get: "kpis/#{kpi.id}",
91
- response: from_api(kpi)
92
- )
93
- api_stub_for(
94
- put: "/kpis/#{kpi.id}",
95
- response: from_api(kpi)
96
- )
97
- end
98
-
99
- it_behaves_like "a jpi v1 admin action"
100
91
 
101
- it 'returns a kpi' do
102
- subject
103
- expect(JSON.parse(response.body)).to eq(hash_for_kpi)
92
+ context 'when the kpi exists' do
93
+ before do
94
+ api_stub_for(
95
+ get: "kpis/#{kpi.id}",
96
+ response: from_api(kpi)
97
+ )
98
+ api_stub_for(
99
+ put: "/kpis/#{kpi.id}",
100
+ response: from_api(kpi)
101
+ )
102
+ end
103
+
104
+ it_behaves_like "a jpi v1 admin action"
105
+
106
+ it 'returns a kpi' do
107
+ subject
108
+ expect(JSON.parse(response.body)).to eq(hash_for_kpi)
109
+ end
104
110
  end
105
111
 
106
- # api_stub should be modified to allow this case to be stubbed
107
- context 'when the kpi update is unsuccessful' do
108
- xit 'spec to be described'
112
+ context 'when the kpi does not exist' do
113
+ before do
114
+ api_stub_for(
115
+ get: "kpis/#{kpi.id}",
116
+ code: 404
117
+ )
118
+ end
119
+
120
+ it 'returns an error message' do
121
+ subject
122
+ expect(JSON.parse(response.body)).to eq({ 'errors' => 'Cannot update kpi' })
123
+ end
109
124
  end
110
125
  end
111
126
 
112
127
  describe '#destroy' do
113
128
  subject { delete :destroy, id: kpi.id }
114
-
115
- before do
116
- api_stub_for(
117
- get: "kpis/#{kpi.id}",
118
- response: from_api(kpi)
119
- )
120
- api_stub_for(
121
- delete: "/kpis/#{kpi.id}",
122
- response: from_api(nil)
123
- )
124
- end
125
129
 
126
- it_behaves_like "a jpi v1 admin action"
130
+ context 'when the kpi exists' do
131
+ before do
132
+ api_stub_for(
133
+ get: "kpis/#{kpi.id}",
134
+ response: from_api(kpi)
135
+ )
136
+ api_stub_for(
137
+ delete: "/kpis/#{kpi.id}",
138
+ response: from_api(nil)
139
+ )
140
+ end
141
+
142
+ it_behaves_like "a jpi v1 admin action"
143
+ end
127
144
 
128
- # api_stub should be modified to allow this case to be stubbed
129
- context 'when the kpi destruction is unsuccessful' do
130
- xit 'spec to be described'
145
+ context 'when the kpi does not exist' do
146
+ before do
147
+ api_stub_for(
148
+ get: "kpis/#{kpi.id}",
149
+ code: 404
150
+ )
151
+ end
152
+
153
+ it 'returns an error message' do
154
+ subject
155
+ expect(JSON.parse(response.body)).to eq({ 'errors' => 'Cannot delete kpi' })
156
+ end
131
157
  end
132
158
  end
133
159
  end
@@ -1,18 +1,15 @@
1
1
  require 'rails_helper'
2
+ require 'mno_enterprise/testing_support/shared_contexts/jpi_v1_admin_controller'
2
3
 
3
4
  module MnoEnterprise
4
5
  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' }
6
+ include_context MnoEnterprise::Jpi::V1::Admin::BaseResourceController
10
7
 
11
8
  let(:user) { build(:user, :admin, :with_organizations) }
12
9
  let(:org) { build(:organization, users: [user]) }
13
10
  let(:template) { build(:impac_dashboard, dashboard_type: 'template') }
14
11
  let(:metadata) { { hist_parameters: { from: '2015-01-01', to: '2015-03-31', period: 'MONTHLY' } } }
15
- let(:widget) { build(:impac_widget, dashboard: template, settings: metadata) }
12
+ let(:widget) { build(:impac_widget, dashboard: template, settings: metadata, layouts: ['figure', 'highcharts']) }
16
13
  let(:kpi) { build(:impac_kpi, widget: widget) }
17
14
 
18
15
  let(:hash_for_kpi) do
@@ -29,15 +26,11 @@ module MnoEnterprise
29
26
  'metadata' => metadata.deep_stringify_keys,
30
27
  "endpoint" => widget.widget_category,
31
28
  "width" => widget.width,
32
- "kpis" => [hash_for_kpi]
29
+ "kpis" => [hash_for_kpi],
30
+ "layouts" => widget.layouts
33
31
  }
34
32
  end
35
33
 
36
- before do
37
- api_stub_for(get: "/users/#{user.id}", response: from_api(user))
38
- sign_in user
39
- end
40
-
41
34
  describe '#create' do
42
35
  let(:widget_params) do
43
36
  {
@@ -45,43 +38,116 @@ module MnoEnterprise
45
38
  name: widget.name,
46
39
  width: widget.width,
47
40
  metadata: metadata,
41
+ layouts: widget.layouts,
48
42
  forbidden: 'param'
49
43
  }
50
44
  end
51
45
 
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)
46
+ context 'with a dashboard' do
47
+ subject { post :create, dashboard_id: dashboard.id, widget: widget_params }
48
+
49
+ let(:dashboard) { build(:impac_dashboard) }
50
+
51
+ context 'when the dashboard exists' do
52
+ before do
53
+ api_stub_for(
54
+ get: "/dashboards",
55
+ params: {
56
+ filter: { 'id' => dashboard.id, 'owner_id' => user.id, 'owner_type' => 'User' },
57
+ limit: 1
58
+ },
59
+ response: from_api([dashboard])
60
+ )
61
+ api_stub_for(
62
+ post: "dashboards/#{dashboard.id}/widgets",
63
+ response: from_api(widget)
64
+ )
65
+ # Why is Her doing a GET /widgets after doing a POST /widgets?
66
+ api_stub_for(
67
+ get: "dashboards/#{dashboard.id}/widgets",
68
+ response: from_api([widget])
69
+ )
70
+ api_stub_for(
71
+ get: "/widgets/#{widget.id}/kpis",
72
+ response: from_api([kpi])
73
+ )
74
+ end
75
+
76
+ it_behaves_like "a jpi v1 admin action"
77
+
78
+ it 'returns a widget' do
79
+ subject
80
+ expect(JSON.parse(response.body)).to eq(hash_for_widget)
81
+ end
82
+ end
83
+
84
+ context 'when the dashboard does not exist' do
85
+ before do
86
+ api_stub_for(
87
+ get: "/dashboards",
88
+ params: {
89
+ filter: { 'id' => dashboard.id, 'owner_id' => user.id, 'owner_type' => 'User' },
90
+ limit: 1
91
+ },
92
+ response: from_api([])
93
+ )
94
+ end
95
+
96
+ it 'returns an error message' do
97
+ subject
98
+ expect(response).to have_http_status(:not_found)
99
+ expect(JSON.parse(response.body)).to eq({ 'errors' => { 'message' => 'Dashboard not found' } })
100
+ end
101
+ end
80
102
  end
81
103
 
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'
104
+ context 'with a dashboard template' do
105
+ subject { post :create, dashboard_template_id: template.id, widget: widget_params }
106
+
107
+ context 'when the template exists' do
108
+ before do
109
+ api_stub_for(
110
+ get: "/dashboards/#{template.id}",
111
+ params: { filter: { 'dashboard_type' => 'template' } },
112
+ response: from_api(template)
113
+ )
114
+ api_stub_for(
115
+ post: "dashboards/#{template.id}/widgets",
116
+ response: from_api(widget)
117
+ )
118
+ # Why is Her doing a GET /widgets after doing a POST /widgets?
119
+ api_stub_for(
120
+ get: "dashboards/#{template.id}/widgets",
121
+ response: from_api([widget])
122
+ )
123
+ api_stub_for(
124
+ get: "/widgets/#{widget.id}/kpis",
125
+ response: from_api([kpi])
126
+ )
127
+ end
128
+
129
+ it_behaves_like "a jpi v1 admin action"
130
+
131
+ it 'returns a widget' do
132
+ subject
133
+ expect(JSON.parse(response.body)).to eq(hash_for_widget)
134
+ end
135
+ end
136
+
137
+ context 'when the template does not exist' do
138
+ before do
139
+ api_stub_for(
140
+ get: "/dashboards/#{template.id}",
141
+ params: { filter: { 'dashboard_type' => 'template' } },
142
+ code: 404
143
+ )
144
+ end
145
+
146
+ it 'returns an error message' do
147
+ subject
148
+ expect(JSON.parse(response.body)).to eq({ 'errors' => { 'message' => 'Dashboard template not found' } })
149
+ end
150
+ end
85
151
  end
86
152
  end
87
153
 
@@ -96,54 +162,76 @@ module MnoEnterprise
96
162
  end
97
163
 
98
164
  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
165
 
117
- it 'returns a widget' do
118
- subject
119
- expect(JSON.parse(response.body)).to eq(hash_for_widget)
166
+ context 'when the widget exists' do
167
+ before do
168
+ api_stub_for(
169
+ get: "widgets/#{widget.id}",
170
+ response: from_api(widget)
171
+ )
172
+ api_stub_for(
173
+ put: "/widgets/#{widget.id}",
174
+ response: from_api(widget)
175
+ )
176
+ api_stub_for(
177
+ get: "/widgets/#{widget.id}/kpis",
178
+ response: from_api([kpi])
179
+ )
180
+ end
181
+
182
+ it_behaves_like "a jpi v1 admin action"
183
+
184
+ it 'returns a widget' do
185
+ subject
186
+ expect(JSON.parse(response.body)).to eq(hash_for_widget)
187
+ end
120
188
  end
121
189
 
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'
190
+ context 'when the widget does not exist' do
191
+ before do
192
+ api_stub_for(
193
+ get: "widgets/#{widget.id}",
194
+ code: 404
195
+ )
196
+ end
197
+
198
+ it 'returns an error message' do
199
+ subject
200
+ expect(JSON.parse(response.body)).to eq({ 'errors' => 'Cannot update widget' })
201
+ end
125
202
  end
126
203
  end
127
204
 
128
205
  describe '#destroy' do
129
206
  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
207
 
142
- it_behaves_like "a jpi v1 admin action"
208
+ context 'when the widget exists' do
209
+ before do
210
+ api_stub_for(
211
+ get: "widgets/#{widget.id}",
212
+ response: from_api(widget)
213
+ )
214
+ api_stub_for(
215
+ delete: "/widgets/#{widget.id}",
216
+ response: from_api(nil)
217
+ )
218
+ end
219
+
220
+ it_behaves_like "a jpi v1 admin action"
221
+ end
143
222
 
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'
223
+ context 'when the widget does not exist' do
224
+ before do
225
+ api_stub_for(
226
+ get: "widgets/#{widget.id}",
227
+ code: 404
228
+ )
229
+ end
230
+
231
+ it 'returns an error message' do
232
+ subject
233
+ expect(JSON.parse(response.body)).to eq({ 'errors' => 'Cannot delete widget' })
234
+ end
147
235
  end
148
236
  end
149
237
  end