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

Move setting up of ASSISTED_DIGITAL flag in AASM machine #533

Merged
merged 2 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,23 @@ module CanChangeWorkflowStatus
transitions from: :worldpay_form,
to: :renewal_received_form,
if: :pending_worldpay_payment_or_convictions_check?,
success: :send_renewal_received_email
success: :send_renewal_received_email,
# TODO: This don't get triggered if in the `success`
# callback block, hence we went for `after`
after: :set_metadata_route

transitions from: :worldpay_form,
to: :renewal_complete_form
to: :renewal_complete_form,
# TODO: This don't get triggered if in the `success`
# callback block, hence we went for `after`
after: :set_metadata_route

transitions from: :bank_transfer_form,
to: :renewal_received_form,
success: :send_renewal_received_email
success: :send_renewal_received_email,
# TODO: This don't get triggered if in the `success`
# callback block, hence we went for `after`
after: :set_metadata_route
end

event :back do
Expand Down
6 changes: 6 additions & 0 deletions app/models/waste_carriers_engine/transient_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ def stuck?
true
end

def set_metadata_route
metaData.route = Rails.configuration.metadata_route

save
end

private

def copy_data_from_registration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def update_registration
end

def update_meta_data
@registration.metaData.route = Rails.configuration.metadata_route
@registration.metaData.route = @transient_registration.metaData.route
@registration.metaData.renew
@registration.metaData.date_registered = Time.now
@registration.metaData.date_activated = @registration.metaData.date_registered
Expand Down
41 changes: 41 additions & 0 deletions spec/models/waste_carriers_engine/transient_registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,47 @@ module WasteCarriersEngine
expect(transient_registration).to have_state(:renewal_start_form)
end
end

context "when transitioning from bank_transfer_form to renewal_received_form succesfully" do
it "set the transient registration metadata route" do
expect(transient_registration).to receive(:set_metadata_route).once

transient_registration.update_attributes(workflow_state: :bank_transfer_form)
transient_registration.next
end
end

context "when transitioning from worldpay_form to renewal_complete_form succesfully" do
it "set the transient registration metadata route" do
expect(transient_registration).to receive(:set_metadata_route).once
expect(transient_registration).to receive(:pending_worldpay_payment_or_convictions_check?).and_return(false)

transient_registration.update_attributes(workflow_state: :worldpay_form)
transient_registration.next
end
end

context "when transitioning from worldpay_form to renewal_received_form succesfully" do
it "set the transient registration metadata route" do
expect(transient_registration).to receive(:set_metadata_route).once
expect(transient_registration).to receive(:pending_worldpay_payment_or_convictions_check?).and_return(true)

transient_registration.update_attributes(workflow_state: :worldpay_form)
transient_registration.next
end
end
end

describe "#set_metadata_route" do
it "updates the transient registration's metadata route" do
metadata_route = double(:metadata_route)

expect(Rails.configuration).to receive(:metadata_route).and_return(metadata_route)
expect(transient_registration.metaData).to receive(:route=).with(metadata_route)
expect(transient_registration).to receive(:save)

transient_registration.set_metadata_route
end
end

describe "reg_identifier" do
Expand Down
39 changes: 39 additions & 0 deletions spec/requests/waste_carriers_engine/bank_transfer_forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,45 @@ module WasteCarriersEngine

include_examples "POST without params form", "bank_transfer_form"

describe "POST new_bank_transfer_form" do
context "when a valid user is signed in" do
let(:user) { create(:user) }

before(:each) do
sign_in(user)
end

context "when a renewal is in progress" do
let(:transient_registration) do
create(:transient_registration,
:has_required_data,
:has_addresses,
:has_key_people,
:has_unpaid_balance,
account_email: user.email)
end

context "when the workflow_state matches the requested form" do
before do
transient_registration.update_attributes(workflow_state: :bank_transfer_form)
end

context "when the request is successful" do
it "updates the transient registration metadata attributes from application configuration" do
allow(Rails.configuration).to receive(:metadata_route).and_return("ASSISTED_DIGITAL")

expect(transient_registration.reload.metaData.route).to be_nil

post_form_with_params(:bank_transfer_form, reg_identifier: transient_registration.reg_identifier)

expect(transient_registration.reload.metaData.route).to eq("ASSISTED_DIGITAL")
end
end
end
end
end
end

describe "GET back_bank_transfer_forms_path" do
context "when a valid user is signed in" do
let(:user) { create(:user) }
Expand Down
20 changes: 20 additions & 0 deletions spec/requests/waste_carriers_engine/worldpay_forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ module WasteCarriersEngine
expect(response).to redirect_to(new_renewal_complete_form_path(reg_id))
end

it "updates the transient registration metadata attributes from application configuration" do
allow(Rails.configuration).to receive(:metadata_route).and_return("ASSISTED_DIGITAL")

expect(transient_registration.reload.metaData.route).to be_nil

get success_worldpay_forms_path(reg_id), params

expect(transient_registration.reload.metaData.route).to eq("ASSISTED_DIGITAL")
end

context "when it has been flagged for conviction checks" do
before do
transient_registration.conviction_sign_offs = [build(:conviction_sign_off)]
Expand All @@ -86,6 +96,16 @@ module WasteCarriersEngine
expect(response).to redirect_to(new_renewal_received_form_path(reg_id))
end

it "updates the transient registration metadata attributes from application configuration" do
allow(Rails.configuration).to receive(:metadata_route).and_return("ASSISTED_DIGITAL")

expect(transient_registration.reload.metaData.route).to be_nil

get success_worldpay_forms_path(reg_id), params

expect(transient_registration.reload.metaData.route).to eq("ASSISTED_DIGITAL")
end

context "when the mailer fails" do
before do
allow(Rails.configuration.action_mailer).to receive(:raise_delivery_errors).and_return(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ module WasteCarriersEngine
expect(registration.reload.finance_details.payments).to include(new_payment)
end

it "copies the registration's route from the transient_registration to the registration" do
transient_registration.metaData.route = "ASSISTED_DIGITAL_FROM_TRANSIENT_REGISTRATION"

renewal_completion_service.complete_renewal

expect(registration.reload.metaData.route).to eq("ASSISTED_DIGITAL_FROM_TRANSIENT_REGISTRATION")
end

it "keeps existing orders" do
old_order = registration.finance_details.orders.first
renewal_completion_service.complete_renewal
Expand Down Expand Up @@ -147,17 +155,6 @@ module WasteCarriersEngine
expect(registration.reload.contact_address.last_name).to eq(last_name)
end

context "when the metadata_route is set" do
before do
allow(Rails.configuration).to receive(:metadata_route).and_return("ASSISTED_DIGITAL")
end

it "updates the registration's route to the correct value" do
renewal_completion_service.complete_renewal
expect(registration.reload.metaData.route).to eq("ASSISTED_DIGITAL")
end
end

it "deletes the transient registration" do
renewal_completion_service.complete_renewal
expect(TransientRegistration.where(reg_identifier: transient_registration.reg_identifier).count).to eq(0)
Expand Down