mno-enterprise-api 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -0
  3. data/Rakefile +12 -0
  4. data/app/assets/javascripts/mno_enterprise/angular/loading-page.app.js.coffee +156 -0
  5. data/app/assets/javascripts/mno_enterprise/application.js +13 -0
  6. data/app/controllers/devise/password_expired_controller.rb +55 -0
  7. data/app/controllers/mno_enterprise/auth/confirmations_controller.rb +5 -0
  8. data/app/controllers/mno_enterprise/auth/omniauth_callbacks_controller.rb +30 -0
  9. data/app/controllers/mno_enterprise/auth/passwords_controller.rb +5 -0
  10. data/app/controllers/mno_enterprise/auth/registrations_controller.rb +5 -0
  11. data/app/controllers/mno_enterprise/auth/sessions_controller.rb +7 -0
  12. data/app/controllers/mno_enterprise/auth/unlocks_controller.rb +5 -0
  13. data/app/controllers/mno_enterprise/deletion_requests_controller.rb +5 -0
  14. data/app/controllers/mno_enterprise/impersonate_controller.rb +48 -0
  15. data/app/controllers/mno_enterprise/jpi/v1/admin/audit_events_controller.rb +16 -0
  16. data/app/controllers/mno_enterprise/jpi/v1/admin/base_resource_controller.rb +5 -0
  17. data/app/controllers/mno_enterprise/jpi/v1/admin/cloud_apps_controller.rb +46 -0
  18. data/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb +47 -0
  19. data/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +27 -0
  20. data/app/controllers/mno_enterprise/jpi/v1/admin/tenant_invoices_controller.rb +14 -0
  21. data/app/controllers/mno_enterprise/jpi/v1/admin/users_controller.rb +63 -0
  22. data/app/controllers/mno_enterprise/jpi/v1/app_instances_controller.rb +24 -0
  23. data/app/controllers/mno_enterprise/jpi/v1/app_instances_sync_controller.rb +36 -0
  24. data/app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb +32 -0
  25. data/app/controllers/mno_enterprise/jpi/v1/current_users_controller.rb +5 -0
  26. data/app/controllers/mno_enterprise/jpi/v1/deletion_requests_controller.rb +5 -0
  27. data/app/controllers/mno_enterprise/jpi/v1/impac/dashboards_controller.rb +5 -0
  28. data/app/controllers/mno_enterprise/jpi/v1/impac/kpis_controller.rb +80 -0
  29. data/app/controllers/mno_enterprise/jpi/v1/impac/widgets_controller.rb +63 -0
  30. data/app/controllers/mno_enterprise/jpi/v1/industry_bundle_controller.rb +25 -0
  31. data/app/controllers/mno_enterprise/jpi/v1/marketplace_controller.rb +22 -0
  32. data/app/controllers/mno_enterprise/jpi/v1/organizations_controller.rb +5 -0
  33. data/app/controllers/mno_enterprise/jpi/v1/shopping_cart_controller.rb +93 -0
  34. data/app/controllers/mno_enterprise/jpi/v1/teams_controller.rb +88 -0
  35. data/app/controllers/mno_enterprise/org_invites_controller.rb +5 -0
  36. data/app/controllers/mno_enterprise/pages_controller.rb +5 -0
  37. data/app/controllers/mno_enterprise/provision_controller.rb +5 -0
  38. data/app/controllers/mno_enterprise/status_controller.rb +27 -0
  39. data/app/controllers/mno_enterprise/webhook/o_auth_controller.rb +5 -0
  40. data/app/mailers/mno_enterprise/system_notification_mailer.rb +5 -0
  41. data/app/models/mno_enterprise/health_check.rb +16 -0
  42. data/app/views/devise/password_expired/show.html.haml +32 -0
  43. data/app/views/mno_enterprise/auth/confirmations/default/_form.html.haml +49 -0
  44. data/app/views/mno_enterprise/auth/confirmations/default/_lounge.html.haml +34 -0
  45. data/app/views/mno_enterprise/auth/confirmations/default/_show.html.haml +10 -0
  46. data/app/views/mno_enterprise/auth/confirmations/lounge.html.haml +4 -0
  47. data/app/views/mno_enterprise/auth/confirmations/material/_form.html.haml +44 -0
  48. data/app/views/mno_enterprise/auth/confirmations/material/_lounge.html.haml +18 -0
  49. data/app/views/mno_enterprise/auth/confirmations/material/_show.html.haml +21 -0
  50. data/app/views/mno_enterprise/auth/confirmations/new.html.haml +31 -0
  51. data/app/views/mno_enterprise/auth/confirmations/show.html.haml +4 -0
  52. data/app/views/mno_enterprise/auth/mailer/confirmation_instructions.html.haml +4 -0
  53. data/app/views/mno_enterprise/auth/mailer/reset_password_instructions.html.haml +6 -0
  54. data/app/views/mno_enterprise/auth/mailer/unlock_instructions.html.haml +5 -0
  55. data/app/views/mno_enterprise/auth/passwords/edit.html.haml +53 -0
  56. data/app/views/mno_enterprise/auth/passwords/new.html.haml +34 -0
  57. data/app/views/mno_enterprise/auth/registrations/default/_form.html.haml +35 -0
  58. data/app/views/mno_enterprise/auth/registrations/default/_new.html.haml +11 -0
  59. data/app/views/mno_enterprise/auth/registrations/material/_form.html.haml +30 -0
  60. data/app/views/mno_enterprise/auth/registrations/material/_new.html.haml +10 -0
  61. data/app/views/mno_enterprise/auth/registrations/new.html.haml +4 -0
  62. data/app/views/mno_enterprise/auth/sessions/default/_form.html.haml +17 -0
  63. data/app/views/mno_enterprise/auth/sessions/default/_new.html.haml +11 -0
  64. data/app/views/mno_enterprise/auth/sessions/material/_form.html.haml +26 -0
  65. data/app/views/mno_enterprise/auth/sessions/material/_new.html.haml +11 -0
  66. data/app/views/mno_enterprise/auth/sessions/new.html.haml +4 -0
  67. data/app/views/mno_enterprise/auth/shared/_links.html.haml +24 -0
  68. data/app/views/mno_enterprise/auth/unlocks/new.html.haml +10 -0
  69. data/app/views/mno_enterprise/deletion_requests/show.html.haml +131 -0
  70. data/app/views/mno_enterprise/jpi/v1/admin/audit_events/_audit_event.json.jbuilder +5 -0
  71. data/app/views/mno_enterprise/jpi/v1/admin/audit_events/index.json.jbuilder +4 -0
  72. data/app/views/mno_enterprise/jpi/v1/admin/cloud_apps/_cloud_app.json.jbuilder +1 -0
  73. data/app/views/mno_enterprise/jpi/v1/admin/cloud_apps/index.json.jbuilder +1 -0
  74. data/app/views/mno_enterprise/jpi/v1/admin/cloud_apps/show.json.jbuilder +1 -0
  75. data/app/views/mno_enterprise/jpi/v1/admin/invoices/_invoice.json.jbuilder +2 -0
  76. data/app/views/mno_enterprise/jpi/v1/admin/invoices/index.json.jbuilder +1 -0
  77. data/app/views/mno_enterprise/jpi/v1/admin/invoices/show.json.jbuilder +2 -0
  78. data/app/views/mno_enterprise/jpi/v1/admin/organizations/_credit_card.json.jbuilder +7 -0
  79. data/app/views/mno_enterprise/jpi/v1/admin/organizations/_invoices.json.jbuilder +8 -0
  80. data/app/views/mno_enterprise/jpi/v1/admin/organizations/_member.json.jbuilder +14 -0
  81. data/app/views/mno_enterprise/jpi/v1/admin/organizations/_organization.json.jbuilder +1 -0
  82. data/app/views/mno_enterprise/jpi/v1/admin/organizations/in_arrears.json.jbuilder +8 -0
  83. data/app/views/mno_enterprise/jpi/v1/admin/organizations/index.json.jbuilder +7 -0
  84. data/app/views/mno_enterprise/jpi/v1/admin/organizations/show.json.jbuilder +11 -0
  85. data/app/views/mno_enterprise/jpi/v1/admin/tenant_invoices/_tenant_invoice.json.jbuilder +5 -0
  86. data/app/views/mno_enterprise/jpi/v1/admin/tenant_invoices/index.json.jbuilder +1 -0
  87. data/app/views/mno_enterprise/jpi/v1/admin/tenant_invoices/show.json.jbuilder +1 -0
  88. data/app/views/mno_enterprise/jpi/v1/admin/users/_user.json.jbuilder +1 -0
  89. data/app/views/mno_enterprise/jpi/v1/admin/users/index.json.jbuilder +2 -0
  90. data/app/views/mno_enterprise/jpi/v1/admin/users/show.json.jbuilder +9 -0
  91. data/app/views/mno_enterprise/jpi/v1/app_instances/_resource.json.jbuilder +23 -0
  92. data/app/views/mno_enterprise/jpi/v1/app_instances/index.json.jbuilder +9 -0
  93. data/app/views/mno_enterprise/jpi/v1/app_instances/show.json.jbuilder +3 -0
  94. data/app/views/mno_enterprise/jpi/v1/billing/index.json.jbuilder +0 -0
  95. data/app/views/mno_enterprise/jpi/v1/current_users/show.json.jbuilder +37 -0
  96. data/app/views/mno_enterprise/jpi/v1/impac/dashboards/_dashboard.json.jbuilder +9 -0
  97. data/app/views/mno_enterprise/jpi/v1/impac/dashboards/index.json.jbuilder +1 -0
  98. data/app/views/mno_enterprise/jpi/v1/impac/dashboards/show.json.jbuilder +1 -0
  99. data/app/views/mno_enterprise/jpi/v1/impac/kpis/_kpi.json.jbuilder +1 -0
  100. data/app/views/mno_enterprise/jpi/v1/impac/kpis/show.json.jbuilder +1 -0
  101. data/app/views/mno_enterprise/jpi/v1/impac/widgets/_widget.json.jbuilder +6 -0
  102. data/app/views/mno_enterprise/jpi/v1/impac/widgets/show.json.jbuilder +1 -0
  103. data/app/views/mno_enterprise/jpi/v1/marketplace/_app.json.jbuilder +14 -0
  104. data/app/views/mno_enterprise/jpi/v1/marketplace/index.json.jbuilder +3 -0
  105. data/app/views/mno_enterprise/jpi/v1/marketplace/show.json.jbuilder +3 -0
  106. data/app/views/mno_enterprise/jpi/v1/organizations/_arrears.json.jbuilder +11 -0
  107. data/app/views/mno_enterprise/jpi/v1/organizations/_billing.json.jbuilder +4 -0
  108. data/app/views/mno_enterprise/jpi/v1/organizations/_credit_card.json.jbuilder +7 -0
  109. data/app/views/mno_enterprise/jpi/v1/organizations/_current_user.json.jbuilder +5 -0
  110. data/app/views/mno_enterprise/jpi/v1/organizations/_invoices.json.jbuilder +8 -0
  111. data/app/views/mno_enterprise/jpi/v1/organizations/_member.json.jbuilder +13 -0
  112. data/app/views/mno_enterprise/jpi/v1/organizations/_organization.json.jbuilder +13 -0
  113. data/app/views/mno_enterprise/jpi/v1/organizations/credit_card.json.jbuilder +1 -0
  114. data/app/views/mno_enterprise/jpi/v1/organizations/index.json.jbuilder +1 -0
  115. data/app/views/mno_enterprise/jpi/v1/organizations/members.json.jbuilder +3 -0
  116. data/app/views/mno_enterprise/jpi/v1/organizations/show.json.jbuilder +15 -0
  117. data/app/views/mno_enterprise/jpi/v1/organizations/show_reduced.json.jbuilder +3 -0
  118. data/app/views/mno_enterprise/jpi/v1/shopping_cart/organizations.json.jbuilder +5 -0
  119. data/app/views/mno_enterprise/jpi/v1/shopping_cart/show.json.jbuilder +59 -0
  120. data/app/views/mno_enterprise/jpi/v1/shopping_cart/show_item.json.jbuilder +34 -0
  121. data/app/views/mno_enterprise/jpi/v1/teams/_team.json.jbuilder +20 -0
  122. data/app/views/mno_enterprise/jpi/v1/teams/index.json.jbuilder +1 -0
  123. data/app/views/mno_enterprise/jpi/v1/teams/show.json.jbuilder +3 -0
  124. data/app/views/mno_enterprise/pages/app_access_unauthorized.html.haml +19 -0
  125. data/app/views/mno_enterprise/pages/app_logout.html.haml +18 -0
  126. data/app/views/mno_enterprise/pages/billing_details_required.html.haml +19 -0
  127. data/app/views/mno_enterprise/pages/loading.html.erb +69 -0
  128. data/app/views/mno_enterprise/provision/_provision_apps.html.haml +42 -0
  129. data/app/views/mno_enterprise/provision/_select_organization.html.haml +17 -0
  130. data/app/views/mno_enterprise/provision/new.html.haml +4 -0
  131. data/app/views/mno_enterprise/webhook/o_auth/authorize.html.haml +26 -0
  132. data/app/views/mno_enterprise/webhook/o_auth/providers/myob.html.haml +29 -0
  133. data/app/views/mno_enterprise/webhook/o_auth/providers/xero.html.haml +34 -0
  134. data/config/initializers/devise.rb +273 -0
  135. data/config/initializers/devise_extension.rb +9 -0
  136. data/config/initializers/devise_log.rb +12 -0
  137. data/config/initializers/health_check.rb +35 -0
  138. data/config/initializers/main_app_version.rb +6 -0
  139. data/config/routes.rb +152 -0
  140. data/lib/mno-enterprise-api.rb +1 -0
  141. data/lib/mno_enterprise/api.rb +14 -0
  142. data/lib/mno_enterprise/api/engine.rb +9 -0
  143. data/lib/mno_enterprise/concerns/controllers/deletion_requests_controller.rb +108 -0
  144. data/lib/mno_enterprise/concerns/controllers/jpi/v1/admin/base_resource_controller.rb +34 -0
  145. data/lib/mno_enterprise/concerns/controllers/jpi/v1/current_users_controller.rb +58 -0
  146. data/lib/mno_enterprise/concerns/controllers/jpi/v1/deletion_requests_controller.rb +69 -0
  147. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb +76 -0
  148. data/lib/mno_enterprise/concerns/controllers/jpi/v1/organizations_controller.rb +180 -0
  149. data/lib/mno_enterprise/concerns/controllers/org_invites_controller.rb +44 -0
  150. data/lib/mno_enterprise/concerns/controllers/pages_controller.rb +78 -0
  151. data/lib/mno_enterprise/concerns/controllers/provision_controller.rb +71 -0
  152. data/lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb +107 -0
  153. data/lib/mno_enterprise/concerns/mailers/system_notification_mailer.rb +158 -0
  154. data/lib/mno_enterprise/event_logger.rb +32 -0
  155. data/spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb +68 -0
  156. data/spec/controllers/mno_enterprise/deletion_requests_controller_spec.rb +141 -0
  157. data/spec/controllers/mno_enterprise/impersonate_controller_spec.rb +48 -0
  158. data/spec/controllers/mno_enterprise/jpi/v1/admin/audit_events_controller_spec.rb +51 -0
  159. data/spec/controllers/mno_enterprise/jpi/v1/admin/cloud_apps_controller_spec.rb +92 -0
  160. data/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb +159 -0
  161. data/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb +116 -0
  162. data/spec/controllers/mno_enterprise/jpi/v1/admin/tenant_invoices_controller_spec.rb +92 -0
  163. data/spec/controllers/mno_enterprise/jpi/v1/admin/users_controller_spec.rb +136 -0
  164. data/spec/controllers/mno_enterprise/jpi/v1/app_instances_controller_spec.rb +76 -0
  165. data/spec/controllers/mno_enterprise/jpi/v1/app_instances_sync_controller_spec.rb +94 -0
  166. data/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb +128 -0
  167. data/spec/controllers/mno_enterprise/jpi/v1/deletion_requests_controller_spec.rb +72 -0
  168. data/spec/controllers/mno_enterprise/jpi/v1/impac/kpis_controller_spec.rb +80 -0
  169. data/spec/controllers/mno_enterprise/jpi/v1/marketplace_controller_spec.rb +115 -0
  170. data/spec/controllers/mno_enterprise/jpi/v1/organizations_controller_spec.rb +516 -0
  171. data/spec/controllers/mno_enterprise/jpi/v1/team_controller_spec.rb +86 -0
  172. data/spec/controllers/mno_enterprise/org_invites_controller_spec.rb +29 -0
  173. data/spec/controllers/mno_enterprise/pages_controller_spec.rb +49 -0
  174. data/spec/controllers/mno_enterprise/provision_controller_spec.rb +94 -0
  175. data/spec/controllers/mno_enterprise/status_controller_spec.rb +34 -0
  176. data/spec/controllers/mno_enterprise/webhook/o_auth_controller_spec.rb +104 -0
  177. data/spec/lib/mno_enterprise/event_logger_spec.rb +28 -0
  178. data/spec/mailer/mno_enterprise/system_notification_mailer_spec.rb +132 -0
  179. data/spec/rails_helper.rb +94 -0
  180. data/spec/requests/devise/authentication_spec.rb +43 -0
  181. data/spec/requests/devise/registration_spec.rb +64 -0
  182. data/spec/routing/devise/confirmation_routing_spec.rb +20 -0
  183. data/spec/routing/devise/passwords_routing_spec.rb +24 -0
  184. data/spec/routing/devise/registrations_routing_spec.rb +16 -0
  185. data/spec/routing/devise/sessions_routing_spec.rb +20 -0
  186. data/spec/routing/mno_enterprise/deletion_requests_controller_routing_spec.rb +20 -0
  187. data/spec/routing/mno_enterprise/impersonate_controller_routing.spec.rb +15 -0
  188. data/spec/routing/mno_enterprise/jpi/v1/admin/audit_events_controller_routing_spec.rb +11 -0
  189. data/spec/routing/mno_enterprise/jpi/v1/admin/cloud_apps_controller_routing_spec.rb +24 -0
  190. data/spec/routing/mno_enterprise/jpi/v1/admin/invoices_controller_routing_spec.rb +37 -0
  191. data/spec/routing/mno_enterprise/jpi/v1/admin/organizations_controller_routing_spec.rb +20 -0
  192. data/spec/routing/mno_enterprise/jpi/v1/admin/tenant_invoices_controller_routing_spec.rb +16 -0
  193. data/spec/routing/mno_enterprise/jpi/v1/admin/users_controller_routing_spec.rb +24 -0
  194. data/spec/routing/mno_enterprise/jpi/v1/app_instances_controller_routing_spec.rb +12 -0
  195. data/spec/routing/mno_enterprise/jpi/v1/app_instances_sync_controller_routing_spec.rb +15 -0
  196. data/spec/routing/mno_enterprise/jpi/v1/current_users_controller_routing_spec.rb +28 -0
  197. data/spec/routing/mno_enterprise/jpi/v1/deletion_requests_controller_routing_spec.rb +24 -0
  198. data/spec/routing/mno_enterprise/jpi/v1/impac/kpis_controller_routing_spec.rb +22 -0
  199. data/spec/routing/mno_enterprise/jpi/v1/marketplace_controller_routing_spec.rb +16 -0
  200. data/spec/routing/mno_enterprise/jpi/v1/organizations_controller_routing_spec.rb +44 -0
  201. data/spec/routing/mno_enterprise/jpi/v1/teams_controller_routing_spec.rb +36 -0
  202. data/spec/routing/mno_enterprise/org_invites_controller_routing_spec.rb +12 -0
  203. data/spec/routing/mno_enterprise/pages_controller_routing_spec.rb +29 -0
  204. data/spec/routing/mno_enterprise/provision_controller_routing_spec.rb +15 -0
  205. data/spec/routing/mno_enterprise/status_controller_routing_spec.rb +19 -0
  206. data/spec/routing/mno_enterprise/webhook/o_auth_controller_routing_spec.rb +27 -0
  207. data/spec/spec_helper.rb +88 -0
  208. metadata +402 -0
