Module: MnoEnterprise::TestingSupport::OrganizationsSharedHelpers
- Defined in:
- lib/mno_enterprise/testing_support/organizations_shared_helpers.rb
Instance Method Summary collapse
- #admin_hash_for_organization(organization) ⇒ Object
- #admin_partial_hash_for_active_apps(organization) ⇒ Object
- #admin_partial_hash_for_invoices(organization) ⇒ Object
- #hash_for_organization(organization, user, admin = false) ⇒ Object
- #hash_for_organizations(organizations, admin = false) ⇒ Object
- #hash_for_reduced_organization(organization) ⇒ Object
- #partial_hash_for_billing(organization) ⇒ Object
- #partial_hash_for_credit_card(cc) ⇒ Object
- #partial_hash_for_current_user(organization, user) ⇒ Object
- #partial_hash_for_invoices(organization) ⇒ Object
- #partial_hash_for_members(organization, admin = false) ⇒ Object
- #partial_hash_for_organization(organization, admin = false) ⇒ Object
Instance Method Details
#admin_hash_for_organization(organization) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 136 def admin_hash_for_organization(organization) hash = {} hash['organization'] = partial_hash_for_organization(organization, true) hash['organization']['members'] = partial_hash_for_members(organization, true) hash['organization']['credit_card'] = {'presence' => false} hash['organization'].merge!(admin_partial_hash_for_invoices(organization)) hash['organization'].merge!(admin_partial_hash_for_active_apps(organization)) hash end |
#admin_partial_hash_for_active_apps(organization) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 159 def admin_partial_hash_for_active_apps(organization) hash = {'active_apps' => []} organization.app_instances.select { |app| app.status == "running" }.each do |active_apps| hash['active_apps'].push({ 'id' => active_apps.id, 'name' => active_apps.name, 'stack' => active_apps.stack, 'uid' => active_apps.uid, 'app_name' => active_apps.app.name, 'app_logo' => active_apps.app.logo }) end hash end |
#admin_partial_hash_for_invoices(organization) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 146 def admin_partial_hash_for_invoices(organization) hash = {'invoices' => []} organization.invoices.order("ended_at DESC").each do |invoice| hash['invoices'].push({ 'started_at' => invoice.started_at, 'ended_at' => invoice.ended_at, 'amount' => AccountingjsSerializer.serialize(invoice.total_due), 'paid' => invoice.paid? }) end hash end |
#hash_for_organization(organization, user, admin = false) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 113 def hash_for_organization(organization, user, admin = false) hash = { 'organization' => partial_hash_for_organization(organization), 'current_user' => partial_hash_for_current_user(organization, user) } hash['organization']['members'] = partial_hash_for_members(organization) if user.role(organization) == 'Super Admin' hash.merge!(partial_hash_for_billing(organization)) hash.merge!(partial_hash_for_invoices(organization)) if (cc = organization.credit_card) hash.merge!(partial_hash_for_credit_card(cc)) end if (situations = organization.arrears_situations) hash.merge!(partial_hash_for_arrears_situations(situations)) end end return hash end |
#hash_for_organizations(organizations, admin = false) ⇒ Object
101 102 103 104 105 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 101 def hash_for_organizations(organizations, admin = false) { 'organizations' => organizations.map { |o| partial_hash_for_organization(o, admin) } } end |
#hash_for_reduced_organization(organization) ⇒ Object
107 108 109 110 111 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 107 def hash_for_reduced_organization(organization) { 'organization' => partial_hash_for_organization(organization) } end |
#partial_hash_for_billing(organization) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 78 def partial_hash_for_billing(organization) { 'billing' => { 'current' => organization.current_billing, 'credit' => organization.current_credit } } end |
#partial_hash_for_credit_card(cc) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 3 def partial_hash_for_credit_card(cc) { 'credit_card' => { 'id' => cc.id, 'title' => cc.title, 'first_name' => cc.first_name, 'last_name' => cc.last_name, 'number' => cc.masked_number, 'month' => cc.month, 'year' => cc.year, 'country' => cc.country, 'verification_value' => 'CVV', 'billing_address' => cc.billing_address, 'billing_city' => cc.billing_city, 'billing_postcode' => cc.billing_postcode, 'billing_country' => cc.billing_country } } end |
#partial_hash_for_current_user(organization, user) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 68 def partial_hash_for_current_user(organization, user) { 'id' => user.id, 'name' => user.name, 'surname' => user.surname, 'email' => user.email, 'role' => user.role(organization) } end |
#partial_hash_for_invoices(organization) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 87 def partial_hash_for_invoices(organization) hash = {'invoices' => []} organization.invoices.order("ended_at DESC").each do |invoice| hash['invoices'].push({ 'period' => invoice.period_label, 'amount' => invoice.total_due, 'paid' => invoice.paid?, 'link' => mnoe_enterprise.invoice_path(invoice.slug), }) end return hash end |
#partial_hash_for_members(organization, admin = false) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 23 def partial_hash_for_members(organization, admin = false) list = [] organization.users.each do |user| u = { 'id' => user.id, 'entity' => 'User', 'name' => user.name, 'surname' => user.surname, 'email' => user.email, 'role' => user.role(organization) } u['uid'] = user.uid if admin list.push(u) end organization.org_invites.each do |invite| list.push({ 'id' => invite.id, 'entity' => 'OrgInvite', 'email' => invite.user_email, 'role' => invite.user_role }) end return list end |
#partial_hash_for_organization(organization, admin = false) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mno_enterprise/testing_support/organizations_shared_helpers.rb', line 51 def partial_hash_for_organization(organization, admin = false) ret = { 'id' => organization.id, 'name' => organization.name, 'soa_enabled' => organization.soa_enabled, 'account_frozen' => organization.account_frozen, 'payment_restriction' => organization.payment_restriction, 'financial_year_end_month' => organization.financial_year_end_month } if admin ret['uid'] = organization.uid end ret end |