Skip to content

Commit

Permalink
Refactoring mail preview fake contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
guicassolato committed Mar 19, 2019
1 parent ccfd6a4 commit 2d83ee7
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions app/mailers/mail_preview.rb
@@ -1,5 +1,5 @@
class MailPreview < MailView
FakeContract = Struct.new(:old_plan, :plan, :provider_account, :service, :account, :name)
FakeContract = Struct.new(:id, :old_plan, :plan, :provider_account, :service, :account, :name)

def application_created
event = Applications::ApplicationCreatedEvent.create(Cinstance.last, User.last)
Expand All @@ -21,7 +21,7 @@ def cinstance_expired_trial

def service_contract_plan_changed
plans = ServicePlan.last(2)
contract = FakeContract.new(plans.first, plans.second, Account.providers.last, Service.last, Account.last, '1')
contract = build_fake_contract(*plans)
event = ServiceContracts::ServiceContractPlanChangedEvent.create(
contract, User.last
)
Expand Down Expand Up @@ -110,11 +110,7 @@ def account_deleted
end

def cinstance_plan_changed
plans = ServicePlan.last(2)
cinstance = FakeContract.new(plans.first, plans.second, Account.providers.last, Service.last, Account.last, '1')
event = Cinstances::CinstancePlanChangedEvent.create(cinstance, User.last)

NotificationMailer.cinstance_plan_changed(event, receiver)
NotificationMailer.cinstance_plan_changed(cinstance_plan_changed_event, receiver)
end

def message_received
Expand Down Expand Up @@ -158,4 +154,15 @@ def daily_report
def receiver
@_receiver ||= User.last
end

def build_fake_contract(old_plan, new_plan)
FakeContract.new(1, old_plan, new_plan, Account.providers.last, Service.last, Account.last, '1')
end

def cinstance_plan_changed_event
plans = ApplicationPlan.last(2)
cinstance = build_fake_contract(*plans)

Cinstances::CinstancePlanChangedEvent.create(cinstance, User.last)
end
end

0 comments on commit 2d83ee7

Please sign in to comment.