mno-enterprise-api 3.1.4 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/mno_enterprise/config.js.coffee.erb +7 -1
- data/app/controllers/mno_enterprise/auth/omniauth_callbacks_controller.rb +3 -27
- data/app/controllers/mno_enterprise/auth/sessions_controller.rb +1 -3
- data/app/controllers/mno_enterprise/jpi/v1/admin/app_answers_controller.rb +26 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/app_comments_controller.rb +28 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller.rb +16 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/app_reviews_controller.rb +30 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/invites_controller.rb +1 -1
- data/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +55 -37
- data/app/controllers/mno_enterprise/jpi/v1/app_answers_controller.rb +22 -0
- data/app/controllers/mno_enterprise/jpi/v1/app_comments_controller.rb +22 -0
- data/app/controllers/mno_enterprise/jpi/v1/app_feedbacks_controller.rb +14 -0
- data/app/controllers/mno_enterprise/jpi/v1/app_instances_controller.rb +1 -20
- data/app/controllers/mno_enterprise/jpi/v1/app_questions_controller.rb +25 -0
- data/app/controllers/mno_enterprise/jpi/v1/app_reviews_controller.rb +94 -0
- data/app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb +12 -0
- data/app/controllers/mno_enterprise/jpi/v1/impac/alerts_controller.rb +5 -0
- data/app/controllers/mno_enterprise/jpi/v1/impac/kpis_controller.rb +1 -76
- data/app/controllers/mno_enterprise/jpi/v1/marketplace_controller.rb +1 -18
- data/app/controllers/mno_enterprise/jpi/v1/teams_controller.rb +1 -83
- data/app/jobs/mno_enterprise/event_logger_job.rb +10 -0
- data/app/views/mno_enterprise/auth/confirmations/new.html.haml +6 -6
- data/app/views/mno_enterprise/auth/passwords/new.html.haml +8 -8
- data/app/views/mno_enterprise/auth/registrations/new.html.haml +1 -0
- data/app/views/mno_enterprise/auth/sessions/new.html.haml +1 -0
- data/app/views/mno_enterprise/auth/shared/_links.html.haml +0 -5
- data/app/views/mno_enterprise/auth/shared/_omniauth.html.haml +10 -0
- data/app/views/mno_enterprise/jpi/v1/admin/app_answers/show.json.jbuilder +15 -0
- data/app/views/mno_enterprise/jpi/v1/admin/app_comments/show.json.jbuilder +15 -0
- data/app/views/mno_enterprise/jpi/v1/admin/app_reviews/_app_review.json.jbuilder +13 -0
- data/app/views/mno_enterprise/jpi/v1/admin/app_reviews/index.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/app_reviews/show.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/admin/organizations/show.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/users/_user.json.jbuilder +1 -1
- data/app/views/mno_enterprise/jpi/v1/app_answers/_resource.json.jbuilder +4 -0
- data/app/views/mno_enterprise/jpi/v1/app_answers/index.json.jbuilder +5 -0
- data/app/views/mno_enterprise/jpi/v1/app_answers/show.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/app_comments/_resource.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/app_comments/index.json.jbuilder +5 -0
- data/app/views/mno_enterprise/jpi/v1/app_comments/show.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/app_feedbacks/_comment.json.jbuilder +10 -0
- data/app/views/mno_enterprise/jpi/v1/app_feedbacks/_resource.json.jbuilder +7 -0
- data/app/views/mno_enterprise/jpi/v1/app_feedbacks/index.json.jbuilder +5 -0
- data/app/views/mno_enterprise/jpi/v1/app_feedbacks/show.json.jbuilder +4 -0
- data/app/views/mno_enterprise/jpi/v1/app_instances/_resource.json.jbuilder +9 -0
- data/app/views/mno_enterprise/jpi/v1/app_questions/_answer.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/app_questions/_resource.json.jbuilder +8 -0
- data/app/views/mno_enterprise/jpi/v1/app_questions/index.json.jbuilder +5 -0
- data/app/views/mno_enterprise/jpi/v1/app_questions/show.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/app_reviews/_resource.json.jbuilder +13 -0
- data/app/views/mno_enterprise/jpi/v1/app_reviews/index.json.jbuilder +5 -0
- data/app/views/mno_enterprise/jpi/v1/app_reviews/show.json.jbuilder +4 -0
- data/app/views/mno_enterprise/jpi/v1/base_resource/_app_review.json.jbuilder +17 -0
- data/app/views/mno_enterprise/jpi/v1/current_users/show.json.jbuilder +9 -1
- data/app/views/mno_enterprise/jpi/v1/impac/alerts/_alert.json.jbuilder +7 -0
- data/app/views/mno_enterprise/jpi/v1/impac/alerts/index.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/impac/alerts/show.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/impac/dashboards/_dashboard.json.jbuilder +8 -3
- data/app/views/mno_enterprise/jpi/v1/impac/kpis/_kpi.json.jbuilder +4 -1
- data/app/views/mno_enterprise/jpi/v1/impac/widgets/_widget.json.jbuilder +1 -1
- data/app/views/mno_enterprise/jpi/v1/impac/widgets/index.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/marketplace/_app.json.jbuilder +4 -0
- data/app/views/mno_enterprise/jpi/v1/marketplace/index.json.jbuilder +1 -2
- data/app/views/mno_enterprise/jpi/v1/marketplace/show.json.jbuilder +1 -1
- data/app/views/mno_enterprise/jpi/v1/organizations/_current_user.json.jbuilder +1 -1
- data/app/views/mno_enterprise/jpi/v1/organizations/_invoices.json.jbuilder +3 -2
- data/app/views/mno_enterprise/jpi/v1/organizations/_member.json.jbuilder +2 -2
- data/app/views/mno_enterprise/jpi/v1/organizations/_organization.json.jbuilder +2 -2
- data/app/views/mno_enterprise/jpi/v1/teams/_team.json.jbuilder +11 -5
- data/app/views/mno_enterprise/pages/terms.html.haml +219 -0
- data/app/views/mno_enterprise/provision/_select_organization.html.haml +6 -2
- data/config/initializers/devise.rb +31 -9
- data/config/initializers/devise_log.rb +4 -4
- data/config/routes.rb +41 -6
- data/lib/mno_enterprise/api.rb +1 -0
- data/lib/mno_enterprise/audit_events_listener.rb +28 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/app_instances_controller.rb +45 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/current_users_controller.rb +14 -4
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/alerts_controller.rb +76 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb +49 -23
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/kpis_controller.rb +167 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/widgets_controller.rb +33 -17
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/marketplace_controller.rb +32 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/organizations_controller.rb +68 -28
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/teams_controller.rb +92 -0
- data/lib/mno_enterprise/concerns/controllers/pages_controller.rb +17 -3
- data/lib/mno_enterprise/concerns/controllers/provision_controller.rb +17 -2
- data/lib/mno_enterprise/concerns/mailers/system_notification_mailer.rb +27 -3
- data/lib/mno_enterprise/event_logger.rb +34 -16
- data/lib/mno_enterprise/intercom_events_listener.rb +96 -0
- data/spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb +28 -0
- data/spec/controllers/mno_enterprise/auth/omniauth_callback_controller_spec.rb +34 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/app_answers_controller_spec.rb +45 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/app_comments_controller_spec.rb +45 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller_spec.rb +31 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/app_reviews_controller_spec.rb +103 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/audit_events_controller_spec.rb +4 -15
- data/spec/controllers/mno_enterprise/jpi/v1/admin/cloud_apps_controller_spec.rb +12 -3
- data/spec/controllers/mno_enterprise/jpi/v1/admin/invites_controller_spec.rb +4 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb +15 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb +17 -1
- data/spec/controllers/mno_enterprise/jpi/v1/admin/tenant_invoices_controller_spec.rb +5 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/users_controller_spec.rb +30 -16
- data/spec/controllers/mno_enterprise/jpi/v1/app_answers_controller_spec.rb +74 -0
- data/spec/controllers/mno_enterprise/jpi/v1/app_comments_controller_spec.rb +74 -0
- data/spec/controllers/mno_enterprise/jpi/v1/app_feedbacks_controller_spec.rb +84 -0
- data/spec/controllers/mno_enterprise/jpi/v1/app_instances_controller_spec.rb +36 -22
- data/spec/controllers/mno_enterprise/jpi/v1/app_questions_controller_spec.rb +80 -0
- data/spec/controllers/mno_enterprise/jpi/v1/app_reviews_controller_spec.rb +107 -0
- data/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb +16 -1
- data/spec/controllers/mno_enterprise/jpi/v1/impac/alerts_controller_spec.rb +82 -0
- data/spec/controllers/mno_enterprise/jpi/v1/impac/kpis_controller_spec.rb +147 -10
- data/spec/controllers/mno_enterprise/jpi/v1/impac/widgets_controller_spec.rb +39 -0
- data/spec/controllers/mno_enterprise/jpi/v1/marketplace_controller_spec.rb +19 -26
- data/spec/controllers/mno_enterprise/jpi/v1/organizations_controller_spec.rb +248 -303
- data/spec/controllers/mno_enterprise/jpi/v1/team_controller_spec.rb +4 -1
- data/spec/controllers/mno_enterprise/pages_controller_spec.rb +21 -0
- data/spec/controllers/mno_enterprise/provision_controller_spec.rb +65 -22
- data/spec/controllers/mno_enterprise/webhook/o_auth_controller_spec.rb +1 -1
- data/spec/jobs/mno_enterprise/event_logger_job_spec.rb +11 -0
- data/spec/lib/mno_enterprise/audit_events_listener_spec.rb +28 -0
- data/spec/lib/mno_enterprise/intercom_events_listener_spec.rb +110 -0
- data/spec/mailer/mno_enterprise/system_notification_mailer_spec.rb +81 -46
- data/spec/routing/mno_enterprise/jpi/v1/admin/app_instances_controller_routing_spec.rb +11 -0
- data/spec/routing/mno_enterprise/jpi/v1/admin/app_reviews_controller_routing_spec.rb +19 -0
- data/spec/routing/mno_enterprise/jpi/v1/app_instances_controller_routing_spec.rb +9 -2
- data/spec/routing/mno_enterprise/jpi/v1/app_reviews_controller_routing_spec.rb +15 -0
- data/spec/routing/mno_enterprise/jpi/v1/current_users_controller_routing_spec.rb +5 -0
- data/spec/routing/mno_enterprise/jpi/v1/impac/alerts_controller_routing_spec.rb +24 -0
- data/spec/routing/mno_enterprise/jpi/v1/impac/dashboards_controller_routing_spec.rb +28 -0
- data/spec/routing/mno_enterprise/jpi/v1/impac/kpis_controller_routing_spec.rb +17 -11
- data/spec/routing/mno_enterprise/jpi/v1/impac/widgets_controller_routing_spec.rb +24 -0
- data/spec/routing/mno_enterprise/jpi/v1/marketplace_controller_routing_spec.rb +2 -2
- data/spec/routing/mno_enterprise/pages_controller_routing_spec.rb +4 -0
- metadata +178 -9
- data/app/controllers/mno_enterprise/jpi/v1/industry_bundle_controller.rb +0 -25
- data/app/controllers/mno_enterprise/jpi/v1/shopping_cart_controller.rb +0 -93
- data/spec/lib/mno_enterprise/event_logger_spec.rb +0 -28
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module MnoEnterprise
|
4
|
+
describe Jpi::V1::Impac::WidgetsController, 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
|
+
|
10
|
+
# Stub ability
|
11
|
+
let!(:ability) { stub_ability }
|
12
|
+
before { allow(ability).to receive(:can?).with(any_args).and_return(true) }
|
13
|
+
|
14
|
+
# Stub user and user call
|
15
|
+
let!(:user) { build(:user) }
|
16
|
+
before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
|
17
|
+
before { sign_in user }
|
18
|
+
|
19
|
+
describe 'GET index' do
|
20
|
+
let!(:org) { build(:organization) }
|
21
|
+
let!(:widget) { build(:impac_widget, settings: { organization_ids: [org.uid] }) }
|
22
|
+
|
23
|
+
subject { get :index, organization_id: org.uid }
|
24
|
+
|
25
|
+
before { api_stub_for(get: "/users/#{user.id}/organizations", response: from_api([org])) }
|
26
|
+
before { api_stub_for(get: "/organizations/#{org.id}/widgets", response: from_api([widget])) }
|
27
|
+
|
28
|
+
it "returns the widgets" do
|
29
|
+
subject
|
30
|
+
expect(JSON.parse(response.body)).to eq({
|
31
|
+
"widgets" => [
|
32
|
+
{"id"=>widget.id, "endpoint"=>widget.endpoint, "settings"=>{"organization_ids"=>[org.uid]}}
|
33
|
+
]
|
34
|
+
})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -5,9 +5,10 @@ module MnoEnterprise
|
|
5
5
|
render_views
|
6
6
|
routes { MnoEnterprise::Engine.routes }
|
7
7
|
before { request.env["HTTP_ACCEPT"] = 'application/json' }
|
8
|
+
before { Rails.cache.clear }
|
8
9
|
|
9
10
|
let!(:app) { build(:app) }
|
10
|
-
|
11
|
+
|
11
12
|
def markdown(text)
|
12
13
|
return text unless text.present?
|
13
14
|
HtmlProcessor.new(text, format: :markdown).html.html_safe
|
@@ -33,7 +34,11 @@ module MnoEnterprise
|
|
33
34
|
'testimonials' => app.testimonials,
|
34
35
|
'pictures' => app.pictures,
|
35
36
|
'pricing_plans' => app.pricing_plans,
|
36
|
-
'rank' => app.rank
|
37
|
+
'rank' => app.rank,
|
38
|
+
'multi_instantiable' => app.multi_instantiable,
|
39
|
+
'subcategories' => app.subcategories,
|
40
|
+
'average_rating' => app.average_rating,
|
41
|
+
'running_instances_count' => app.running_instances_count
|
37
42
|
}
|
38
43
|
end
|
39
44
|
|
@@ -69,10 +74,7 @@ module MnoEnterprise
|
|
69
74
|
)
|
70
75
|
end
|
71
76
|
|
72
|
-
it
|
73
|
-
subject
|
74
|
-
expect(response).to be_success
|
75
|
-
end
|
77
|
+
it { is_expected.to be_success }
|
76
78
|
|
77
79
|
it 'returns the right response' do
|
78
80
|
subject
|
@@ -86,10 +88,7 @@ module MnoEnterprise
|
|
86
88
|
api_stub_for(get: '/apps', response: from_api([app]))
|
87
89
|
end
|
88
90
|
|
89
|
-
it
|
90
|
-
subject
|
91
|
-
expect(response).to be_success
|
92
|
-
end
|
91
|
+
it { is_expected.to be_success }
|
93
92
|
|
94
93
|
it 'returns the right response' do
|
95
94
|
subject
|
@@ -102,46 +101,40 @@ module MnoEnterprise
|
|
102
101
|
before { api_stub_for(get: "/apps/#{app.id}", response: from_api(app)) }
|
103
102
|
subject { get :show, id: app.id }
|
104
103
|
|
105
|
-
it
|
106
|
-
subject
|
107
|
-
expect(response).to be_success
|
108
|
-
end
|
104
|
+
it { is_expected.to be_success }
|
109
105
|
|
110
106
|
it 'returns the right response' do
|
111
107
|
subject
|
112
108
|
expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_app(app).to_json))
|
113
109
|
end
|
114
110
|
end
|
115
|
-
|
111
|
+
|
116
112
|
describe 'GET #index' do
|
117
113
|
subject { get :index }
|
118
114
|
|
119
|
-
context 'when multiples apps' do
|
115
|
+
context 'when multiples apps' do
|
120
116
|
let(:app1) { build(:app, rank: 5 ) }
|
121
117
|
let(:app2) { build(:app, rank: 0 ) }
|
122
118
|
|
123
|
-
before do
|
119
|
+
before do
|
124
120
|
MnoEnterprise.marketplace_listing = nil
|
125
121
|
api_stub_for(get: '/apps', response: from_api([app1,app2]))
|
126
122
|
end
|
127
123
|
|
128
|
-
it
|
129
|
-
subject
|
130
|
-
expect(response).to be_success
|
131
|
-
end
|
124
|
+
it { is_expected.to be_success }
|
132
125
|
|
133
126
|
it 'returns the right response' do
|
134
127
|
subject
|
135
128
|
expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_apps([app2, app1]).to_json))
|
136
|
-
end
|
129
|
+
end
|
137
130
|
end
|
138
|
-
|
139
|
-
context 'when multiples apps and attributes nil' do
|
131
|
+
|
132
|
+
context 'when multiples apps and attributes nil' do
|
140
133
|
let(:app1) { build(:app, rank: 5 ) }
|
141
134
|
let(:app2) { build(:app, rank: 0 ) }
|
142
135
|
let(:app3) { build(:app, rank: nil ) }
|
143
136
|
|
144
|
-
before do
|
137
|
+
before do
|
145
138
|
MnoEnterprise.marketplace_listing = nil
|
146
139
|
api_stub_for(get: '/apps', response: from_api([app1,app3,app2]))
|
147
140
|
end
|
@@ -149,7 +142,7 @@ module MnoEnterprise
|
|
149
142
|
it 'returns the right response' do
|
150
143
|
subject
|
151
144
|
expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_apps([app2, app1, app3]).to_json))
|
152
|
-
end
|
145
|
+
end
|
153
146
|
end
|
154
147
|
end
|
155
148
|
end
|
@@ -9,7 +9,7 @@ module MnoEnterprise
|
|
9
9
|
routes { MnoEnterprise::Engine.routes }
|
10
10
|
before { request.env["HTTP_ACCEPT"] = 'application/json' }
|
11
11
|
#before { allow_any_instance_of(CreditCard).to receive(:save_to_gateway).and_return(true) }
|
12
|
-
|
12
|
+
|
13
13
|
|
14
14
|
#===============================================
|
15
15
|
# Assignments
|
@@ -17,40 +17,45 @@ module MnoEnterprise
|
|
17
17
|
# Stub controller ability
|
18
18
|
let!(:ability) { stub_ability }
|
19
19
|
before { allow(ability).to receive(:can?).with(any_args).and_return(true) }
|
20
|
-
|
20
|
+
|
21
21
|
# Stub user and user call
|
22
|
-
let(:user) { build(:user) }
|
22
|
+
let(:user) { build(:user, role: 'Admin') }
|
23
23
|
before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
|
24
24
|
before { sign_in user }
|
25
|
-
|
25
|
+
|
26
26
|
# Advanced features - currently disabled
|
27
27
|
let!(:credit_card) { build(:credit_card, organization_id: organization.id) }
|
28
28
|
let!(:invoice) { build(:invoice, organization_id: organization.id) }
|
29
29
|
let!(:org_invite) { build(:org_invite, organization: organization) }
|
30
|
-
|
30
|
+
|
31
31
|
# Stub organization + associations
|
32
32
|
let(:organization) { build(:organization) }
|
33
|
-
|
33
|
+
|
34
|
+
before do
|
35
|
+
organizations = [organization]
|
36
|
+
allow(organizations).to receive(:loaded?).and_return(true)
|
37
|
+
allow_any_instance_of(MnoEnterprise::User).to receive(:organizations).and_return(organizations)
|
38
|
+
end
|
34
39
|
|
35
40
|
before { api_stub_for(post: "/organizations", response: from_api(organization)) }
|
36
41
|
before { api_stub_for(put: "/organizations/#{organization.id}", response: from_api(organization)) }
|
37
42
|
before { api_stub_for(delete: "/organizations/#{organization.id}", response: from_api(nil)) }
|
38
|
-
|
43
|
+
|
39
44
|
before { api_stub_for(get: "/organizations/#{organization.id}/credit_card", response: from_api(credit_card)) }
|
40
45
|
before { api_stub_for(put: "/credit_cards/#{credit_card.id}", response: from_api(credit_card)) }
|
41
|
-
|
42
|
-
|
46
|
+
|
47
|
+
|
43
48
|
before { api_stub_for(get: "/organizations/#{organization.id}/invoices", response: from_api([invoice])) }
|
44
49
|
before { api_stub_for(get: "/organizations/#{organization.id}/org_invites", response: from_api([org_invite])) }
|
45
50
|
before { api_stub_for(get: "/organizations/#{organization.id}/users", response: from_api([user])) }
|
46
51
|
before { api_stub_for(post: "/organizations/#{organization.id}/users", response: from_api(user)) }
|
47
|
-
|
52
|
+
|
48
53
|
#===============================================
|
49
54
|
# Specs
|
50
55
|
#===============================================
|
51
56
|
describe 'GET #index' do
|
52
57
|
subject { get :index }
|
53
|
-
|
58
|
+
|
54
59
|
it_behaves_like "jpi v1 protected action"
|
55
60
|
|
56
61
|
context 'success' do
|
@@ -62,10 +67,10 @@ module MnoEnterprise
|
|
62
67
|
end
|
63
68
|
end
|
64
69
|
end
|
65
|
-
|
70
|
+
|
66
71
|
describe 'GET #show' do
|
67
72
|
subject { get :show, id: organization.id }
|
68
|
-
|
73
|
+
|
69
74
|
it_behaves_like "jpi v1 protected action"
|
70
75
|
|
71
76
|
context 'success' do
|
@@ -86,20 +91,20 @@ module MnoEnterprise
|
|
86
91
|
# end
|
87
92
|
end
|
88
93
|
end
|
89
|
-
|
94
|
+
|
90
95
|
describe 'POST #create' do
|
91
96
|
let(:params) { { 'name' => organization.name } }
|
92
97
|
subject { post :create, organization: params }
|
93
|
-
|
98
|
+
|
94
99
|
it_behaves_like "jpi v1 protected action"
|
95
|
-
|
100
|
+
|
96
101
|
context 'success' do
|
97
102
|
before { subject }
|
98
|
-
|
103
|
+
|
99
104
|
it 'creates the organization' do
|
100
105
|
expect(assigns(:organization).name).to eq(organization.name)
|
101
106
|
end
|
102
|
-
|
107
|
+
|
103
108
|
it 'adds the user as Super Admin' do
|
104
109
|
expect(assigns(:organization).users).to eq([user])
|
105
110
|
end
|
@@ -109,13 +114,13 @@ module MnoEnterprise
|
|
109
114
|
end
|
110
115
|
end
|
111
116
|
end
|
112
|
-
|
117
|
+
|
113
118
|
describe 'PUT #update' do
|
114
119
|
let(:params) { { 'name' => organization.name + 'a', 'soa_enabled' => !organization.soa_enabled } }
|
115
120
|
subject { put :update, id: organization.id, organization: params }
|
116
|
-
|
121
|
+
|
117
122
|
it_behaves_like "jpi v1 authorizable action"
|
118
|
-
|
123
|
+
|
119
124
|
context 'success' do
|
120
125
|
it 'updates the organization' do
|
121
126
|
expect(organization).to receive(:save).and_return(true)
|
@@ -220,297 +225,237 @@ module MnoEnterprise
|
|
220
225
|
subject
|
221
226
|
expect(JSON.parse(response.body)).to eq(partial_hash_for_credit_card(organization.credit_card))
|
222
227
|
end
|
228
|
+
|
229
|
+
describe 'when payment restrictions are set' do
|
230
|
+
before { organization.meta_data = {payment_restriction: [:visa]} }
|
231
|
+
let(:visa) { '4111111111111111' }
|
232
|
+
let(:mastercard) { '5105105105105100' }
|
233
|
+
|
234
|
+
context 'with a valid type' do
|
235
|
+
before { params.merge!(number: visa) }
|
236
|
+
it 'updates the entity credit card' do
|
237
|
+
expect_any_instance_of(MnoEnterprise::CreditCard).to receive(:save).and_return(true)
|
238
|
+
subject
|
239
|
+
expect(organization.credit_card).to_not be_nil
|
240
|
+
expect(organization.credit_card).to be_valid
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'returns a partial representation of the entity' do
|
244
|
+
subject
|
245
|
+
expect(JSON.parse(response.body)).to eq(partial_hash_for_credit_card(organization.credit_card))
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'with an invalid type' do
|
250
|
+
before { params.merge!(number: mastercard) }
|
251
|
+
it 'does not the entity credit card' do
|
252
|
+
expect_any_instance_of(MnoEnterprise::CreditCard).not_to receive(:save)
|
253
|
+
subject
|
254
|
+
expect(organization.credit_card.errors).to_not be_empty
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'returns an error' do
|
258
|
+
subject
|
259
|
+
expect(response).to have_http_status(:bad_request)
|
260
|
+
expect(JSON.parse(response.body)).to eq({"number" => ["Payment is limited to Visa Card Holders"]})
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
223
264
|
end
|
224
265
|
end
|
225
266
|
|
226
|
-
|
227
|
-
|
228
|
-
# let(:params) { [{email: 'newmember@maestrano.com', role: 'Power User', team_id: team.id}] }
|
229
|
-
# subject { put :invite_members, id: organization.id, invites: params }
|
230
|
-
#
|
231
|
-
# it_behaves_like "jpi v1 authorizable action"
|
232
|
-
#
|
233
|
-
# context 'success' do
|
234
|
-
# before { subject }
|
235
|
-
#
|
236
|
-
# it 'creates a new invite' do
|
237
|
-
# invite = organization.org_invites.first
|
238
|
-
# expect(invite.user_email).to eq(params.first[:email])
|
239
|
-
# expect(invite.user_role).to eq(params.first[:role])
|
240
|
-
# expect(invite.organization).to eq(organization)
|
241
|
-
# expect(invite.team).to eq(team)
|
242
|
-
# expect(invite.referrer).to eq(user)
|
243
|
-
# end
|
244
|
-
#
|
245
|
-
# it 'returns a partial representation of the entity' do
|
246
|
-
# organization.reload
|
247
|
-
# expect(JSON.parse(response.body)).to eq(partial_hash_for_members(organization))
|
248
|
-
# end
|
249
|
-
# end
|
250
|
-
# end
|
267
|
+
describe 'PUT #invite_members' do
|
268
|
+
before { api_stub_for(post: "/organizations/#{organization.id}/org_invites", response: from_api(org_invite)) }
|
251
269
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
# let(:params) { { email: 'somemember@maestrano.com', role: 'Admin'} }
|
256
|
-
# subject { put :update_member, id: organization.id, member: params }
|
257
|
-
#
|
258
|
-
# context 'guest' do
|
259
|
-
# before { subject }
|
260
|
-
# it { expect(response.code).to eq("401") }
|
261
|
-
# end
|
262
|
-
#
|
263
|
-
# context 'unauthorized as guest' do
|
264
|
-
# before { sign_in user }
|
265
|
-
# before { subject }
|
266
|
-
# it { expect(response.code).to eq("401") }
|
267
|
-
# end
|
268
|
-
#
|
269
|
-
# context 'unauthorized as member' do
|
270
|
-
# let(:role) { 'Power User' }
|
271
|
-
# before { sign_in user }
|
272
|
-
# before { organization.add_user(user,role) }
|
273
|
-
# before { subject }
|
274
|
-
# it { expect(response.code).to eq("401") }
|
275
|
-
# end
|
276
|
-
#
|
277
|
-
# context 'authorized with member' do
|
278
|
-
# let(:role) { 'Admin' }
|
279
|
-
# let(:member) { build(:user, email: params[:email]) }
|
280
|
-
# before { organization.add_user(user,role) }
|
281
|
-
# before { organization.add_user(member) }
|
282
|
-
# before { sign_in user }
|
283
|
-
# before { subject }
|
284
|
-
#
|
285
|
-
# it 'updates the member role' do
|
286
|
-
# member.reload
|
287
|
-
# expect(member.role(organization)).to eq(params[:role])
|
288
|
-
# end
|
289
|
-
#
|
290
|
-
# it 'returns a partial representation of the entity' do
|
291
|
-
# organization.reload
|
292
|
-
# expect(JSON.parse(response.body)).to eq(partial_hash_for_members(organization))
|
293
|
-
# end
|
294
|
-
# end
|
295
|
-
#
|
296
|
-
# context 'authorized with invite' do
|
297
|
-
# let(:role) { 'Admin' }
|
298
|
-
# let!(:member) { build(:org_invite, user_email: params[:email], organization: organization) }
|
299
|
-
# before { organization.add_user(user,role) }
|
300
|
-
# before { sign_in user }
|
301
|
-
# before { subject }
|
302
|
-
#
|
303
|
-
# it 'updates the member role' do
|
304
|
-
# member.reload
|
305
|
-
# expect(member.user_role).to eq(params[:role])
|
306
|
-
# end
|
307
|
-
#
|
308
|
-
# it 'returns a partial representation of the entity' do
|
309
|
-
# organization.reload
|
310
|
-
# expect(JSON.parse(response.body)).to eq(partial_hash_for_members(organization))
|
311
|
-
# end
|
312
|
-
# end
|
313
|
-
# end
|
314
|
-
#
|
315
|
-
# describe 'PUT #remove_member' do
|
316
|
-
# let(:user) { build(:user) }
|
317
|
-
# let(:organization) { build(:organization) }
|
318
|
-
# let(:params) { { email: 'somemember@maestrano.com', role: 'Admin'} }
|
319
|
-
# subject { put :remove_member, id: organization.id, member: params }
|
320
|
-
#
|
321
|
-
# context 'guest' do
|
322
|
-
# before { subject }
|
323
|
-
# it { expect(response.code).to eq("401") }
|
324
|
-
# end
|
325
|
-
#
|
326
|
-
# context 'unauthorized as guest' do
|
327
|
-
# before { sign_in user }
|
328
|
-
# before { subject }
|
329
|
-
# it { expect(response.code).to eq("401") }
|
330
|
-
# end
|
331
|
-
#
|
332
|
-
# context 'unauthorized as member' do
|
333
|
-
# let(:role) { 'Power User' }
|
334
|
-
# let!(:member) { build(:user, email: params[:email]) }
|
335
|
-
# before { sign_in user }
|
336
|
-
# before { organization.add_user(user,role) }
|
337
|
-
# before { subject }
|
338
|
-
# it { expect(response.code).to eq("401") }
|
339
|
-
# end
|
340
|
-
#
|
341
|
-
# context 'authorized - with member' do
|
342
|
-
# let(:role) { 'Admin' }
|
343
|
-
# let(:member) { build(:user, email: params[:email]) }
|
344
|
-
# before { organization.add_user(user,role) }
|
345
|
-
# before { organization.add_user(member) }
|
346
|
-
# before { sign_in user }
|
347
|
-
# before { subject }
|
348
|
-
#
|
349
|
-
# it 'remove the member' do
|
350
|
-
# member.reload
|
351
|
-
# expect(member.role(organization)).to be_nil
|
352
|
-
# end
|
353
|
-
#
|
354
|
-
# it 'returns a partial representation of the entity' do
|
355
|
-
# organization.reload
|
356
|
-
# expect(JSON.parse(response.body)).to eq(partial_hash_for_members(organization))
|
357
|
-
# end
|
358
|
-
# end
|
359
|
-
#
|
360
|
-
# context 'authorized - with invite' do
|
361
|
-
# let(:role) { 'Admin' }
|
362
|
-
# let!(:invite) { build(:org_invite, organization: organization, user_email: params[:email]) }
|
363
|
-
# before { organization.add_user(user,role) }
|
364
|
-
# before { sign_in user }
|
365
|
-
# before { subject }
|
366
|
-
#
|
367
|
-
# it 'remove the member' do
|
368
|
-
# invite.reload
|
369
|
-
# expect(invite).to be_expired
|
370
|
-
# end
|
371
|
-
#
|
372
|
-
# it 'returns a partial representation of the entity' do
|
373
|
-
# organization.reload
|
374
|
-
# expect(JSON.parse(response.body)).to eq(partial_hash_for_members(organization))
|
375
|
-
# end
|
376
|
-
# end
|
377
|
-
# end
|
270
|
+
let(:team) { build(:team, organization: organization) }
|
271
|
+
let(:params) { [{email: 'newmember@maestrano.com', role: 'Power User', team_id: team.id}] }
|
272
|
+
subject { put :invite_members, id: organization.id, invites: params }
|
378
273
|
|
379
|
-
|
380
|
-
# let(:user) { build(:user) }
|
381
|
-
# let(:organization) { build(:organization) }
|
382
|
-
#
|
383
|
-
# before { allow_any_instance_of(CreditCard).to receive(:save_to_gateway).and_return(true) }
|
384
|
-
# subject { put :update_support_plan, id: organization.id, support_plan:'concierge' }
|
385
|
-
#
|
386
|
-
# context 'guest' do
|
387
|
-
# before { subject }
|
388
|
-
# it { expect(response.code).to eq("401") }
|
389
|
-
# end
|
390
|
-
#
|
391
|
-
# context 'unauthorized as guest' do
|
392
|
-
# before { sign_in user }
|
393
|
-
# before { subject }
|
394
|
-
# it { expect(response.code).to eq("401") }
|
395
|
-
# end
|
396
|
-
#
|
397
|
-
# context 'unauthorized as member' do
|
398
|
-
# let(:role) { 'Admin' }
|
399
|
-
# before { sign_in user }
|
400
|
-
# before { organization.add_user(user,role) }
|
401
|
-
# before { subject }
|
402
|
-
# it { expect(response.code).to eq("401") }
|
403
|
-
# end
|
404
|
-
#
|
405
|
-
# context 'authorized' do
|
406
|
-
# let(:role) { 'Super Admin' }
|
407
|
-
# before { sign_in user }
|
408
|
-
# before { organization.add_user(user,role) }
|
409
|
-
# before { subject }
|
410
|
-
#
|
411
|
-
# it 'updates the entity support plan' do
|
412
|
-
# organization.reload
|
413
|
-
# expect(organization.current_support_plan).to eq('concierge')
|
414
|
-
# end
|
415
|
-
#
|
416
|
-
# it 'returns a partial representation of the entity' do
|
417
|
-
# organization.reload
|
418
|
-
# expect(JSON.parse(response.body)).to eq(partial_hash_for_organization(organization))
|
419
|
-
# end
|
420
|
-
# end
|
421
|
-
# end
|
274
|
+
it_behaves_like "jpi v1 authorizable action"
|
422
275
|
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
# end
|
455
|
-
# }
|
456
|
-
# before { sign_in user }
|
457
|
-
# before { organization.add_user(user) }
|
458
|
-
# let(:delay) { double(:delay) }
|
459
|
-
# before { PartnerMailer.stub(:delay).and_return(delay) }
|
460
|
-
#
|
461
|
-
# it "sends an email to the account manager with the customer's enquiry" do
|
462
|
-
# Timecop.freeze(now + 6.months) do
|
463
|
-
# expect(delay).to receive(:contact_partner).with({"message"=>"I would like to be trained on blabla", "first_name"=>user.name, "last_name"=>user.surname, "email"=>user.email})
|
464
|
-
# subject
|
465
|
-
# end
|
466
|
-
# end
|
467
|
-
#
|
468
|
-
# it "consume a custom training session credit" do
|
469
|
-
# delay.stub(:contact_partner).and_return(true)
|
470
|
-
# Timecop.freeze(now + 8.months) do
|
471
|
-
# subject
|
472
|
-
# expect(organization.support_plan.custom_training_credits).to eq(0)
|
473
|
-
# end
|
474
|
-
# end
|
475
|
-
#
|
476
|
-
# it 'returns a partial representation of the entity' do
|
477
|
-
# delay.stub(:contact_partner).and_return(true)
|
478
|
-
# Timecop.freeze(now + 6.months) do
|
479
|
-
# subject
|
480
|
-
# organization.reload
|
481
|
-
# expect(JSON.parse(response.body)).to eq(partial_hash_for_organization(organization))
|
482
|
-
# end
|
483
|
-
# end
|
484
|
-
# end
|
485
|
-
# end
|
276
|
+
context 'succcess' do
|
277
|
+
let(:relation) { instance_double('Her::Model::Relation') }
|
278
|
+
before do
|
279
|
+
allow(relation).to receive(:active).and_return(relation)
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'creates an invitation' do
|
283
|
+
# For the view
|
284
|
+
allow(organization).to receive(:members).and_return([org_invite])
|
285
|
+
|
286
|
+
expect(organization).to receive(:org_invites).and_return(relation)
|
287
|
+
expect(relation).to receive(:create).with(
|
288
|
+
user_email: 'newmember@maestrano.com',
|
289
|
+
user_role: 'Power User',
|
290
|
+
team_id: team.id.to_s,
|
291
|
+
referrer_id: user.id
|
292
|
+
).and_return(org_invite)
|
293
|
+
subject
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'sends a notification email' do
|
297
|
+
expect(MnoEnterprise::SystemNotificationMailer).to receive(:organization_invite).with(org_invite).and_call_original
|
298
|
+
subject
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'returns a partial representation of the entity' do
|
302
|
+
subject
|
303
|
+
expect(JSON.parse(response.body)).to eq({'members' => partial_hash_for_members(organization)})
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
486
307
|
|
487
|
-
|
308
|
+
describe 'PUT #update_member' do
|
488
309
|
# let(:user) { build(:user) }
|
489
310
|
# let(:organization) { build(:organization) }
|
490
|
-
# subject { put :update_meta_data, name:'field_example', value:'test', id: organization.id }
|
491
|
-
#
|
492
|
-
# context "when organization has update rights" do
|
493
|
-
# let(:role) { 'Super Admin' }
|
494
|
-
# before { sign_in user }
|
495
|
-
# before { organization.add_user(user,role) }
|
496
|
-
#
|
497
|
-
# it { expect(subject).to be_success }
|
498
|
-
#
|
499
|
-
# it "calls put_meta_data with the rights args" do
|
500
|
-
# Organization.any_instance.should_receive(:put_meta_data).with('field_example','test')
|
501
|
-
# subject
|
502
|
-
# end
|
503
|
-
# end
|
504
|
-
#
|
505
|
-
# context "when user is not logged in" do
|
506
|
-
# before { sign_in user }
|
507
|
-
# before { organization.add_user(user) }
|
508
|
-
#
|
509
|
-
# it "is not successful" do
|
510
|
-
# expect(subject).to_not be_success
|
511
|
-
# end
|
512
|
-
# end
|
513
|
-
# end
|
514
311
|
|
312
|
+
before { api_stub_for(put: "/org_invites/#{org_invite.id}")}
|
313
|
+
|
314
|
+
let(:email) { 'somemember@maestrano.com' }
|
315
|
+
let(:role) { 'Admin' }
|
316
|
+
let(:params) { { email: email, role: role} }
|
317
|
+
subject { put :update_member, id: organization.id, member: params }
|
318
|
+
|
319
|
+
it_behaves_like "jpi v1 authorizable action"
|
320
|
+
|
321
|
+
context 'with user' do
|
322
|
+
let(:member) { build(:user) }
|
323
|
+
let(:email) { member.email }
|
324
|
+
# No verifying double as this rely on method_missing and proxying
|
325
|
+
let(:collection) { double('Her::Collection') }
|
326
|
+
|
327
|
+
before do
|
328
|
+
allow(collection).to receive(:to_a).and_return([member])
|
329
|
+
allow(organization).to receive(:users).and_return(collection)
|
330
|
+
end
|
331
|
+
|
332
|
+
# Happy path
|
333
|
+
it 'updates the member role' do
|
334
|
+
expect(collection).to receive(:update).with(id: member.id, role: params[:role])
|
335
|
+
subject
|
336
|
+
end
|
337
|
+
|
338
|
+
# Exceptions
|
339
|
+
context 'when admin' do
|
340
|
+
context 'assign super admin role' do
|
341
|
+
let(:role) { 'Super Admin' }
|
342
|
+
it 'denies access' do
|
343
|
+
expect(subject).to_not be_successful
|
344
|
+
expect(subject.code).to eq('403')
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context 'edit super admin' do
|
349
|
+
let(:member) { build(:user, role: 'Super Admin') }
|
350
|
+
let(:role) { 'Member' }
|
351
|
+
|
352
|
+
it 'denies access' do
|
353
|
+
expect(subject).to_not be_successful
|
354
|
+
expect(subject.code).to eq('403')
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
context 'last super admin changing his role' do
|
360
|
+
let(:user) { build(:user, role: 'Super Admin') }
|
361
|
+
let(:member) { user }
|
362
|
+
let(:role) { 'Member' }
|
363
|
+
|
364
|
+
it 'denies access' do
|
365
|
+
expect(subject).to_not be_successful
|
366
|
+
expect(subject.code).to eq('403')
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context 'with invite' do
|
372
|
+
let(:relation) { instance_double('Her::Model::Relation') }
|
373
|
+
|
374
|
+
before do
|
375
|
+
allow(relation).to receive(:active).and_return(relation)
|
376
|
+
allow(relation).to receive(:where).and_return([org_invite])
|
377
|
+
|
378
|
+
allow(organization).to receive(:org_invites).and_return(relation)
|
379
|
+
# For the view
|
380
|
+
allow(organization).to receive(:members).and_return([org_invite])
|
381
|
+
end
|
382
|
+
|
383
|
+
|
384
|
+
# Happy Path
|
385
|
+
it 'updates the member role' do
|
386
|
+
expect(org_invite).to receive(:update).with(user_role: params[:role])
|
387
|
+
subject
|
388
|
+
end
|
389
|
+
|
390
|
+
# Exceptions
|
391
|
+
context 'when admin' do
|
392
|
+
context 'assign super admin role' do
|
393
|
+
let(:role) { 'Super Admin' }
|
394
|
+
it 'denies access' do
|
395
|
+
expect(subject).to_not be_successful
|
396
|
+
expect(subject.code).to eq('403')
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
context 'edit super admin' do
|
401
|
+
let!(:org_invite) { build(:org_invite, organization: organization, user_role: 'Super Admin') }
|
402
|
+
let(:role) { 'Member' }
|
403
|
+
|
404
|
+
it 'denies access' do
|
405
|
+
expect(subject).to_not be_successful
|
406
|
+
expect(subject.code).to eq('403')
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
it 'renders a the user list' do
|
413
|
+
subject
|
414
|
+
expect(JSON.parse(response.body)).to eq({'members' => partial_hash_for_members(organization)})
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
describe 'PUT #remove_member' do
|
419
|
+
before do
|
420
|
+
api_stub_for(delete: "/organizations/#{organization.id}/users/#{user.id}", response: from_api(nil))
|
421
|
+
api_stub_for(put: "/org_invites/#{org_invite.id}", response: from_api(nil))
|
422
|
+
end
|
423
|
+
|
424
|
+
let(:params) { { email: 'somemember@maestrano.com' } }
|
425
|
+
subject { put :remove_member, id: organization.id, member: params }
|
426
|
+
|
427
|
+
it_behaves_like "jpi v1 authorizable action"
|
428
|
+
|
429
|
+
|
430
|
+
context 'with user' do
|
431
|
+
let(:params) { { email: user.email } }
|
432
|
+
it 'removes the member' do
|
433
|
+
expect(organization).to receive(:remove_user).with(user).and_call_original
|
434
|
+
subject
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
context 'with invite' do
|
439
|
+
let(:relation) { instance_double('Her::Model::Relation') }
|
440
|
+
before do
|
441
|
+
allow(relation).to receive(:active).and_return(relation)
|
442
|
+
allow(relation).to receive(:where).and_return([org_invite])
|
443
|
+
|
444
|
+
allow(organization).to receive(:org_invites).and_return(relation)
|
445
|
+
# For the view
|
446
|
+
allow(organization).to receive(:members).and_return([org_invite])
|
447
|
+
end
|
448
|
+
|
449
|
+
it 'removes the member' do
|
450
|
+
expect(org_invite).to receive(:cancel!)
|
451
|
+
subject
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
it 'renders a the user list' do
|
456
|
+
subject
|
457
|
+
expect(JSON.parse(response.body)).to eq({'members' => partial_hash_for_members(organization)})
|
458
|
+
end
|
459
|
+
end
|
515
460
|
end
|
516
461
|
end
|