mno-enterprise-api 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -0
- data/Rakefile +12 -0
- data/app/assets/javascripts/mno_enterprise/angular/loading-page.app.js.coffee +156 -0
- data/app/assets/javascripts/mno_enterprise/application.js +13 -0
- data/app/controllers/devise/password_expired_controller.rb +55 -0
- data/app/controllers/mno_enterprise/auth/confirmations_controller.rb +5 -0
- data/app/controllers/mno_enterprise/auth/omniauth_callbacks_controller.rb +30 -0
- data/app/controllers/mno_enterprise/auth/passwords_controller.rb +5 -0
- data/app/controllers/mno_enterprise/auth/registrations_controller.rb +5 -0
- data/app/controllers/mno_enterprise/auth/sessions_controller.rb +7 -0
- data/app/controllers/mno_enterprise/auth/unlocks_controller.rb +5 -0
- data/app/controllers/mno_enterprise/deletion_requests_controller.rb +5 -0
- data/app/controllers/mno_enterprise/impersonate_controller.rb +48 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/audit_events_controller.rb +16 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/base_resource_controller.rb +5 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/cloud_apps_controller.rb +46 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb +47 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +27 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/tenant_invoices_controller.rb +14 -0
- data/app/controllers/mno_enterprise/jpi/v1/admin/users_controller.rb +63 -0
- data/app/controllers/mno_enterprise/jpi/v1/app_instances_controller.rb +24 -0
- data/app/controllers/mno_enterprise/jpi/v1/app_instances_sync_controller.rb +36 -0
- data/app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb +32 -0
- data/app/controllers/mno_enterprise/jpi/v1/current_users_controller.rb +5 -0
- data/app/controllers/mno_enterprise/jpi/v1/deletion_requests_controller.rb +5 -0
- data/app/controllers/mno_enterprise/jpi/v1/impac/dashboards_controller.rb +5 -0
- data/app/controllers/mno_enterprise/jpi/v1/impac/kpis_controller.rb +80 -0
- data/app/controllers/mno_enterprise/jpi/v1/impac/widgets_controller.rb +63 -0
- data/app/controllers/mno_enterprise/jpi/v1/industry_bundle_controller.rb +25 -0
- data/app/controllers/mno_enterprise/jpi/v1/marketplace_controller.rb +22 -0
- data/app/controllers/mno_enterprise/jpi/v1/organizations_controller.rb +5 -0
- data/app/controllers/mno_enterprise/jpi/v1/shopping_cart_controller.rb +93 -0
- data/app/controllers/mno_enterprise/jpi/v1/teams_controller.rb +88 -0
- data/app/controllers/mno_enterprise/org_invites_controller.rb +5 -0
- data/app/controllers/mno_enterprise/pages_controller.rb +5 -0
- data/app/controllers/mno_enterprise/provision_controller.rb +5 -0
- data/app/controllers/mno_enterprise/status_controller.rb +27 -0
- data/app/controllers/mno_enterprise/webhook/o_auth_controller.rb +5 -0
- data/app/mailers/mno_enterprise/system_notification_mailer.rb +5 -0
- data/app/models/mno_enterprise/health_check.rb +16 -0
- data/app/views/devise/password_expired/show.html.haml +32 -0
- data/app/views/mno_enterprise/auth/confirmations/default/_form.html.haml +49 -0
- data/app/views/mno_enterprise/auth/confirmations/default/_lounge.html.haml +34 -0
- data/app/views/mno_enterprise/auth/confirmations/default/_show.html.haml +10 -0
- data/app/views/mno_enterprise/auth/confirmations/lounge.html.haml +4 -0
- data/app/views/mno_enterprise/auth/confirmations/material/_form.html.haml +44 -0
- data/app/views/mno_enterprise/auth/confirmations/material/_lounge.html.haml +18 -0
- data/app/views/mno_enterprise/auth/confirmations/material/_show.html.haml +21 -0
- data/app/views/mno_enterprise/auth/confirmations/new.html.haml +31 -0
- data/app/views/mno_enterprise/auth/confirmations/show.html.haml +4 -0
- data/app/views/mno_enterprise/auth/mailer/confirmation_instructions.html.haml +4 -0
- data/app/views/mno_enterprise/auth/mailer/reset_password_instructions.html.haml +6 -0
- data/app/views/mno_enterprise/auth/mailer/unlock_instructions.html.haml +5 -0
- data/app/views/mno_enterprise/auth/passwords/edit.html.haml +53 -0
- data/app/views/mno_enterprise/auth/passwords/new.html.haml +34 -0
- data/app/views/mno_enterprise/auth/registrations/default/_form.html.haml +35 -0
- data/app/views/mno_enterprise/auth/registrations/default/_new.html.haml +11 -0
- data/app/views/mno_enterprise/auth/registrations/material/_form.html.haml +30 -0
- data/app/views/mno_enterprise/auth/registrations/material/_new.html.haml +10 -0
- data/app/views/mno_enterprise/auth/registrations/new.html.haml +4 -0
- data/app/views/mno_enterprise/auth/sessions/default/_form.html.haml +17 -0
- data/app/views/mno_enterprise/auth/sessions/default/_new.html.haml +11 -0
- data/app/views/mno_enterprise/auth/sessions/material/_form.html.haml +26 -0
- data/app/views/mno_enterprise/auth/sessions/material/_new.html.haml +11 -0
- data/app/views/mno_enterprise/auth/sessions/new.html.haml +4 -0
- data/app/views/mno_enterprise/auth/shared/_links.html.haml +24 -0
- data/app/views/mno_enterprise/auth/unlocks/new.html.haml +10 -0
- data/app/views/mno_enterprise/deletion_requests/show.html.haml +131 -0
- data/app/views/mno_enterprise/jpi/v1/admin/audit_events/_audit_event.json.jbuilder +5 -0
- data/app/views/mno_enterprise/jpi/v1/admin/audit_events/index.json.jbuilder +4 -0
- data/app/views/mno_enterprise/jpi/v1/admin/cloud_apps/_cloud_app.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/cloud_apps/index.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/cloud_apps/show.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/invoices/_invoice.json.jbuilder +2 -0
- data/app/views/mno_enterprise/jpi/v1/admin/invoices/index.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/invoices/show.json.jbuilder +2 -0
- data/app/views/mno_enterprise/jpi/v1/admin/organizations/_credit_card.json.jbuilder +7 -0
- data/app/views/mno_enterprise/jpi/v1/admin/organizations/_invoices.json.jbuilder +8 -0
- data/app/views/mno_enterprise/jpi/v1/admin/organizations/_member.json.jbuilder +14 -0
- data/app/views/mno_enterprise/jpi/v1/admin/organizations/_organization.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/organizations/in_arrears.json.jbuilder +8 -0
- data/app/views/mno_enterprise/jpi/v1/admin/organizations/index.json.jbuilder +7 -0
- data/app/views/mno_enterprise/jpi/v1/admin/organizations/show.json.jbuilder +11 -0
- data/app/views/mno_enterprise/jpi/v1/admin/tenant_invoices/_tenant_invoice.json.jbuilder +5 -0
- data/app/views/mno_enterprise/jpi/v1/admin/tenant_invoices/index.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/tenant_invoices/show.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/users/_user.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/admin/users/index.json.jbuilder +2 -0
- data/app/views/mno_enterprise/jpi/v1/admin/users/show.json.jbuilder +9 -0
- data/app/views/mno_enterprise/jpi/v1/app_instances/_resource.json.jbuilder +23 -0
- data/app/views/mno_enterprise/jpi/v1/app_instances/index.json.jbuilder +9 -0
- data/app/views/mno_enterprise/jpi/v1/app_instances/show.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/billing/index.json.jbuilder +0 -0
- data/app/views/mno_enterprise/jpi/v1/current_users/show.json.jbuilder +37 -0
- data/app/views/mno_enterprise/jpi/v1/impac/dashboards/_dashboard.json.jbuilder +9 -0
- data/app/views/mno_enterprise/jpi/v1/impac/dashboards/index.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/impac/dashboards/show.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/impac/kpis/_kpi.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/impac/kpis/show.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/impac/widgets/_widget.json.jbuilder +6 -0
- data/app/views/mno_enterprise/jpi/v1/impac/widgets/show.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/marketplace/_app.json.jbuilder +14 -0
- data/app/views/mno_enterprise/jpi/v1/marketplace/index.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/marketplace/show.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/_arrears.json.jbuilder +11 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/_billing.json.jbuilder +4 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/_credit_card.json.jbuilder +7 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/_current_user.json.jbuilder +5 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/_invoices.json.jbuilder +8 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/_member.json.jbuilder +13 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/_organization.json.jbuilder +13 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/credit_card.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/index.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/members.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/show.json.jbuilder +15 -0
- data/app/views/mno_enterprise/jpi/v1/organizations/show_reduced.json.jbuilder +3 -0
- data/app/views/mno_enterprise/jpi/v1/shopping_cart/organizations.json.jbuilder +5 -0
- data/app/views/mno_enterprise/jpi/v1/shopping_cart/show.json.jbuilder +59 -0
- data/app/views/mno_enterprise/jpi/v1/shopping_cart/show_item.json.jbuilder +34 -0
- data/app/views/mno_enterprise/jpi/v1/teams/_team.json.jbuilder +20 -0
- data/app/views/mno_enterprise/jpi/v1/teams/index.json.jbuilder +1 -0
- data/app/views/mno_enterprise/jpi/v1/teams/show.json.jbuilder +3 -0
- data/app/views/mno_enterprise/pages/app_access_unauthorized.html.haml +19 -0
- data/app/views/mno_enterprise/pages/app_logout.html.haml +18 -0
- data/app/views/mno_enterprise/pages/billing_details_required.html.haml +19 -0
- data/app/views/mno_enterprise/pages/loading.html.erb +69 -0
- data/app/views/mno_enterprise/provision/_provision_apps.html.haml +42 -0
- data/app/views/mno_enterprise/provision/_select_organization.html.haml +17 -0
- data/app/views/mno_enterprise/provision/new.html.haml +4 -0
- data/app/views/mno_enterprise/webhook/o_auth/authorize.html.haml +26 -0
- data/app/views/mno_enterprise/webhook/o_auth/providers/myob.html.haml +29 -0
- data/app/views/mno_enterprise/webhook/o_auth/providers/xero.html.haml +34 -0
- data/config/initializers/devise.rb +273 -0
- data/config/initializers/devise_extension.rb +9 -0
- data/config/initializers/devise_log.rb +12 -0
- data/config/initializers/health_check.rb +35 -0
- data/config/initializers/main_app_version.rb +6 -0
- data/config/routes.rb +152 -0
- data/lib/mno-enterprise-api.rb +1 -0
- data/lib/mno_enterprise/api.rb +14 -0
- data/lib/mno_enterprise/api/engine.rb +9 -0
- data/lib/mno_enterprise/concerns/controllers/deletion_requests_controller.rb +108 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/admin/base_resource_controller.rb +34 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/current_users_controller.rb +58 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/deletion_requests_controller.rb +69 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb +76 -0
- data/lib/mno_enterprise/concerns/controllers/jpi/v1/organizations_controller.rb +180 -0
- data/lib/mno_enterprise/concerns/controllers/org_invites_controller.rb +44 -0
- data/lib/mno_enterprise/concerns/controllers/pages_controller.rb +78 -0
- data/lib/mno_enterprise/concerns/controllers/provision_controller.rb +71 -0
- data/lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb +107 -0
- data/lib/mno_enterprise/concerns/mailers/system_notification_mailer.rb +158 -0
- data/lib/mno_enterprise/event_logger.rb +32 -0
- data/spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb +68 -0
- data/spec/controllers/mno_enterprise/deletion_requests_controller_spec.rb +141 -0
- data/spec/controllers/mno_enterprise/impersonate_controller_spec.rb +48 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/audit_events_controller_spec.rb +51 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/cloud_apps_controller_spec.rb +92 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb +159 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb +116 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/tenant_invoices_controller_spec.rb +92 -0
- data/spec/controllers/mno_enterprise/jpi/v1/admin/users_controller_spec.rb +136 -0
- data/spec/controllers/mno_enterprise/jpi/v1/app_instances_controller_spec.rb +76 -0
- data/spec/controllers/mno_enterprise/jpi/v1/app_instances_sync_controller_spec.rb +94 -0
- data/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb +128 -0
- data/spec/controllers/mno_enterprise/jpi/v1/deletion_requests_controller_spec.rb +72 -0
- data/spec/controllers/mno_enterprise/jpi/v1/impac/kpis_controller_spec.rb +80 -0
- data/spec/controllers/mno_enterprise/jpi/v1/marketplace_controller_spec.rb +115 -0
- data/spec/controllers/mno_enterprise/jpi/v1/organizations_controller_spec.rb +516 -0
- data/spec/controllers/mno_enterprise/jpi/v1/team_controller_spec.rb +86 -0
- data/spec/controllers/mno_enterprise/org_invites_controller_spec.rb +29 -0
- data/spec/controllers/mno_enterprise/pages_controller_spec.rb +49 -0
- data/spec/controllers/mno_enterprise/provision_controller_spec.rb +94 -0
- data/spec/controllers/mno_enterprise/status_controller_spec.rb +34 -0
- data/spec/controllers/mno_enterprise/webhook/o_auth_controller_spec.rb +104 -0
- data/spec/lib/mno_enterprise/event_logger_spec.rb +28 -0
- data/spec/mailer/mno_enterprise/system_notification_mailer_spec.rb +132 -0
- data/spec/rails_helper.rb +94 -0
- data/spec/requests/devise/authentication_spec.rb +43 -0
- data/spec/requests/devise/registration_spec.rb +64 -0
- data/spec/routing/devise/confirmation_routing_spec.rb +20 -0
- data/spec/routing/devise/passwords_routing_spec.rb +24 -0
- data/spec/routing/devise/registrations_routing_spec.rb +16 -0
- data/spec/routing/devise/sessions_routing_spec.rb +20 -0
- data/spec/routing/mno_enterprise/deletion_requests_controller_routing_spec.rb +20 -0
- data/spec/routing/mno_enterprise/impersonate_controller_routing.spec.rb +15 -0
- data/spec/routing/mno_enterprise/jpi/v1/admin/audit_events_controller_routing_spec.rb +11 -0
- data/spec/routing/mno_enterprise/jpi/v1/admin/cloud_apps_controller_routing_spec.rb +24 -0
- data/spec/routing/mno_enterprise/jpi/v1/admin/invoices_controller_routing_spec.rb +37 -0
- data/spec/routing/mno_enterprise/jpi/v1/admin/organizations_controller_routing_spec.rb +20 -0
- data/spec/routing/mno_enterprise/jpi/v1/admin/tenant_invoices_controller_routing_spec.rb +16 -0
- data/spec/routing/mno_enterprise/jpi/v1/admin/users_controller_routing_spec.rb +24 -0
- data/spec/routing/mno_enterprise/jpi/v1/app_instances_controller_routing_spec.rb +12 -0
- data/spec/routing/mno_enterprise/jpi/v1/app_instances_sync_controller_routing_spec.rb +15 -0
- data/spec/routing/mno_enterprise/jpi/v1/current_users_controller_routing_spec.rb +28 -0
- data/spec/routing/mno_enterprise/jpi/v1/deletion_requests_controller_routing_spec.rb +24 -0
- data/spec/routing/mno_enterprise/jpi/v1/impac/kpis_controller_routing_spec.rb +22 -0
- data/spec/routing/mno_enterprise/jpi/v1/marketplace_controller_routing_spec.rb +16 -0
- data/spec/routing/mno_enterprise/jpi/v1/organizations_controller_routing_spec.rb +44 -0
- data/spec/routing/mno_enterprise/jpi/v1/teams_controller_routing_spec.rb +36 -0
- data/spec/routing/mno_enterprise/org_invites_controller_routing_spec.rb +12 -0
- data/spec/routing/mno_enterprise/pages_controller_routing_spec.rb +29 -0
- data/spec/routing/mno_enterprise/provision_controller_routing_spec.rb +15 -0
- data/spec/routing/mno_enterprise/status_controller_routing_spec.rb +19 -0
- data/spec/routing/mno_enterprise/webhook/o_auth_controller_routing_spec.rb +27 -0
- data/spec/spec_helper.rb +88 -0
- 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
|