mno-enterprise-api 3.3.3 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/app/controllers/mno_enterprise/jpi/v1/admin/impac/dashboards_controller.rb +105 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/impac/widgets_controller.rb +20 -8
- data/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb +1 -1
- data/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +1 -140
- data/app/controllers/mno_enterprise/jpi/v1/admin/sub_tenants_controller.rb +64 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/users_controller.rb +30 -20
- data/app/views/mno_enterprise/jpi/v1/admin/impac/dashboards/_dashboard.json.jbuilder +12 -0
- data/app/views/mno_enterprise/jpi/v1/admin/impac/dashboards/index.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/impac/dashboards/show.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/impac/widgets/_widget.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/organizations/_organization.json.jbuilder +1 -1
- data/app/views/mno_enterprise/jpi/v1/admin/sub_tenants/_sub_tenant.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/sub_tenants/index.json.jbuilder +2 -0
- data/app/views/mno_enterprise/jpi/v1/admin/sub_tenants/show.json.jbuilder +12 -0
- data/app/views/mno_enterprise/jpi/v1/admin/users/_user.json.jbuilder +1 -1
- data/app/views/mno_enterprise/jpi/v1/admin/users/show.json.jbuilder +5 -5
- data/app/views/mno_enterprise/jpi/v1/current_users/show.json.jbuilder +4 -2
- data/app/views/mno_enterprise/jpi/v1/impac/widgets/_widget.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/_organization.json.jbuilder +1 -1
- data/config/routes.rb +9 -1
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/admin/organizations_controller.rb +159 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/alerts_controller.rb +3 -6
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb +29 -38
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/kpis_controller.rb +7 -8
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/widgets_controller.rb +14 -2
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/organizations_controller.rb +1 -1
- data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/dashboard_controller_spec.rb +149 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/dashboard_templates_controller_spec.rb +151 -139
- data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/kpis_controller_spec.rb +95 -69
- data/spec/controllers/mno_enterprise/jpi/v1/admin/impac/widgets_controller_spec.rb +169 -81
- data/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb +1 -1
- data/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb +2 -1
- data/spec/controllers/mno_enterprise/jpi/v1/admin/sub_tenants_controller_spec.rb +172 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/users_controller_spec.rb +29 -12
- data/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb +4 -2
- data/spec/controllers/mno_enterprise/jpi/v1/impac/dashboards_controller_spec.rb +26 -15
- data/spec/controllers/mno_enterprise/jpi/v1/impac/kpis_controller_spec.rb +11 -7
- data/spec/routing/mno_enterprise/jpi/v1/admin/impac/dashboards_controller_routing_spec.rb +28 -0
- data/spec/routing/mno_enterprise/jpi/v1/impac/dashboards_controller_routing_spec.rb +4 -0
- metadata +85 -70
@@ -158,7 +158,7 @@ module MnoEnterprise
|
|
158
158
|
it { expect(response).to be_success }
|
159
159
|
|
160
160
|
it 'returns a valid amount' do
|
161
|
-
expected = {'last_portfolio_amount' => {'amount' => tenant.last_portfolio_amount.amount, 'currency' => tenant.last_portfolio_amount.
|
161
|
+
expected = {'last_portfolio_amount' => {'amount' => tenant.last_portfolio_amount.amount, 'currency' => tenant.last_portfolio_amount.currency.to_s}}
|
162
162
|
|
163
163
|
expect(response.body).to eq(expected.to_json)
|
164
164
|
end
|
@@ -70,7 +70,8 @@ module MnoEnterprise
|
|
70
70
|
'name' => organization.name,
|
71
71
|
'soa_enabled' => organization.soa_enabled,
|
72
72
|
'created_at' => organization.created_at,
|
73
|
-
'account_frozen' => organization.account_frozen
|
73
|
+
'account_frozen' => organization.account_frozen,
|
74
|
+
'financial_year_end_month' => organization.financial_year_end_month
|
74
75
|
}],
|
75
76
|
'metadata' => {'pagination' => {'count' => 1}}
|
76
77
|
}
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module MnoEnterprise
|
4
|
+
describe Jpi::V1::Admin::SubTenantsController, type: :controller do
|
5
|
+
include MnoEnterprise::TestingSupport::SharedExamples::JpiV1Admin
|
6
|
+
render_views
|
7
|
+
routes { MnoEnterprise::Engine.routes }
|
8
|
+
before { request.env['HTTP_ACCEPT'] = 'application/json' }
|
9
|
+
|
10
|
+
def hash_for_sub_tenants(sub_tenants)
|
11
|
+
{
|
12
|
+
'sub_tenants' => sub_tenants.map { |s| partial_hash_for_sub_tenant(s) },
|
13
|
+
'metadata' => {'pagination' => {'count' => sub_tenants.count}}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def hash_for_sub_tenant(s)
|
18
|
+
hash = partial_hash_for_sub_tenant(s).merge(
|
19
|
+
{
|
20
|
+
'clients' => s.clients.map { |c| hash_for_client(c) },
|
21
|
+
'account_managers' => s.account_managers.map { |c| hash_account_manager(c) },
|
22
|
+
})
|
23
|
+
{'sub_tenant' => hash}
|
24
|
+
end
|
25
|
+
|
26
|
+
def partial_hash_for_sub_tenant(s)
|
27
|
+
{
|
28
|
+
'id' => s.id,
|
29
|
+
'name' => s.name,
|
30
|
+
'created_at' => s.created_at,
|
31
|
+
'updated_at' => s.updated_at,
|
32
|
+
'client_ids' => s.client_ids,
|
33
|
+
'account_manager_ids' => s.account_manager_ids
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def hash_for_client(client)
|
38
|
+
{
|
39
|
+
'id' => client.id,
|
40
|
+
'uid' => client.uid,
|
41
|
+
'name' => client.name,
|
42
|
+
'created_at' => client.created_at
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def hash_account_manager(user)
|
47
|
+
{
|
48
|
+
'id' => user.id,
|
49
|
+
'uid' => user.uid,
|
50
|
+
'name' => user.name,
|
51
|
+
'surname' => user.surname,
|
52
|
+
'email' => user.email,
|
53
|
+
'created_at' => user.created_at,
|
54
|
+
'admin_role' => user.admin_role
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
shared_examples_for 'unauthorized access' do
|
59
|
+
it { expect(subject).to_not be_success }
|
60
|
+
it do
|
61
|
+
subject
|
62
|
+
expect(response.status).to eq(401)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#===============================================
|
67
|
+
# Specs
|
68
|
+
#===============================================
|
69
|
+
let(:current_user) { build(:user, :admin) }
|
70
|
+
let(:user) { build(:user) }
|
71
|
+
let(:organization) { build(:organization) }
|
72
|
+
let(:sub_tenant) { build(:sub_tenant, account_managers: [user], clients: [organization]) }
|
73
|
+
|
74
|
+
before do
|
75
|
+
api_stub_for(get: '/sub_tenants', response: from_api([sub_tenant]))
|
76
|
+
api_stub_for(get: "/sub_tenants/#{sub_tenant.id}", response: from_api(sub_tenant))
|
77
|
+
api_stub_for(get: "/users/#{current_user.id}", response: from_api(current_user))
|
78
|
+
api_stub_for(get: "/users/#{current_user.id}/organizations", response: from_api([organization]))
|
79
|
+
sign_in current_user
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#index' do
|
83
|
+
subject { get :index }
|
84
|
+
context 'not admin' do
|
85
|
+
let(:current_user) { build(:user) }
|
86
|
+
it_behaves_like 'unauthorized access'
|
87
|
+
end
|
88
|
+
context 'admin' do
|
89
|
+
context 'success' do
|
90
|
+
before { subject }
|
91
|
+
it 'returns a list of sub_tenant' do
|
92
|
+
expect(response).to be_success
|
93
|
+
expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_sub_tenants([sub_tenant]).to_json))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'GET #show' do
|
100
|
+
subject { get :show, id: sub_tenant.id }
|
101
|
+
|
102
|
+
before do
|
103
|
+
api_stub_for(get: "/sub_tenants/#{sub_tenant.id}/clients", response: from_api([organization]))
|
104
|
+
api_stub_for(get: "/sub_tenants/#{sub_tenant.id}/account_managers", response: from_api([user]))
|
105
|
+
end
|
106
|
+
context 'not admin' do
|
107
|
+
let(:current_user) { build(:user) }
|
108
|
+
it_behaves_like 'unauthorized access'
|
109
|
+
end
|
110
|
+
context 'admin' do
|
111
|
+
it_behaves_like 'a jpi v1 admin action'
|
112
|
+
context 'success' do
|
113
|
+
before { subject }
|
114
|
+
it 'returns a complete description of the sub_tenant' do
|
115
|
+
expect(response).to be_success
|
116
|
+
expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_sub_tenant(sub_tenant).to_json))
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'PUT #update' do
|
123
|
+
subject { put :update, id: sub_tenant.id, sub_tenant: {name: 'new name'} }
|
124
|
+
|
125
|
+
before do
|
126
|
+
api_stub_for(get: "/sub_tenants/#{sub_tenant.id}", response: from_api(sub_tenant))
|
127
|
+
api_stub_for(put: "/sub_tenants/#{sub_tenant.id}", response: -> { sub_tenant.name = 'new name'; from_api(sub_tenant) })
|
128
|
+
sign_in current_user
|
129
|
+
end
|
130
|
+
|
131
|
+
it_behaves_like 'a jpi v1 admin action' do
|
132
|
+
before { api_stub_for(get: "/users/#{user.id}/organizations", response: from_api([organization])) }
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'not admin' do
|
136
|
+
let(:current_user) { build(:user) }
|
137
|
+
it_behaves_like 'unauthorized access'
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'admin' do
|
141
|
+
before { subject }
|
142
|
+
context 'success' do
|
143
|
+
it { expect(response).to be_success }
|
144
|
+
# Test that the user is updated by testing the api endpoint was called
|
145
|
+
it { expect(sub_tenant.name).to eq('new name') }
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe 'DELETE #destroy' do
|
151
|
+
subject { delete :destroy, id: sub_tenant.id }
|
152
|
+
before do
|
153
|
+
api_stub_for(get: "/sub_tenants/#{sub_tenant.id}", response: from_api(sub_tenant))
|
154
|
+
api_stub_for(delete: "/sub_tenants/#{sub_tenant.id}")
|
155
|
+
sign_in current_user
|
156
|
+
end
|
157
|
+
it_behaves_like 'a jpi v1 admin action'
|
158
|
+
|
159
|
+
context 'not admin' do
|
160
|
+
let(:current_user) { build(:user) }
|
161
|
+
it_behaves_like 'unauthorized access'
|
162
|
+
end
|
163
|
+
context 'admin' do
|
164
|
+
context 'success' do
|
165
|
+
it { subject }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
|
@@ -7,15 +7,25 @@ module MnoEnterprise
|
|
7
7
|
routes { MnoEnterprise::Engine.routes }
|
8
8
|
before { request.env["HTTP_ACCEPT"] = 'application/json' }
|
9
9
|
|
10
|
-
def
|
10
|
+
def partial_hash_for_organizations(user)
|
11
11
|
user.organizations.map do |org|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
hash_for_organization(org)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def hash_for_organization(org)
|
17
|
+
{
|
18
|
+
'id' => org.id,
|
19
|
+
'uid' => org.uid,
|
20
|
+
'name' => org.name,
|
21
|
+
'account_frozen' => org.account_frozen,
|
22
|
+
'created_at' => org.created_at
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def partial_hash_for_clients(user)
|
27
|
+
user.clients.map do |org|
|
28
|
+
hash_for_organization(org)
|
19
29
|
end
|
20
30
|
end
|
21
31
|
|
@@ -29,9 +39,12 @@ module MnoEnterprise
|
|
29
39
|
'surname' => user.surname,
|
30
40
|
'admin_role' => user.admin_role,
|
31
41
|
'created_at' => user.created_at,
|
42
|
+
'updated_at' => user.updated_at,
|
32
43
|
'last_sign_in_at' => user.last_sign_in_at,
|
33
44
|
'confirmed_at' => user.confirmed_at,
|
34
|
-
'sign_in_count' => user.sign_in_count
|
45
|
+
'sign_in_count' => user.sign_in_count,
|
46
|
+
'mnoe_sub_tenant_id' => user.mnoe_sub_tenant_id,
|
47
|
+
'client_ids' => user.client_ids
|
35
48
|
}
|
36
49
|
end
|
37
50
|
|
@@ -44,7 +57,7 @@ module MnoEnterprise
|
|
44
57
|
|
45
58
|
def hash_for_user(user)
|
46
59
|
hash = {
|
47
|
-
'user' => partial_hash_for_user(user).merge('organizations' =>
|
60
|
+
'user' => partial_hash_for_user(user).merge('organizations' => partial_hash_for_organizations(user), 'clients' => partial_hash_for_clients(user))
|
48
61
|
}
|
49
62
|
|
50
63
|
return hash
|
@@ -55,11 +68,15 @@ module MnoEnterprise
|
|
55
68
|
# Assignments
|
56
69
|
#===============================================
|
57
70
|
# Stub user and user call
|
58
|
-
let(:user) { build(:user, :admin, :with_organizations) }
|
71
|
+
let(:user) { build(:user, :admin, :with_organizations, :with_clients) }
|
72
|
+
|
73
|
+
let(:organization) { build(:organization) }
|
74
|
+
|
59
75
|
before do
|
60
76
|
api_stub_for(get: "/users", response: from_api([user]))
|
61
77
|
api_stub_for(get: "/users/#{user.id}", response: from_api(user))
|
62
|
-
api_stub_for(get: "/users/#{user.id}/organizations", response: from_api(
|
78
|
+
api_stub_for(get: "/users/#{user.id}/organizations", response: from_api([organization]))
|
79
|
+
api_stub_for(get: "/users/#{user.id}/clients", response: from_api([organization]))
|
63
80
|
sign_in user
|
64
81
|
end
|
65
82
|
|
@@ -34,7 +34,8 @@ module MnoEnterprise
|
|
34
34
|
'sso_session' => res.sso_session,
|
35
35
|
'admin_role' => res.admin_role,
|
36
36
|
'avatar_url' => avatar_url(res),
|
37
|
-
'tos_accepted_at' => res.meta_data[:tos_accepted_at] || false
|
37
|
+
'tos_accepted_at' => res.meta_data[:tos_accepted_at] || false,
|
38
|
+
'mnoe_sub_tenant_id' => res.mnoe_sub_tenant_id
|
38
39
|
}
|
39
40
|
|
40
41
|
if res.id
|
@@ -47,7 +48,8 @@ module MnoEnterprise
|
|
47
48
|
'currency' => 'AUD',
|
48
49
|
'current_user_role' => o.role,
|
49
50
|
'has_myob_essentials_only' => o.has_myob_essentials_only?,
|
50
|
-
'financial_year_end_month' => o.financial_year_end_month
|
51
|
+
'financial_year_end_month' => o.financial_year_end_month,
|
52
|
+
'acl' => o.acl
|
51
53
|
}
|
52
54
|
end
|
53
55
|
|
@@ -37,6 +37,7 @@ module MnoEnterprise
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
let!(:ability) { stub_ability }
|
40
41
|
let(:user) { build(:user, :with_organizations) }
|
41
42
|
let(:org) { build(:organization, users: [user]) }
|
42
43
|
let(:metadata) { { hist_parameters: { from: '2015-01-01', to: '2015-03-31', period: 'MONTHLY' } } }
|
@@ -130,6 +131,10 @@ module MnoEnterprise
|
|
130
131
|
end
|
131
132
|
|
132
133
|
describe 'POST #create' do
|
134
|
+
subject { post :create, user_id: user.id, dashboard: dashboard_params }
|
135
|
+
|
136
|
+
include_context "#{described_class}: dashboard dependencies stubs"
|
137
|
+
|
133
138
|
before do
|
134
139
|
api_stub_for(
|
135
140
|
post: "users/#{user.id}/dashboards",
|
@@ -140,20 +145,24 @@ module MnoEnterprise
|
|
140
145
|
get: "users/#{user.id}/dashboards",
|
141
146
|
response: from_api([dashboard])
|
142
147
|
)
|
148
|
+
allow(ability).to receive(:can?).with(:create_impac_dashboards, any_args).and_return(true)
|
143
149
|
end
|
144
|
-
include_context "#{described_class}: dashboard dependencies stubs"
|
145
|
-
|
146
|
-
subject { post :create, user_id: user.id, dashboard: dashboard_params }
|
147
150
|
|
148
151
|
it_behaves_like "jpi v1 protected action"
|
149
152
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
+
context 'when authorized' do
|
154
|
+
it 'returns a dashboard' do
|
155
|
+
subject
|
156
|
+
expect(JSON.parse(response.body)).to eq(hash_for_dashboard)
|
157
|
+
end
|
153
158
|
end
|
154
159
|
end
|
155
160
|
|
156
161
|
describe 'PUT #update' do
|
162
|
+
subject { put :update, id: dashboard.id, dashboard: dashboard_params }
|
163
|
+
|
164
|
+
include_context "#{described_class}: dashboard dependencies stubs"
|
165
|
+
|
157
166
|
before do
|
158
167
|
api_stub_for(
|
159
168
|
get: "users/#{user.id}/dashboards/#{dashboard.id}",
|
@@ -163,10 +172,8 @@ module MnoEnterprise
|
|
163
172
|
put: "dashboards/#{dashboard.id}",
|
164
173
|
response: from_api(dashboard)
|
165
174
|
)
|
175
|
+
allow(ability).to receive(:can?).with(:update_impac_dashboards, any_args).and_return(true)
|
166
176
|
end
|
167
|
-
include_context "#{described_class}: dashboard dependencies stubs"
|
168
|
-
|
169
|
-
subject { put :update, id: dashboard.id, dashboard: dashboard_params }
|
170
177
|
|
171
178
|
it_behaves_like "jpi v1 protected action"
|
172
179
|
|
@@ -177,6 +184,10 @@ module MnoEnterprise
|
|
177
184
|
end
|
178
185
|
|
179
186
|
describe "DELETE destroy" do
|
187
|
+
subject { delete :destroy, id: dashboard.id }
|
188
|
+
|
189
|
+
include_context "#{described_class}: dashboard dependencies stubs"
|
190
|
+
|
180
191
|
before do
|
181
192
|
api_stub_for(
|
182
193
|
get: "users/#{user.id}/dashboards/#{dashboard.id}",
|
@@ -186,15 +197,17 @@ module MnoEnterprise
|
|
186
197
|
delete: "dashboards/#{dashboard.id}",
|
187
198
|
response: from_api(dashboard)
|
188
199
|
)
|
200
|
+
allow(ability).to receive(:can?).with(:destroy_impac_dashboards, any_args).and_return(true)
|
189
201
|
end
|
190
|
-
include_context "#{described_class}: dashboard dependencies stubs"
|
191
|
-
|
192
|
-
subject { delete :destroy, id: dashboard.id }
|
193
202
|
|
194
203
|
it_behaves_like "jpi v1 protected action"
|
195
204
|
end
|
196
205
|
|
197
206
|
describe 'POST copy' do
|
207
|
+
subject { post :copy, id: template.id, dashboard: dashboard_params }
|
208
|
+
|
209
|
+
include_context "#{described_class}: dashboard dependencies stubs"
|
210
|
+
|
198
211
|
let(:template) { build(:impac_dashboard, dashboard_type: 'template') }
|
199
212
|
|
200
213
|
before do
|
@@ -207,10 +220,8 @@ module MnoEnterprise
|
|
207
220
|
post: "/dashboards/#{template.id}/copy",
|
208
221
|
response: from_api(dashboard)
|
209
222
|
)
|
223
|
+
allow(ability).to receive(:can?).with(:create_impac_dashboards, any_args).and_return(true)
|
210
224
|
end
|
211
|
-
include_context "#{described_class}: dashboard dependencies stubs"
|
212
|
-
|
213
|
-
subject { post :copy, id: template.id, dashboard: dashboard_params }
|
214
225
|
|
215
226
|
it_behaves_like "jpi v1 protected action"
|
216
227
|
|
@@ -78,7 +78,6 @@ module MnoEnterprise
|
|
78
78
|
|
79
79
|
describe 'POST #create' do
|
80
80
|
shared_examples "create kpi action" do
|
81
|
-
|
82
81
|
it "creates the kpi" do
|
83
82
|
subject
|
84
83
|
expect(assigns(:kpi)).to eq(kpi)
|
@@ -89,6 +88,8 @@ module MnoEnterprise
|
|
89
88
|
|
90
89
|
let (:kpi_targets) { {} }
|
91
90
|
|
91
|
+
before { allow(ability).to receive(:can?).with(:create_impac_kpis, any_args).and_return(true) }
|
92
|
+
|
92
93
|
context "a dashboard KPI" do
|
93
94
|
subject { post :create, dashboard_id: dashboard.id, kpi: kpi_hash }
|
94
95
|
|
@@ -170,6 +171,8 @@ module MnoEnterprise
|
|
170
171
|
end
|
171
172
|
|
172
173
|
describe 'PUT #update' do
|
174
|
+
subject { put :update, id: kpi.id, kpi: kpi_hash.merge(params) }
|
175
|
+
|
173
176
|
RSpec.shared_examples 'a kpi update action' do
|
174
177
|
it "updates the kpi" do
|
175
178
|
subject
|
@@ -233,16 +236,14 @@ module MnoEnterprise
|
|
233
236
|
let(:kpi_hash) { from_api(kpi)[:data].except(:dashboard).merge(element_watched: 'New Watchable') }
|
234
237
|
let(:params) { {} }
|
235
238
|
|
236
|
-
subject { put :update, id: kpi.id, kpi: kpi_hash.merge(params) }
|
237
|
-
|
238
239
|
before do
|
239
240
|
api_stub_for(get: "/kpis/#{kpi.id}", response: from_api(kpi))
|
240
241
|
api_stub_for(put: "/kpis/#{kpi.id}", response: kpi_hash)
|
241
242
|
api_stub_for(get: "/kpis/#{kpi.id}/alerts", response: from_api(alerts_hashes))
|
243
|
+
allow(ability).to receive(:can?).with(:update_impac_kpis, any_args).and_return(true)
|
244
|
+
kpi.save
|
242
245
|
end
|
243
246
|
|
244
|
-
before { kpi.save }
|
245
|
-
|
246
247
|
context "a dashboard KPI" do
|
247
248
|
it_behaves_like "jpi v1 authorizable action"
|
248
249
|
it_behaves_like "a kpi update action"
|
@@ -260,8 +261,11 @@ module MnoEnterprise
|
|
260
261
|
describe 'DELETE #destroy' do
|
261
262
|
subject { delete :destroy, id: kpi.id }
|
262
263
|
|
263
|
-
before
|
264
|
-
|
264
|
+
before do
|
265
|
+
api_stub_for(get: "/kpis/#{kpi.id}", response: from_api(kpi))
|
266
|
+
api_stub_for(delete: "/kpis/#{kpi.id}", response: {message: 'ok', code: 200})
|
267
|
+
allow(ability).to receive(:can?).with(:destroy_impac_kpis, any_args).and_return(true)
|
268
|
+
end
|
265
269
|
|
266
270
|
it_behaves_like "jpi v1 authorizable action"
|
267
271
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module MnoEnterprise
|
4
|
+
RSpec.describe Jpi::V1::Admin::Impac::DashboardsController, type: :routing do
|
5
|
+
routes { MnoEnterprise::Engine.routes }
|
6
|
+
|
7
|
+
it 'routes to #index' do
|
8
|
+
expect(get('/jpi/v1/admin/impac/dashboards')).to route_to('mno_enterprise/jpi/v1/admin/impac/dashboards#index', format: 'json')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'routes to #create' do
|
12
|
+
expect(post('/jpi/v1/admin/impac/dashboards')).to route_to('mno_enterprise/jpi/v1/admin/impac/dashboards#create', format: 'json')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'routes to #update' do
|
16
|
+
expect(put('/jpi/v1/admin/impac/dashboards/2')).to route_to('mno_enterprise/jpi/v1/admin/impac/dashboards#update', id: '2', format: 'json')
|
17
|
+
expect(patch('/jpi/v1/admin/impac/dashboards/2')).to route_to('mno_enterprise/jpi/v1/admin/impac/dashboards#update', id: '2', format: 'json')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'routes to #destroy' do
|
21
|
+
expect(delete('/jpi/v1/admin/impac/dashboards/2')).to route_to('mno_enterprise/jpi/v1/admin/impac/dashboards#destroy', id: '2', format: 'json')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'routes to #copy' do
|
25
|
+
expect(post('/jpi/v1/admin/impac/dashboards/2/copy')).to route_to('mno_enterprise/jpi/v1/admin/impac/dashboards#copy', id: '2', format: 'json')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|