@@ -0,0 +1,48 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe ImpersonateController, type: :controller do
5
+ render_views
6
+ routes { MnoEnterprise::Engine.routes }
7
+
8
+ # Stub model calls
9
+ let(:user) { build(:user, :admin) }
10
+ let(:user2) { build(:user) }
11
+ before do
12
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
13
+ api_stub_for(put: "/users/#{user.id}", response: from_api(user))
14
+ api_stub_for(get: "/users/#{user2.id}", response: from_api(user2))
15
+ api_stub_for(put: "/users/#{user2.id}", response: from_api(user2))
16
+
17
+ end
18
+
19
+ context "admin user" do
20
+ before do
21
+ sign_in user
22
+ end
23
+
24
+ describe "#create" do
25
+
26
+
27
+ it do
28
+ expect(controller.current_user.id).to eq(user.id)
29
+ get :create, user_id: user2.id
30
+ expect(controller.current_user.id).to eq(user2.id)
31
+ end
32
+ end
33
+
34
+ describe "#destroy" do
35
+ before do
36
+ get :create, user_id: user2.id
37
+ end
38
+
39
+ it { expect(controller.current_user.id).to eq(user2.id) }
40
+
41
+ subject { get :destroy }
42
+
43
+ it { subject; expect(controller.current_user.id).to eq(user.id) }
44
+ end
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,51 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe Jpi::V1::Admin::AuditEventsController, 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
+ # Assignments
12
+ #===============================================
13
+ # Stub controller ability
14
+ # let!(:ability) { stub_ability }
15
+ # before { allow(ability).to receive(:can?).with(any_args).and_return(true) }
16
+
17
+ # # Stub user and user call
18
+ let(:user) { FactoryGirl.build(:user, :admin) }
19
+ before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
20
+ # before { api_stub_for(get: '/users?filter%5Bemail%5D&limit=1', response: from_api(nil)) }
21
+
22
+ before { sign_in user }
23
+
24
+ let(:audit_event) { FactoryGirl.build(:audit_event) }
25
+ before { api_stub_for(get: '/audit_events', response: from_api([audit_event]))}
26
+
27
+ describe 'GET #index' do
28
+ subject { get :index }
29
+
30
+ # TODO it_behaves_like for admin
31
+ # it_behaves_like 'jpi v1 protected action'
32
+
33
+ it 'is successful' do
34
+ subject
35
+ expect(response).to be_success
36
+ end
37
+
38
+ context 'sucess' do
39
+ it 'assigns @audit_events' do
40
+ subject
41
+ expect(assigns(:audit_events).to_a).to eq([audit_event])
42
+ end
43
+
44
+ it 'renders the :index view' do
45
+ subject
46
+ expect(response).to render_template :index
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,92 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe Jpi::V1::Admin::CloudAppsController, type: :controller do
5
+ render_views
6
+ routes { MnoEnterprise::Engine.routes }
7
+ before { request.env["HTTP_ACCEPT"] = 'application/json' }
8
+
9
+ # Stub model calls
10
+ let(:admin) { build(:user, :admin) }
11
+ let(:app) { build(:app, stack: 'cloud', uid: 'cld-1234', name: 'My App', api_key: '28034234') }
12
+
13
+ before do
14
+ api_stub_for(get: "/users/#{admin.id}", response: from_api(admin))
15
+ api_stub_for(get: "/apps", response: from_api([app]))
16
+ api_stub_for(get: "/apps/#{app.id}", response: from_api(app))
17
+ api_stub_for(put: "/apps/#{app.id}", response: from_api(app))
18
+ end
19
+
20
+ context "admin user" do
21
+ before do
22
+ sign_in admin
23
+ end
24
+
25
+ describe "#index" do
26
+ subject { get :index }
27
+
28
+ it 'returns the cloud aplications' do
29
+ subject
30
+ expect(JSON.parse(response.body)).to eq({"cloud_apps"=>[{"id"=>app.id, "uid"=>app.uid, "name"=>app.name, "api_key"=>app.api_key, "tiny_description"=>app.tiny_description, "description"=>app.description, "metadata_url"=>nil, "details"=>nil, "terms_url"=>app.terms_url}]})
31
+ end
32
+ end
33
+
34
+ describe '#update' do
35
+ let(:params) { {name: 'CloudApp', terms_url: 'terms.com'} }
36
+ subject { put :update, id: app.id, cloud_app: params }
37
+
38
+ before { allow(MnoEnterprise::App).to receive(:find) { app } }
39
+
40
+ it 'assigns the cloud app' do
41
+ subject
42
+ expect(assigns[:cloud_app]).to eq(app)
43
+ end
44
+
45
+ it 'updates the cloud app' do
46
+ expect(app).to receive(:save) { true }
47
+ subject
48
+ expect(app.terms_url).to eq(params[:terms_url])
49
+ end
50
+
51
+ it 'only updates authorized fields' do
52
+ subject
53
+ expect(app.name).to eq('My App')
54
+ end
55
+
56
+ it 'is successful' do
57
+ subject
58
+ expect(response).to be_success
59
+ end
60
+ end
61
+
62
+ describe "#regenerate_api_key" do
63
+ subject { put :regenerate_api_key, id: app.id }
64
+
65
+ it 'regenerates the API key' do
66
+ expect_any_instance_of(MnoEnterprise::App).to receive(:regenerate_api_key!)
67
+ subject
68
+ end
69
+ end
70
+
71
+ describe "#refresh_metadata" do
72
+ subject { put :refresh_metadata, id: app.id, metadata_url: 'http://test.com' }
73
+
74
+ context 'with a valid response' do
75
+ it 'refreshes the metadata' do
76
+ expect(subject).to render_template(:show)
77
+ end
78
+ end
79
+
80
+ context 'with an error response' do
81
+ before { expect_any_instance_of(MnoEnterprise::App).to receive(:refresh_metadata!).and_return({errors: [{detail: 'error'}]}) }
82
+
83
+ it 'returns the error message' do
84
+ subject
85
+ expect(JSON.parse(response.body)).to eq({"errors" => [{"detail"=>"error"}]})
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ end
@@ -0,0 +1,159 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe Jpi::V1::Admin::InvoicesController, type: :controller do
5
+ render_views
6
+ routes { MnoEnterprise::Engine.routes }
7
+ before { request.env["HTTP_ACCEPT"] = 'application/json' }
8
+
9
+ def partial_hash_for_invoice(invoice)
10
+ {
11
+ 'id' => invoice.id,
12
+ 'price' => invoice.price,
13
+ 'started_at' => invoice.started_at,
14
+ 'ended_at' => invoice.ended_at,
15
+ 'created_at' => invoice.created_at,
16
+ 'updated_at' => invoice.updated_at,
17
+ 'paid_at' => invoice.paid_at,
18
+ 'slug' => invoice.slug,
19
+ 'tax_pips_applied' => invoice.tax_pips_applied,
20
+ 'billing_address' => invoice.billing_address
21
+ }
22
+ end
23
+
24
+ def hash_for_invoices(invoices)
25
+ {
26
+ 'invoices' => invoices.map { |o| partial_hash_for_invoice(o) }
27
+ }
28
+ end
29
+
30
+ def hash_for_invoice(invoice)
31
+ {
32
+ 'invoice' => partial_hash_for_invoice(invoice)
33
+ }
34
+ end
35
+
36
+ #===============================================
37
+ # Assignments
38
+ #===============================================
39
+ # Stub invoice and invoice call
40
+ let(:invoice) { build(:invoice) }
41
+ let(:user) { build(:user, :admin) }
42
+ let(:tenant) { build(:tenant) }
43
+ let(:org1) { build(:organization, current_billing: Money.new(10_000,'AUD')) }
44
+ let(:org2) { build(:organization, current_billing: Money.new(1000,'AUD')) }
45
+
46
+ before do
47
+ api_stub_for(get: "/invoices", response: from_api([invoice]))
48
+ api_stub_for(get: "/invoices/#{invoice.id}", response: from_api(invoice))
49
+ api_stub_for(get: "/users", response: from_api([user]))
50
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
51
+ api_stub_for(get: "/organizations", response: from_api([org1, org2]))
52
+ api_stub_for(get: "/tenant", response: from_api(tenant))
53
+ sign_in user
54
+ end
55
+
56
+ #===============================================
57
+ # Specs
58
+ #===============================================
59
+ describe '#index' do
60
+ subject { get :index }
61
+
62
+ context 'success' do
63
+ before { subject }
64
+
65
+ it 'returns a list of invoices' do
66
+ expect(response).to be_success
67
+ expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_invoices([invoice]).to_json))
68
+ end
69
+ end
70
+ end
71
+
72
+ describe 'GET #show' do
73
+ subject { get :show, id: invoice.id }
74
+
75
+ context 'success' do
76
+ before { subject }
77
+
78
+ it 'returns a complete description of the invoice' do
79
+ expect(response).to be_success
80
+ expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_invoice(invoice).to_json))
81
+ end
82
+ end
83
+ end
84
+
85
+ describe 'GET #current_billing_amount' do
86
+ subject { get :current_billing_amount }
87
+
88
+ context 'success' do
89
+ before { subject }
90
+
91
+ it { expect(response).to be_success }
92
+
93
+ it 'returns the sum of the current_billing' do
94
+ expected = {'current_billing_amount' => {"amount"=>"110.0", "currency"=>"AUD"}}
95
+ expect(response.body).to eq(expected.to_json)
96
+ end
97
+ end
98
+ end
99
+
100
+ describe 'GET #last_invoicing_amount' do
101
+ subject { get :last_invoicing_amount }
102
+
103
+ context 'success' do
104
+ before { subject }
105
+
106
+ let(:last_invoicing_amount) { {'last_invoicing_amount' => {"amount"=>"6879.94", "currency"=>"AUD"}} }
107
+
108
+ it 'returns the sum of the last invoices' do
109
+ expect(response).to be_success
110
+ expect(JSON.parse(response.body)).to eq(JSON.parse(last_invoicing_amount.to_json))
111
+ end
112
+ end
113
+ end
114
+
115
+ describe 'GET #outstanding_amount' do
116
+ subject { get :outstanding_amount }
117
+
118
+ context 'success' do
119
+ before { subject }
120
+ let(:outstanding_amount) { {'outstanding_amount' => {"amount"=>"1789.86", "currency"=>"AUD"}} }
121
+
122
+ it 'returns the sum of unpaid invoices' do
123
+ expect(response).to be_success
124
+ expect(JSON.parse(response.body)).to eq(JSON.parse(outstanding_amount.to_json))
125
+ end
126
+ end
127
+ end
128
+
129
+ describe 'GET #last_portfolio_amount' do
130
+ subject { get :last_portfolio_amount }
131
+
132
+ context 'success' do
133
+ before { subject }
134
+
135
+ it { expect(response).to be_success }
136
+
137
+ it 'returns a valid amount' do
138
+ expected = {'last_portfolio_amount' => {'amount' => tenant.last_portfolio_amount.amount, 'currency' => tenant.last_portfolio_amount.currency_as_string}}
139
+
140
+ expect(response.body).to eq(expected.to_json)
141
+ end
142
+ end
143
+ end
144
+
145
+ describe 'GET #last_commission_amount' do
146
+ subject { get :last_commission_amount }
147
+
148
+ context 'success' do
149
+ before { subject }
150
+ let(:last_commission_amount) { {'last_commission_amount' => {"amount"=>"4123.45", "currency"=>"AUD"}} }
151
+
152
+ it 'returns the sum of commissions' do
153
+ expect(response).to be_success
154
+ expect(JSON.parse(response.body)).to eq(JSON.parse(last_commission_amount.to_json))
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,116 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe Jpi::V1::Admin::OrganizationsController, type: :controller do
5
+ include MnoEnterprise::TestingSupport::OrganizationsSharedHelpers
6
+ render_views
7
+ routes { MnoEnterprise::Engine.routes }
8
+ before { request.env["HTTP_ACCEPT"] = 'application/json' }
9
+
10
+ def hash_for_arrears(arrears)
11
+ {
12
+ 'in_arrears' => arrears.map { |a| partial_hash_for_arrears(a) }
13
+ }
14
+ end
15
+
16
+ def partial_hash_for_arrears(arrear)
17
+ {
18
+ 'name' => arrear.name,
19
+ 'amount' => AccountingjsSerializer.serialize(arrear.payment),
20
+ 'category' => arrear.category,
21
+ 'status' => arrear.status
22
+ }
23
+ end
24
+
25
+ #===============================================
26
+ # Assignments
27
+ #===============================================
28
+
29
+ # Stub user and user call
30
+ let(:user) { build(:user, admin_role: 'admin') }
31
+ before do
32
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
33
+ sign_in user
34
+ end
35
+
36
+
37
+ # Stub organization + associations
38
+ let!(:invoice) { build(:invoice, organization_id: organization.id) }
39
+ let(:organization) { build(:organization) }
40
+ let(:arrears) { build(:arrears_situation) }
41
+ let(:org_invite) { build(:org_invite, organization: organization) }
42
+ let(:app_instance) { build(:app_instance, organization: organization) }
43
+ let(:credit_card) { build(:credit_card, organization: organization) }
44
+
45
+ before do
46
+ allow_any_instance_of(MnoEnterprise::User).to receive(:organizations).and_return([organization]) # ???
47
+ api_stub_for(get: "/organizations/#{organization.id}/invoices", response: from_api([invoice]))
48
+ api_stub_for(get: "/organizations", response: from_api([organization]))
49
+ api_stub_for(get: "/organizations/#{organization.id}", response: from_api(organization))
50
+ api_stub_for(get: "/organizations/#{organization.id}/users", response: from_api([user]))
51
+ api_stub_for(get: "/organizations/#{organization.id}/org_invites", response: from_api([org_invite]))
52
+ api_stub_for(get: "/organizations/#{organization.id}/app_instances", response: from_api([app_instance]))
53
+ api_stub_for(get: "/organizations/#{organization.id}/credit_card", response: from_api([credit_card]))
54
+ api_stub_for(get: "/arrears_situations", response: from_api([arrears]))
55
+ end
56
+
57
+ let(:expected_hash_for_organizations) {
58
+ {
59
+ 'organizations' => [{
60
+ 'id' => organization.id,
61
+ 'uid' => organization.uid,
62
+ 'name' => organization.name,
63
+ 'soa_enabled' => organization.soa_enabled,
64
+ 'created_at' => organization.created_at,
65
+ 'credit_card' => {'presence' => organization.credit_card?}
66
+ }],
67
+ 'metadata' => {'pagination' => {'count' => 1}}
68
+ }
69
+ }
70
+
71
+ #===============================================
72
+ # Specs
73
+ #===============================================
74
+ describe '#index' do
75
+ subject { get :index }
76
+
77
+ context 'success' do
78
+ before { subject }
79
+
80
+ it { expect(response).to be_success }
81
+
82
+ it 'returns a list of organizations' do
83
+ expect(JSON.parse(response.body)).to eq(JSON.parse(expected_hash_for_organizations.to_json))
84
+ end
85
+ end
86
+ end
87
+
88
+ describe 'GET #show' do
89
+ subject { get :show, id: organization.id }
90
+
91
+ context 'success' do
92
+ before { subject }
93
+
94
+ it { expect(response).to be_success }
95
+
96
+ # TODO: admin and normal views are different we should test another way
97
+ xit 'returns a complete description of the organization' do
98
+ expect(JSON.parse(response.body)).to eq(JSON.parse(admin_hash_for_organization(organization).to_json))
99
+ end
100
+ end
101
+ end
102
+
103
+ describe 'GET #in_arrears' do
104
+ subject { get :in_arrears }
105
+
106
+ context 'success' do
107
+ before { subject }
108
+
109
+ it 'returns arrears with the organization name' do
110
+ expect(response).to be_success
111
+ expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_arrears([arrears]).to_json))
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end