Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 🥒 Clean up some buyer steps #3852

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Prev Previous commit
🚧
  • Loading branch information
josemigallas committed Aug 5, 2024
commit 410d19ab2ce4560bdd136ae6b5bc4e4946ddc315
107 changes: 48 additions & 59 deletions test/factories/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@

factory(:account, :parent => :account_without_users) do
after(:create) do |account|
if account.users.empty?
username = account.org_name.gsub(/[^a-zA-Z0-9_\.]+/, '_')

admin = FactoryBot.create(:admin, :username => username, :account_id => account.id)
admin.activate!
end
FactoryBot.create(:active_admin, account: account) if account.users.empty?
end

after(:stub) do |account|
Expand All @@ -55,6 +50,52 @@
factory :buyer do
buyer { true }
end

factory :master_account, traits: [:approved] do
master { true }
org_name { 'Master account' }
payment_gateway_type { :bogus }
association :settings
billing_strategy factory: :postpaid_with_charging

after(:build) do |account|
if account.users.empty?
account.users << FactoryBot.build(:active_admin, account_id: account.id, username: "superadmin")
else
account.admins.each { |user| user.activate! if user.can_activate? }
end
end

after(:create) do |account|
account.provider_account = account

if account.users.empty?
account.users << FactoryBot.create(:active_admin, account_id: account.id, username: "superadmin")
else
account.admins.each { |user| user.activate! if user.can_activate? }
end

service = FactoryBot.create(:service, account: account)

# Defaults
app_plan = FactoryBot.create(:published_application_plan, issuer: service, default: true)
account_plan = FactoryBot.create(:account_plan, :published, issuer: account, default: true)
account.update_attribute :default_account_plan, account_plan

service.update_attribute(:default_service_plan, service.service_plans.first) # rubocop:disable Rails/SkipsModelValidations

%w[prepaid_billing postpaid_billing anonymous_clients liquid].each do |feature|
service.features.create!(system_name: feature, name: feature.humanize)
end

FactoryBot.create(:cinstance, plan: app_plan, user_account: account)
end

after(:stub) do |account|
Account.stubs(:master).returns(account)
Account.stubs(:find_by_domain).with(account.internal_domain).returns(account)
end
end
end

factory(:pending_buyer_account, traits: [:pending], parent: :buyer) do
Expand Down Expand Up @@ -132,7 +173,7 @@
# assign tenant id manualy, because we cannot do it by trigger
account.tenant_id = account.id

account.approve!
account.approve! if account.pending?

account.services.first.update_attribute :mandatory_app_key, false
account.settings.update!(
Expand Down Expand Up @@ -193,56 +234,4 @@
a.save
end
end

factory(:master_account, :parent => :account) do
master { true }
org_name { 'Master account' }
payment_gateway_type { :bogus }
association :settings

after(:build) do |account|
account.billing_strategy = FactoryBot.build(:postpaid_with_charging)
if account.users.empty?
account.users << FactoryBot.build(:admin, :account_id => account.id, :username => "superadmin", state: 'active')
end
account.admins.each { |user| user.activate! if user.can_activate? }
end

after(:create) do |account|
account.provider_account = account

if account.users.empty?
account.users << FactoryBot.create(:admin, :account_id => account.id, :username => "superadmin", state: 'active')
end
account.admins.each { |user| user.activate! if user.can_activate? }
account.approve! if account.can_approve?

#[multiservice] First service is the default
service = FactoryBot.create(:service, :account => account)

# Defaults
application_plan = FactoryBot.create(:application_plan, issuer: service, state: 'published')
account_plan = FactoryBot.create(:account_plan, issuer: account, state: 'published')

service.update_attribute :default_application_plan, application_plan
service.update_attribute :default_service_plan, service.service_plans.first
account.update_attribute :default_account_plan, account_plan

# TODO: add more master features here, if needed
%w[prepaid_billing postpaid_billing anonymous_clients liquid].each do |feature|
account.default_service.features.create!(:system_name => feature, :name => feature.humanize)
end

FactoryBot.create(:cinstance, :plan => account.default_service.application_plans.published.first,
:user_account => account)

account.reload
end


after(:stub) do |account|
Account.stubs(:master).returns(account)
Account.stubs(:find_by_domain).with(account.internal_domain).returns(account)
end
end
end
4 changes: 4 additions & 0 deletions test/factories/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
after(:build) do |plan, evaluator|
plan.issuer.update(default_account_plan: plan) if evaluator.default
end

trait :published do
state { :published }
end
end

factory(:service_plan, parent: :plan, class: ServicePlan) do
Expand Down
1 change: 1 addition & 0 deletions test/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

factory(:admin, :parent => :user) do
role { :admin }
username { account.org_name.gsub(/[^a-zA-Z0-9_\.]+/, '_') }
end

factory(:active_admin, :parent => :admin) do
Expand Down