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,92 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe Jpi::V1::Admin::TenantInvoicesController, 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_tenant_invoices(tenant_invoice)
10
+ {
11
+ 'id' => tenant_invoice.id,
12
+ 'started_at' => tenant_invoice.started_at,
13
+ 'ended_at' => tenant_invoice.ended_at,
14
+ 'created_at' => tenant_invoice.created_at,
15
+ 'updated_at' => tenant_invoice.updated_at,
16
+ 'slug' => tenant_invoice.slug,
17
+ 'paid_at' => tenant_invoice.paid_at,
18
+ 'total_portfolio_amount' => AccountingjsSerializer.serialize(tenant_invoice.total_portfolio_amount),
19
+ 'total_commission_amount' => AccountingjsSerializer.serialize(tenant_invoice.total_commission_amount),
20
+ 'non_commissionable_amount' => AccountingjsSerializer.serialize(tenant_invoice.non_commissionable_amount)
21
+ }
22
+ end
23
+
24
+ def partial_hash_for_tenant_invoice(tenant_invoice)
25
+ {
26
+ 'id' => tenant_invoice.id,
27
+ 'started_at' => tenant_invoice.started_at,
28
+ 'created_at' => tenant_invoice.created_at,
29
+ 'ended_at' => tenant_invoice.ended_at,
30
+ 'updated_at' => tenant_invoice.updated_at,
31
+ 'paid_at' => tenant_invoice.paid_at,
32
+ 'slug' => tenant_invoice.slug
33
+ }
34
+ end
35
+
36
+ def hash_for_tenant_invoices(tenant_invoices)
37
+ {
38
+ 'tenant_invoices' => tenant_invoices.map { |o| partial_hash_for_tenant_invoices(o) }
39
+ }
40
+
41
+ end
42
+
43
+ def hash_for_tenant_invoice(tenant_invoice)
44
+ {
45
+ 'tenant_invoice' => partial_hash_for_tenant_invoice(tenant_invoice)
46
+ }
47
+ end
48
+
49
+ #===============================================
50
+ # Assignments
51
+ #===============================================
52
+ # Stub tenant_invoice and tenant_invoice call
53
+ let!(:tenant_invoice) { build(:tenant_invoice) }
54
+ let!(:user) { build(:user, :admin) }
55
+ before do
56
+ api_stub_for(get: "/tenant_invoices", response: from_api([tenant_invoice]))
57
+ api_stub_for(get: "/tenant_invoices/#{tenant_invoice.id}", response: from_api(tenant_invoice))
58
+ api_stub_for(get: "/users", response: from_api([user]))
59
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
60
+ sign_in user
61
+ end
62
+
63
+ #===============================================
64
+ # Specs
65
+ #===============================================
66
+ describe '#index' do
67
+ subject { get :index }
68
+
69
+ context 'success' do
70
+ before { subject }
71
+
72
+ it 'returns a list of tenant_invoices' do
73
+ expect(response).to be_success
74
+ expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_tenant_invoices([tenant_invoice]).to_json))
75
+ end
76
+ end
77
+ end
78
+
79
+ describe 'GET #show' do
80
+ subject { get :show, id: tenant_invoice.id }
81
+
82
+ context 'success' do
83
+ before { subject }
84
+
85
+ it 'returns a complete description of the tenant_invoice' do
86
+ expect(response).to be_success
87
+ expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_tenant_invoice(tenant_invoice).to_json))
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,136 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe Jpi::V1::Admin::UsersController, 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_organization(user)
10
+ user.organizations.map do |org|
11
+ {
12
+ 'id' => org.id,
13
+ 'uid' => org.uid,
14
+ 'name' => org.name,
15
+ 'created_at' => org.created_at
16
+ }
17
+ end
18
+ end
19
+
20
+ def partial_hash_for_user(user)
21
+ {
22
+ 'id' => user.id,
23
+ 'uid' => user.uid,
24
+ 'email' => user.email,
25
+ 'phone' => user.phone,
26
+ 'name' => user.name,
27
+ 'surname' => user.surname,
28
+ 'admin_role' => user.admin_role,
29
+ 'created_at' => user.created_at,
30
+ 'last_sign_in_at' => user.last_sign_in_at,
31
+ 'confirmed_at' => user.confirmed_at,
32
+ 'organizations' => partial_hash_for_organization(user)
33
+ }
34
+ end
35
+
36
+ def partial_hash_for_users(user)
37
+ {
38
+ 'id' => user.id,
39
+ 'uid' => user.uid,
40
+ 'email' => user.email,
41
+ 'name' => user.name,
42
+ 'surname' => user.surname,
43
+ 'admin_role' => user.admin_role,
44
+ 'created_at' => user.created_at
45
+ }
46
+ end
47
+
48
+ def hash_for_users(users)
49
+ {
50
+ 'users' => users.map { |o| partial_hash_for_users(o) },
51
+ 'metadata' => {'pagination' => {'count' => users.count}}
52
+ }
53
+ end
54
+
55
+ def hash_for_user(user)
56
+ hash = {
57
+ 'user' => partial_hash_for_user(user)
58
+ }
59
+
60
+ return hash
61
+ end
62
+
63
+ #===============================================
64
+ # Assignments
65
+ #===============================================
66
+ # Stub user and user call
67
+ let(:user) { build(:user, :admin, :with_organizations) }
68
+ before do
69
+ api_stub_for(get: "/users", response: from_api([user]))
70
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
71
+ api_stub_for(get: "/users/#{user.id}/organizations", response: from_api(user))
72
+ sign_in user
73
+ end
74
+
75
+ #==========================
76
+ # =====================
77
+ # Specs
78
+ #===============================================
79
+ describe '#index' do
80
+ subject { get :index }
81
+
82
+ context 'success' do
83
+ before { subject }
84
+
85
+ it 'returns a list of users' do
86
+ expect(response).to be_success
87
+ expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_users([user]).to_json))
88
+ end
89
+ end
90
+ end
91
+
92
+ describe 'GET #show' do
93
+ subject { get :show, id: user.id }
94
+
95
+ context 'success' do
96
+ before { subject }
97
+
98
+ it 'returns a complete description of the user' do
99
+ expect(response).to be_success
100
+ expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_user(user).to_json))
101
+ end
102
+ end
103
+ end
104
+
105
+ describe 'PUT #update' do
106
+ subject { put :update, id: user.id, user: {admin_role: 'staff'} }
107
+
108
+ before do
109
+ api_stub_for(put: "/users/#{user.id}", response: ->{ user.admin_role = 'staff'; from_api(user) })
110
+ subject
111
+ end
112
+
113
+ it { expect(response).to be_success }
114
+
115
+ # Test that the user is updated by testing the api endpoint was called
116
+ it { expect(user.admin_role).to eq('staff') }
117
+ end
118
+
119
+ describe 'DELETE #destroy' do
120
+ let(:user_to_delete) { build(:user) }
121
+ subject { delete :destroy, id: user_to_delete.id }
122
+
123
+ before do
124
+ api_stub_for(get: "/users/#{user_to_delete.id}", respond_with: user_to_delete)
125
+ api_stub_for(delete: "/users/#{user_to_delete.id}", response: ->{ user_to_delete.name = 'deleted'; from_api(user_to_delete) })
126
+ subject
127
+ end
128
+
129
+ it { expect(response).to be_success }
130
+
131
+ # Test that the user is deleted by testing the api endpoint was called
132
+ it { expect(user_to_delete.name).to eq('deleted') }
133
+
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,76 @@
1
+ require 'rails_helper'
2
+
3
+ # TODO: spec AppInstance response
4
+ module MnoEnterprise
5
+ describe Jpi::V1::AppInstancesController, type: :controller do
6
+ include MnoEnterprise::TestingSupport::JpiV1TestHelper
7
+ render_views
8
+ routes { MnoEnterprise::Engine.routes }
9
+ before { request.env["HTTP_ACCEPT"] = 'application/json' }
10
+
11
+ # Stub ability
12
+ let!(:ability) { stub_ability }
13
+ before { allow(ability).to receive(:can?).with(any_args).and_return(true) }
14
+
15
+ # Stub user and user call
16
+ let(:user) { build(:user) }
17
+ before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
18
+
19
+ # Stub organization/app_instance + associations
20
+ let(:organization) { build(:organization) }
21
+ let(:app_instance) { build(:app_instance, status: "running") }
22
+ 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
+
25
+ describe 'GET #index' do
26
+ before { sign_in user }
27
+ let(:timestamp) { nil }
28
+ subject { get :index, organization_id: organization.id, timestamp: timestamp }
29
+
30
+ it_behaves_like "jpi v1 protected action"
31
+
32
+ describe 'all' do
33
+ before { subject }
34
+ it { expect(assigns(:app_instances)).to eq([app_instance]) }
35
+ end
36
+
37
+ describe 'with inactive app_instances' do
38
+ let(:app_instance) { build(:app_instance, status: "terminated", terminated_at: 10.minutes.ago) }
39
+ before { subject }
40
+ it { expect(assigns(:app_instances)).to be_empty }
41
+ end
42
+
43
+ describe 'with no access to the app_instance' do
44
+ before { allow(ability).to receive(:can?).with(any_args).and_return(false) }
45
+ before { subject }
46
+ it { expect(assigns(:app_instances)).to be_empty }
47
+ end
48
+
49
+ describe 'with timestamp' do
50
+ describe 'before instance updated_at' do
51
+ let(:timestamp) { (app_instance.updated_at - 2.minutes).to_i }
52
+ before { subject }
53
+ it { expect(assigns(:app_instances)).to eq([app_instance]) }
54
+ end
55
+
56
+ describe 'after instance updated_at' do
57
+ let(:timestamp) { (app_instance.updated_at + 2.minutes).to_i }
58
+ before { subject }
59
+ it { expect(assigns(:app_instances)).to be_empty }
60
+ end
61
+ end
62
+ end
63
+
64
+ describe 'DELETE #destroy' do
65
+ let(:app_instance) { build(:app_instance) }
66
+ before { api_stub_for(get: "/app_instances/#{app_instance.id}", respond_with: app_instance)}
67
+ before { api_stub_for(delete: "/app_instances/#{app_instance.id}", response: ->{ app_instance.status = 'terminated'; from_api(app_instance) }) }
68
+ before { sign_in user }
69
+ subject { delete :destroy, id: app_instance.id }
70
+
71
+ it_behaves_like "jpi v1 protected action"
72
+
73
+ it { subject; expect(app_instance.status).to eq('terminated')}
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,94 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe Jpi::V1::AppInstancesSyncController, type: :controller do
5
+ include MnoEnterprise::TestingSupport::JpiV1TestHelper
6
+ # include MnoEnterprise::TestingSupport::OrganizationsSharedHelpers
7
+
8
+ render_views
9
+ routes { MnoEnterprise::Engine.routes }
10
+ before { request.env["HTTP_ACCEPT"] = 'application/json' }
11
+
12
+
13
+ #===============================================
14
+ # Assignments
15
+ #===============================================
16
+ # Stub controller ability
17
+ let!(:ability) { stub_ability }
18
+ before { allow(ability).to receive(:can?).with(any_args).and_return(true) }
19
+
20
+ # Stub user and user call
21
+ let(:user) { build(:user) }
22
+ before do
23
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
24
+ api_stub_for(put: "/users/#{user.id}", response: from_api(user))
25
+ end
26
+ before { sign_in user }
27
+
28
+ # Stub organization
29
+ let(:organization) { build(:organization) }
30
+ before { allow_any_instance_of(MnoEnterprise::User).to receive(:organizations).and_return([organization]) }
31
+
32
+
33
+ #===============================================
34
+ # Specs
35
+ #===============================================
36
+ describe 'GET #index' do
37
+ # App instances
38
+ let(:app1) { build(:app_instance, owner: organization, status: 'running') }
39
+ let(:app2) { build(:app_instance, owner: organization, status: 'running') }
40
+ before { api_stub_for(put: "/app_instances/#{app1.id}", response: from_api(app1)) }
41
+ before { api_stub_for(put: "/app_instances/#{app2.id}", response: from_api(app2)) }
42
+ before { app1.save ; app2.save }
43
+
44
+ # Apps sync
45
+ let(:progress_results) { { connectors: [
46
+ HashWithIndifferentAccess.new({name: 'a_name', status: 'RUNNING', date: nil}),
47
+ HashWithIndifferentAccess.new({name: 'a_name', status: 'FAILED', date: nil})
48
+ ] } }
49
+ before { api_stub_for(get: "/organizations/#{organization.id}/app_instances_sync/anything", response: from_api(progress_results)) }
50
+
51
+ subject { get :index, organization_id: organization.uid }
52
+
53
+ it_behaves_like "jpi v1 protected action"
54
+
55
+ it "verifies the user's rights" do
56
+ expect(ability).to receive(:can?).with(:check_apps_sync, organization)
57
+ subject
58
+ end
59
+
60
+ it "returns the fetched connectors" do
61
+ subject
62
+ expect(JSON.parse(response.body)['connectors']).to eq(progress_results[:connectors])
63
+ end
64
+
65
+ context "when a connector is still syncing" do
66
+ before { subject }
67
+ it { expect(JSON.parse(response.body)['is_syncing']).to be_truthy }
68
+ end
69
+
70
+ context "when no connector is syncing" do
71
+ let(:progress_results) { { connectors: [
72
+ HashWithIndifferentAccess.new({name: 'a_name', status: 'FAILED', date: nil})
73
+ ] } }
74
+ before { subject }
75
+ it { expect(JSON.parse(response.body)['is_syncing']).to be_falsey }
76
+ end
77
+ end
78
+
79
+ describe "POST #create" do
80
+ xit "to spec: cannot stub 'post /app_instances_syncs data%5Bmode%5D=a_mode'"
81
+
82
+ # # Apps sync
83
+ # let(:sync_results) { [] }
84
+ # before { api_stub_for(post: "/app_instances_sync", response: from_api(sync_results)) }
85
+
86
+ # subject { post :create, organization_id: organization.uid, mode: 'a_mode', return_url: 'a/random/url' }
87
+
88
+ # it "verifies the user's rights" do
89
+ # expect(ability).to receive(:can?).with(:sync_apps, organization)
90
+ # subject
91
+ # end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,128 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe Jpi::V1::CurrentUsersController, type: :controller do
5
+ render_views
6
+ routes { MnoEnterprise::Engine.routes }
7
+ before { request.env["HTTP_ACCEPT"] = 'application/json' }
8
+
9
+ def json_for(res)
10
+ json_hash_for(res).to_json
11
+ end
12
+
13
+ def json_hash_for(res)
14
+ {'current_user' => hash_for(res)}
15
+ end
16
+
17
+ def hash_for(res)
18
+ hash = {
19
+ 'id' => res.id,
20
+ 'name' => res.name,
21
+ 'surname' => res.surname,
22
+ 'email' => res.email,
23
+ 'logged_in' => !!res.id,
24
+ 'created_at' => res.created_at ? res.created_at.iso8601 : nil,
25
+ 'company' => res.company,
26
+ 'phone' => res.phone,
27
+ 'phone_country_code' => res.phone_country_code,
28
+ 'country_code' => res.geo_country_code || 'US',
29
+ 'website' => res.website,
30
+ 'sso_session' => res.sso_session
31
+ }
32
+
33
+ if res.id
34
+ hash['admin_role'] = res.admin_role
35
+ hash['organizations'] = (res.organizations || []).map do |o|
36
+ {
37
+ 'id' => o.id,
38
+ 'uid' => o.uid,
39
+ 'name' => o.name,
40
+ 'currency' => 'AUD',
41
+ 'current_user_role' => o.role,
42
+ 'has_myob_essentials_only' => o.has_myob_essentials_only?
43
+ }
44
+ end
45
+
46
+ if res.deletion_request.present?
47
+ hash['deletion_request'] = {
48
+ 'id' => res.deletion_request.id,
49
+ 'token' => res.deletion_request.token
50
+ }
51
+ end
52
+ end
53
+
54
+ hash
55
+ end
56
+
57
+ # Stub user retrieval
58
+ let!(:user) { build(:user, :with_deletion_request, :with_organizations) }
59
+ before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
60
+
61
+ describe "GET #show" do
62
+ subject { get :show }
63
+
64
+ describe 'guest' do
65
+ it 'is successful' do
66
+ subject
67
+ expect(response).to be_success
68
+ end
69
+
70
+ it 'returns the right response' do
71
+ subject
72
+ expect(response.body).to eq(json_for(MnoEnterprise::User.new))
73
+ end
74
+ end
75
+
76
+ describe 'logged in' do
77
+ before { sign_in user }
78
+
79
+ it 'is successful' do
80
+ subject
81
+ expect(response).to be_success
82
+ end
83
+
84
+ it 'returns the right response' do
85
+ subject
86
+ expect(response.body).to eq(json_for(user))
87
+ end
88
+ end
89
+ end
90
+
91
+ describe 'PUT #update' do
92
+ let(:attrs) { {name: user.name + 'aaa'} }
93
+ before { api_stub_for(put: "/users/#{user.id}", response: -> { user.assign_attributes(attrs); from_api(user) }) }
94
+
95
+ subject { put :update, user: attrs }
96
+
97
+ describe 'guest' do
98
+ before { subject }
99
+ it { expect(response).to_not be_success }
100
+ end
101
+
102
+ describe 'logged in' do
103
+ before { sign_in user }
104
+ before { subject }
105
+ it { expect(user.name).to eq(attrs[:name]) }
106
+ end
107
+ end
108
+
109
+ describe 'PUT #update_password' do
110
+ let(:attrs) { {current_password: 'password', password: 'blablabla', password_confirmation: 'blablabla'} }
111
+ before { api_stub_for(put: "/users/#{user.id}", response: from_api(user)) }
112
+
113
+ subject { put :update_password, user: attrs }
114
+
115
+ describe 'guest' do
116
+ before { subject }
117
+ it { expect(response).to_not be_success }
118
+ end
119
+
120
+ describe 'logged in' do
121
+ before { sign_in user }
122
+ before { subject }
123
+ it { expect(response).to be_success }
124
+ it { expect(controller.current_user).to eq(user) } # check user is re-signed in
125
+ end
126
+ end
127
+ end
128
+ end