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

Remove extra logging and fix order of events #859

Merged
merged 2 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# frozen_string_literal: true

module WasteCarriersEngine
class UnpaidBalanceError < StandardError; end
class PendingConvictionsError < StandardError; end

class RegistrationActivationService < BaseService
def run(registration:)
@registration = registration

return unless can_be_completed?

registration.with_lock do
activate_registration if can_be_completed?
activate_registration
end

send_confirmation_email
Expand All @@ -23,19 +22,19 @@ def activate_registration
end

def can_be_completed?
balance_is_paid? && no_pending_conviction_check?
balance_is_paid? && no_pending_conviction_check? && correct_status?
end

def balance_is_paid?
raise UnpaidBalanceError if @registration.unpaid_balance?
!@registration.unpaid_balance?
end

true
def correct_status?
@registration.pending?
end

def no_pending_conviction_check?
raise PendingConvictionsError if @registration.pending_manual_conviction_check?

true
!@registration.pending_manual_conviction_check?
end

def send_confirmation_email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ module WasteCarriersEngine
context "when the balance is unpaid" do
before { allow(registration).to receive(:unpaid_balance?).and_return(true) }

it "raises an error" do
expect { service }.to raise_error(UnpaidBalanceError)
it "does not activates the registration" do
expect { service }.to_not change { registration.active? }
end
end

context "when the registration has a pending convictions check" do
before { allow(registration).to receive(:pending_manual_conviction_check?).and_return(true) }

it "raises an error" do
expect { service }.to raise_error(PendingConvictionsError)
it "does not activates the registration" do
expect { service }.to_not change { registration.active? }
end
end

Expand Down