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
@@ -2,6 +2,7 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
module MnoEnterprise
|
4
4
|
describe Jpi::V1::Admin::TenantInvoicesController, type: :controller do
|
5
|
+
include MnoEnterprise::TestingSupport::SharedExamples::JpiV1Admin
|
5
6
|
render_views
|
6
7
|
routes { MnoEnterprise::Engine.routes }
|
7
8
|
before { request.env["HTTP_ACCEPT"] = 'application/json' }
|
@@ -66,6 +67,8 @@ module MnoEnterprise
|
|
66
67
|
describe '#index' do
|
67
68
|
subject { get :index }
|
68
69
|
|
70
|
+
it_behaves_like 'a jpi v1 admin action'
|
71
|
+
|
69
72
|
context 'success' do
|
70
73
|
before { subject }
|
71
74
|
|
@@ -79,6 +82,8 @@ module MnoEnterprise
|
|
79
82
|
describe 'GET #show' do
|
80
83
|
subject { get :show, id: tenant_invoice.id }
|
81
84
|
|
85
|
+
it_behaves_like 'a jpi v1 admin action'
|
86
|
+
|
82
87
|
context 'success' do
|
83
88
|
before { subject }
|
84
89
|
|
@@ -2,6 +2,7 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
module MnoEnterprise
|
4
4
|
describe Jpi::V1::Admin::UsersController, type: :controller do
|
5
|
+
include MnoEnterprise::TestingSupport::SharedExamples::JpiV1Admin
|
5
6
|
render_views
|
6
7
|
routes { MnoEnterprise::Engine.routes }
|
7
8
|
before { request.env["HTTP_ACCEPT"] = 'application/json' }
|
@@ -28,7 +29,8 @@ module MnoEnterprise
|
|
28
29
|
'admin_role' => user.admin_role,
|
29
30
|
'created_at' => user.created_at,
|
30
31
|
'last_sign_in_at' => user.last_sign_in_at,
|
31
|
-
'confirmed_at' => user.confirmed_at
|
32
|
+
'confirmed_at' => user.confirmed_at,
|
33
|
+
'sign_in_count' => user.sign_in_count
|
32
34
|
}
|
33
35
|
end
|
34
36
|
|
@@ -67,6 +69,8 @@ module MnoEnterprise
|
|
67
69
|
describe '#index' do
|
68
70
|
subject { get :index }
|
69
71
|
|
72
|
+
it_behaves_like "a jpi v1 admin action"
|
73
|
+
|
70
74
|
context 'success' do
|
71
75
|
before { subject }
|
72
76
|
|
@@ -80,6 +84,8 @@ module MnoEnterprise
|
|
80
84
|
describe 'GET #show' do
|
81
85
|
subject { get :show, id: user.id }
|
82
86
|
|
87
|
+
it_behaves_like "a jpi v1 admin action"
|
88
|
+
|
83
89
|
context 'success' do
|
84
90
|
before { subject }
|
85
91
|
|
@@ -100,22 +106,27 @@ module MnoEnterprise
|
|
100
106
|
|
101
107
|
user.admin_role = nil
|
102
108
|
api_stub_for(put: "/users/#{user.id}", response: -> { user.admin_role = 'staff'; from_api(user) })
|
103
|
-
subject
|
104
109
|
end
|
105
110
|
|
106
|
-
|
107
|
-
it { expect(response).to be_success }
|
111
|
+
it_behaves_like "a jpi v1 admin action"
|
108
112
|
|
109
|
-
|
110
|
-
|
111
|
-
end
|
113
|
+
context 'success' do
|
114
|
+
before { subject }
|
112
115
|
|
113
|
-
|
114
|
-
|
116
|
+
context 'when admin' do
|
117
|
+
it { expect(response).to be_success }
|
118
|
+
|
119
|
+
# Test that the user is updated by testing the api endpoint was called
|
120
|
+
it { expect(user.admin_role).to eq('staff') }
|
121
|
+
end
|
115
122
|
|
116
|
-
|
123
|
+
context 'when staff' do
|
124
|
+
let(:current_user) { build(:user, :staff) }
|
117
125
|
|
118
|
-
|
126
|
+
it { expect(response).to have_http_status(:unauthorized) }
|
127
|
+
|
128
|
+
it { expect(user.admin_role).to be_nil }
|
129
|
+
end
|
119
130
|
end
|
120
131
|
end
|
121
132
|
|
@@ -126,20 +137,23 @@ module MnoEnterprise
|
|
126
137
|
before do
|
127
138
|
api_stub_for(get: "/users/#{user_to_delete.id}", respond_with: user_to_delete)
|
128
139
|
api_stub_for(delete: "/users/#{user_to_delete.id}", response: ->{ user_to_delete.name = 'deleted'; from_api(user_to_delete) })
|
129
|
-
subject
|
130
140
|
end
|
131
141
|
|
132
|
-
|
142
|
+
it_behaves_like "a jpi v1 admin action"
|
133
143
|
|
134
|
-
|
135
|
-
|
144
|
+
context 'success' do
|
145
|
+
before { subject }
|
146
|
+
|
147
|
+
# Test that the user is deleted by testing the api endpoint was called
|
148
|
+
it { expect(user_to_delete.name).to eq('deleted') }
|
149
|
+
end
|
136
150
|
end
|
137
151
|
|
138
152
|
describe 'POST #signup_email' do
|
139
153
|
let(:email) { 'test@test.com' }
|
140
154
|
subject { post :signup_email, user: {email: email}}
|
141
155
|
|
142
|
-
|
156
|
+
it_behaves_like "a jpi v1 admin action"
|
143
157
|
|
144
158
|
it 'sends the signup instructions' do
|
145
159
|
message_delivery = instance_double(ActionMailer::MessageDelivery)
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module MnoEnterprise
|
4
|
+
describe Jpi::V1::AppAnswersController, 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
|
+
|
11
|
+
#===============================================
|
12
|
+
# Assignments
|
13
|
+
#===============================================
|
14
|
+
let(:user) { build(:user) }
|
15
|
+
before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
|
16
|
+
before { sign_in user }
|
17
|
+
|
18
|
+
let(:app) { build(:app) }
|
19
|
+
let(:answer_1) { build(:app_answer, question_id: 'qid') }
|
20
|
+
let(:answer_2) { build(:app_answer, question_id: 'qid') }
|
21
|
+
let(:expected_hash_for_answer_1) do
|
22
|
+
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)
|
23
|
+
answer_1.attributes.slice(*attrs).merge({'created_at' => answer_1.created_at.as_json, 'updated_at' => answer_1.updated_at.as_json})
|
24
|
+
end
|
25
|
+
let(:expected_hash_for_answer_2) do
|
26
|
+
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)
|
27
|
+
answer_2.attributes.slice(*attrs).merge({'created_at' => answer_2.created_at.as_json, 'updated_at' => answer_2.updated_at.as_json})
|
28
|
+
end
|
29
|
+
let(:expected_hash_for_answers) do
|
30
|
+
{
|
31
|
+
'app_answers' => [expected_hash_for_answer_1, expected_hash_for_answer_2],
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
before do
|
36
|
+
api_stub_for(get: "/apps/#{app.id}", response: from_api(app))
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'GET #index' do
|
40
|
+
|
41
|
+
before do
|
42
|
+
api_stub_for(get: "/app_answers?filter[question_id]=qid&filter[status]=approved", response: from_api([expected_hash_for_answer_1, expected_hash_for_answer_2]))
|
43
|
+
end
|
44
|
+
|
45
|
+
subject { get :index, id: app.id, question_id: 'qid' }
|
46
|
+
|
47
|
+
it_behaves_like "jpi v1 protected action"
|
48
|
+
|
49
|
+
it_behaves_like "a paginated action"
|
50
|
+
|
51
|
+
it 'renders the list of reviews' do
|
52
|
+
subject
|
53
|
+
expect(JSON.parse(response.body)).to eq(expected_hash_for_answers)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'POST #create', focus: true do
|
58
|
+
let(:params) { {organization_id: 1, description: 'A Review', foo: 'bar', question_id: 'qid'} }
|
59
|
+
|
60
|
+
before do
|
61
|
+
api_stub_for(post: "/app_answers", response: from_api(answer_1))
|
62
|
+
api_stub_for(get: "/app_answers/#{answer_1.id}", response: from_api(answer_1))
|
63
|
+
end
|
64
|
+
|
65
|
+
subject { post :create, id: app.id, app_answer: params }
|
66
|
+
|
67
|
+
it_behaves_like "jpi v1 protected action"
|
68
|
+
|
69
|
+
it 'renders the new review' do
|
70
|
+
expect(JSON.parse(subject.body)).to include('app_answer' => expected_hash_for_answer_1)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module MnoEnterprise
|
4
|
+
describe Jpi::V1::AppCommentsController, 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
|
+
|
11
|
+
#===============================================
|
12
|
+
# Assignments
|
13
|
+
#===============================================
|
14
|
+
let(:user) { build(:user) }
|
15
|
+
before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
|
16
|
+
before { sign_in user }
|
17
|
+
|
18
|
+
let(:app) { build(:app) }
|
19
|
+
let(:comment_1) { build(:app_comment, feedback_id: 'fid') }
|
20
|
+
let(:comment_2) { build(:app_comment, feedback_id: 'fid') }
|
21
|
+
let(:expected_hash_for_comment_1) do
|
22
|
+
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)
|
23
|
+
comment_1.attributes.slice(*attrs).merge({'created_at' => comment_1.created_at.as_json, 'updated_at' => comment_1.updated_at.as_json})
|
24
|
+
end
|
25
|
+
let(:expected_hash_for_comment_2) do
|
26
|
+
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)
|
27
|
+
comment_2.attributes.slice(*attrs).merge({'created_at' => comment_2.created_at.as_json, 'updated_at' => comment_2.updated_at.as_json})
|
28
|
+
end
|
29
|
+
let(:expected_hash_for_comments) do
|
30
|
+
{
|
31
|
+
'app_comments' => [expected_hash_for_comment_1, expected_hash_for_comment_2],
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
before do
|
36
|
+
api_stub_for(get: "/apps/#{app.id}", response: from_api(app))
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'GET #index' do
|
40
|
+
|
41
|
+
before do
|
42
|
+
api_stub_for(get: "/app_comments?filter[feedback_id]=fid&filter[status]=approved", response: from_api([expected_hash_for_comment_1, expected_hash_for_comment_2]))
|
43
|
+
end
|
44
|
+
|
45
|
+
subject { get :index, id: app.id, feedback_id: 'fid' }
|
46
|
+
|
47
|
+
it_behaves_like "jpi v1 protected action"
|
48
|
+
|
49
|
+
it_behaves_like "a paginated action"
|
50
|
+
|
51
|
+
it 'renders the list of reviews' do
|
52
|
+
subject
|
53
|
+
expect(JSON.parse(response.body)).to eq(expected_hash_for_comments)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'POST #create', focus: true do
|
58
|
+
let(:params) { {organization_id: 1, description: 'A Review', foo: 'bar', feedback_id: 'fid'} }
|
59
|
+
|
60
|
+
before do
|
61
|
+
api_stub_for(post: "/app_comments", response: from_api(comment_1))
|
62
|
+
api_stub_for(get: "/app_comments/#{comment_1.id}", response: from_api(comment_1))
|
63
|
+
end
|
64
|
+
|
65
|
+
subject { post :create, id: app.id, app_comment: params }
|
66
|
+
|
67
|
+
it_behaves_like "jpi v1 protected action"
|
68
|
+
|
69
|
+
it 'renders the new review' do
|
70
|
+
expect(JSON.parse(subject.body)).to include('app_comment' => expected_hash_for_comment_1)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module MnoEnterprise
|
4
|
+
describe Jpi::V1::AppFeedbacksController, 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
|
+
|
11
|
+
#===============================================
|
12
|
+
# Assignments
|
13
|
+
#===============================================
|
14
|
+
let(:user) { build(:user) }
|
15
|
+
before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
|
16
|
+
before { sign_in user }
|
17
|
+
|
18
|
+
let(:app) { build(:app) }
|
19
|
+
let(:feedback_comment_1) { build(:app_comment) }
|
20
|
+
let(:feedback_comment_2) { build(:app_comment) }
|
21
|
+
let(:app_feedback) { build(:app_feedback, comments: [feedback_comment_1, feedback_comment_2]) }
|
22
|
+
let(:expected_hash_for_comment_1) do
|
23
|
+
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
|
+
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})
|
25
|
+
end
|
26
|
+
let(:expected_hash_for_comment_2) do
|
27
|
+
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)
|
28
|
+
feedback_comment_2.attributes.slice(*attrs).merge({'created_at' => feedback_comment_2.created_at.as_json, 'updated_at' => feedback_comment_2.updated_at.as_json})
|
29
|
+
end
|
30
|
+
let(:expected_array_for_comments) { [expected_hash_for_comment_1, expected_hash_for_comment_2] }
|
31
|
+
let(:expected_hash_for_feedback) do
|
32
|
+
attrs = %w(id rating description status user_id user_name organization_id organization_name app_id app_name user_admin_role comments edited edited_by_name edited_by_admin_role edited_by_id)
|
33
|
+
app_feedback.attributes.slice(*attrs).merge({'created_at' => app_feedback.created_at.as_json, 'updated_at' => app_feedback.updated_at.as_json, 'comments' => expected_array_for_comments})
|
34
|
+
end
|
35
|
+
let(:expected_hash_for_feedbacks) do
|
36
|
+
{
|
37
|
+
'app_feedbacks' => [expected_hash_for_feedback],
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
before do
|
42
|
+
api_stub_for(get: "/apps/#{app.id}", response: from_api(app))
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'GET #index' do
|
46
|
+
|
47
|
+
before do
|
48
|
+
api_stub_for(get: "/app_feedbacks?filter[reviewable_id]=#{app.id}", response: from_api([app_feedback]))
|
49
|
+
end
|
50
|
+
|
51
|
+
subject { get :index, id: app.id }
|
52
|
+
|
53
|
+
it_behaves_like "jpi v1 protected action"
|
54
|
+
|
55
|
+
it_behaves_like "a paginated action"
|
56
|
+
|
57
|
+
it 'renders the list of reviews' do
|
58
|
+
subject
|
59
|
+
expect(JSON.parse(response.body)).to eq(expected_hash_for_feedbacks)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'POST #create', focus: true do
|
64
|
+
let(:params) { {organization_id: 1, description: 'A Review', rating: 5, foo: 'bar'} }
|
65
|
+
|
66
|
+
before do
|
67
|
+
api_stub_for(post: "/app_feedbacks", response: from_api(app_feedback))
|
68
|
+
api_stub_for(get: "/app_feedbacks/#{app_feedback.id}", response: from_api(app_feedback))
|
69
|
+
end
|
70
|
+
|
71
|
+
subject { post :create, id: app.id, app_feedback: params }
|
72
|
+
|
73
|
+
it_behaves_like "jpi v1 protected action"
|
74
|
+
|
75
|
+
it 'renders the new review' do
|
76
|
+
expect(JSON.parse(subject.body)).to include('app_feedback' => expected_hash_for_feedback)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'renders the new average rating' do
|
80
|
+
expect(JSON.parse(subject.body)).to include('average_rating' => app.average_rating)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -15,14 +15,23 @@ module MnoEnterprise
|
|
15
15
|
# Stub user and user call
|
16
16
|
let(:user) { build(:user) }
|
17
17
|
before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
|
18
|
-
|
19
|
-
# Stub organization/app_instance + associations
|
18
|
+
# Stub organization + associations
|
20
19
|
let(:organization) { build(:organization) }
|
21
|
-
let(:app_instance) { build(:app_instance, status: "running") }
|
22
20
|
before { allow_any_instance_of(MnoEnterprise::User).to receive(:organizations).and_return([organization]) }
|
23
|
-
before { allow(organization).to receive(:app_instances).and_return([app_instance]) }
|
24
21
|
|
25
22
|
describe 'GET #index' do
|
23
|
+
let(:app_instance) { build(:app_instance, status: "running") }
|
24
|
+
let(:app_instance) { build(:app_instance, under_free_trial: false) }
|
25
|
+
let(:app_instances) { instance_double('Her::Model::Relation') }
|
26
|
+
|
27
|
+
before do
|
28
|
+
allow(organization).to receive(:app_instances).and_return(app_instances)
|
29
|
+
# Only active instances
|
30
|
+
allow(app_instances).to receive(:active).and_return(app_instances)
|
31
|
+
# Updated since last tick
|
32
|
+
allow(app_instances).to receive(:where).and_return([app_instance])
|
33
|
+
end
|
34
|
+
|
26
35
|
before { sign_in user }
|
27
36
|
let(:timestamp) { nil }
|
28
37
|
subject { get :index, organization_id: organization.id, timestamp: timestamp }
|
@@ -30,35 +39,40 @@ module MnoEnterprise
|
|
30
39
|
it_behaves_like "jpi v1 protected action"
|
31
40
|
|
32
41
|
describe 'all' do
|
33
|
-
|
34
|
-
|
42
|
+
it { subject; expect(assigns(:app_instances)).to eq([app_instance]) }
|
43
|
+
|
44
|
+
it 'filter only active instances' do
|
45
|
+
expect(app_instances).to receive(:active)
|
46
|
+
subject
|
47
|
+
end
|
35
48
|
end
|
36
49
|
|
37
|
-
|
38
|
-
let(:
|
39
|
-
|
40
|
-
it
|
50
|
+
context 'with timestamp' do
|
51
|
+
let(:timestamp) { Time.current.to_i }
|
52
|
+
|
53
|
+
it 'filter updates since last request' do
|
54
|
+
expect(app_instances).to receive(:where).with("updated_at.gt" => Time.at(timestamp))
|
55
|
+
subject
|
56
|
+
end
|
41
57
|
end
|
42
58
|
|
43
|
-
|
59
|
+
context 'without access to the app_instance' do
|
44
60
|
before { allow(ability).to receive(:can?).with(any_args).and_return(false) }
|
45
61
|
before { subject }
|
46
62
|
it { expect(assigns(:app_instances)).to be_empty }
|
47
63
|
end
|
64
|
+
end
|
48
65
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
it { expect(assigns(:app_instances)).to eq([app_instance]) }
|
54
|
-
end
|
66
|
+
describe 'POST #create' do
|
67
|
+
let(:app) { build(:app, nid: 'my-app' ) }
|
68
|
+
let(:app_instance) { build(:app_instance, app: app, owner: organization ) }
|
69
|
+
subject { post :create, organization_id: organization.id, nid: 'my-app' }
|
55
70
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
it { expect(assigns(:app_instances)).to be_empty }
|
60
|
-
end
|
71
|
+
before do
|
72
|
+
api_stub_for(post: "/organizations/#{organization.id}/app_instances", response: from_api(app_instance))
|
73
|
+
api_stub_for(get: "/organizations/#{organization.id}/app_instances", response: from_api([app_instance]))
|
61
74
|
end
|
75
|
+
it_behaves_like "jpi v1 protected action"
|
62
76
|
end
|
63
77
|
|
64
78
|
describe 'DELETE #destroy' do
|