diff --git a/app/services/flow/flows/provider_dwp_override.rb b/app/services/flow/flows/provider_dwp_override.rb index b668bb428a..dbf6f87478 100644 --- a/app/services/flow/flows/provider_dwp_override.rb +++ b/app/services/flow/flows/provider_dwp_override.rb @@ -2,46 +2,10 @@ module Flow module Flows class ProviderDWPOverride < FlowSteps STEPS = { - confirm_dwp_non_passported_applications: { - path: ->(application) { urls.providers_legal_aid_application_confirm_dwp_non_passported_applications_path(application) }, - forward: lambda do |application, confirm_dwp_non_passported| - if confirm_dwp_non_passported - application.change_state_machine_type("NonPassportedStateMachine") - :about_financial_means - else - application.change_state_machine_type("PassportedStateMachine") - :check_client_details - end - end, - }, - check_client_details: { - path: ->(application) { urls.providers_legal_aid_application_check_client_details_path(application) }, - forward: :received_benefit_confirmations, - }, - received_benefit_confirmations: { - path: ->(application) { urls.providers_legal_aid_application_received_benefit_confirmation_path(application) }, - forward: lambda do |application, has_benefit| - if has_benefit - application.change_state_machine_type("PassportedStateMachine") - :has_evidence_of_benefits - else - application.change_state_machine_type("NonPassportedStateMachine") - :about_financial_means - end - end, - }, - has_evidence_of_benefits: { - path: ->(application) { urls.providers_legal_aid_application_has_evidence_of_benefit_path(application) }, - forward: lambda do |application, has_evidence_of_benefit| - if has_evidence_of_benefit - application.change_state_machine_type("PassportedStateMachine") - application.used_delegated_functions? ? :substantive_applications : :capital_introductions - else - application.change_state_machine_type("NonPassportedStateMachine") - :about_financial_means - end - end, - }, + confirm_dwp_non_passported_applications: Steps::ProviderDWPOverride::ConfirmDWPNonPassportedApplicationsStep, + check_client_details: Steps::ProviderDWPOverride::CheckClientDetailsStep, + received_benefit_confirmations: Steps::ProviderDWPOverride::ReceivedBenefitConfirmationsStep, + has_evidence_of_benefits: Steps::ProviderDWPOverride::HasEvidenceOfBenefitsStep, }.freeze end end diff --git a/app/services/flow/steps/provider_dwp_override/check_client_details_step.rb b/app/services/flow/steps/provider_dwp_override/check_client_details_step.rb new file mode 100644 index 0000000000..09c65b525e --- /dev/null +++ b/app/services/flow/steps/provider_dwp_override/check_client_details_step.rb @@ -0,0 +1,10 @@ +module Flow + module Steps + module ProviderDWPOverride + CheckClientDetailsStep = Step.new( + path: ->(application) { Flow::Steps.urls.providers_legal_aid_application_check_client_details_path(application) }, + forward: :received_benefit_confirmations, + ) + end + end +end diff --git a/app/services/flow/steps/provider_dwp_override/confirm_dwp_non_passported_applications_step.rb b/app/services/flow/steps/provider_dwp_override/confirm_dwp_non_passported_applications_step.rb new file mode 100644 index 0000000000..cd81e49839 --- /dev/null +++ b/app/services/flow/steps/provider_dwp_override/confirm_dwp_non_passported_applications_step.rb @@ -0,0 +1,18 @@ +module Flow + module Steps + module ProviderDWPOverride + ConfirmDWPNonPassportedApplicationsStep = Step.new( + path: ->(application) { Flow::Steps.urls.providers_legal_aid_application_confirm_dwp_non_passported_applications_path(application) }, + forward: lambda do |application, confirm_dwp_non_passported| + if confirm_dwp_non_passported + application.change_state_machine_type("NonPassportedStateMachine") + :about_financial_means + else + application.change_state_machine_type("PassportedStateMachine") + :check_client_details + end + end, + ) + end + end +end diff --git a/app/services/flow/steps/provider_dwp_override/has_evidence_of_benefits_step.rb b/app/services/flow/steps/provider_dwp_override/has_evidence_of_benefits_step.rb new file mode 100644 index 0000000000..cf9a00ab12 --- /dev/null +++ b/app/services/flow/steps/provider_dwp_override/has_evidence_of_benefits_step.rb @@ -0,0 +1,18 @@ +module Flow + module Steps + module ProviderDWPOverride + HasEvidenceOfBenefitsStep = Step.new( + path: ->(application) { Flow::Steps.urls.providers_legal_aid_application_has_evidence_of_benefit_path(application) }, + forward: lambda do |application, has_evidence_of_benefits| + if has_evidence_of_benefits + application.change_state_machine_type("PassportedStateMachine") + application.used_delegated_functions? ? :substantive_applications : :capital_introductions + else + application.change_state_machine_type("NonPassportedStateMachine") + :about_financial_means + end + end, + ) + end + end +end diff --git a/app/services/flow/steps/provider_dwp_override/received_benefit_confirmations_step.rb b/app/services/flow/steps/provider_dwp_override/received_benefit_confirmations_step.rb new file mode 100644 index 0000000000..47216a5b10 --- /dev/null +++ b/app/services/flow/steps/provider_dwp_override/received_benefit_confirmations_step.rb @@ -0,0 +1,18 @@ +module Flow + module Steps + module ProviderDWPOverride + ReceivedBenefitConfirmationsStep = Step.new( + path: ->(application) { Flow::Steps.urls.providers_legal_aid_application_received_benefit_confirmation_path(application) }, + forward: lambda do |application, has_benefit| + if has_benefit + application.change_state_machine_type("PassportedStateMachine") + :has_evidence_of_benefits + else + application.change_state_machine_type("NonPassportedStateMachine") + :about_financial_means + end + end, + ) + end + end +end diff --git a/app/services/flow/steps/step.rb b/app/services/flow/steps/step.rb new file mode 100644 index 0000000000..89da2b1246 --- /dev/null +++ b/app/services/flow/steps/step.rb @@ -0,0 +1,9 @@ +module Flow + module Steps + def self.urls + Rails.application.routes.url_helpers + end + + Step = Struct.new(:path, :forward, :check_answers) + end +end diff --git a/spec/requests/providers/check_client_details_controller_spec.rb b/spec/requests/providers/check_client_details_controller_spec.rb index 00685213ae..008368c605 100644 --- a/spec/requests/providers/check_client_details_controller_spec.rb +++ b/spec/requests/providers/check_client_details_controller_spec.rb @@ -102,17 +102,4 @@ end end end - - describe "PATCH /providers/applications/:legal_aid_application_id/check_client_details" do - subject(:patch_request) { patch "/providers/applications/#{application_id}/check_client_details" } - - before do - login_as application.provider - patch_request - end - - it "continues to the received benefit confirmations page" do - expect(response).to redirect_to(providers_legal_aid_application_received_benefit_confirmation_path(application)) - end - end end diff --git a/spec/requests/providers/confirm_dwp_non_passported_applications_controller_spec.rb b/spec/requests/providers/confirm_dwp_non_passported_applications_controller_spec.rb index f178a9e451..d6413a4dd9 100644 --- a/spec/requests/providers/confirm_dwp_non_passported_applications_controller_spec.rb +++ b/spec/requests/providers/confirm_dwp_non_passported_applications_controller_spec.rb @@ -108,16 +108,6 @@ patch_request end - it "displays the about financial means page" do - patch_request - expect(response).to redirect_to(providers_legal_aid_application_about_financial_means_path(application)) - end - - it "uses the non-passported state machine" do - patch_request - expect(application.reload.state_machine_proxy.type).to eq "NonPassportedStateMachine" - end - it "calls the HMRC::CreateResponsesService" do patch_request expect(HMRC::CreateResponsesService).to have_received(:call).once @@ -150,21 +140,11 @@ expect(application.reload.state).to eq "overriding_dwp_result" end - it "displays the check_client_details page" do - patch_request - expect(response).to redirect_to providers_legal_aid_application_check_client_details_path(application) - end - it "does not update the partner shared benefit field" do patch_request expect(partner.reload.shared_benefit_with_applicant).to be false end - it "uses the passported state machine" do - patch_request - expect(application.reload.state_machine_proxy.type).to eq "PassportedStateMachine" - end - it "calls the HMRC::CreateResponsesService" do patch_request expect(HMRC::CreateResponsesService).to have_received(:call) @@ -196,11 +176,6 @@ expect(partner.reload.shared_benefit_with_applicant).to be true end - it "displays the check_client_details page" do - patch_request - expect(response).to redirect_to providers_legal_aid_application_check_client_details_path(application) - end - it "uses the passported state machine" do patch_request expect(application.reload.state_machine_proxy.type).to eq "PassportedStateMachine" diff --git a/spec/requests/providers/has_evidence_of_benefits_controller_spec.rb b/spec/requests/providers/has_evidence_of_benefits_controller_spec.rb index 4a4ecb99ff..06458752fb 100644 --- a/spec/requests/providers/has_evidence_of_benefits_controller_spec.rb +++ b/spec/requests/providers/has_evidence_of_benefits_controller_spec.rb @@ -88,22 +88,6 @@ expect(dwp_override.has_evidence_of_benefit).to be true end - it "redirects to the upload substantive application page" do - expect(response).to redirect_to(providers_legal_aid_application_substantive_application_path(legal_aid_application)) - end - - context "when the provider has not used delegated functions" do - let(:legal_aid_application) { create(:legal_aid_application, :with_dwp_override, :applicant_details_checked) } - - it "redirects to the upload capital introductions page" do - expect(response).to redirect_to(providers_legal_aid_application_capital_introduction_path(legal_aid_application)) - end - end - - it "updates the state machine type" do - expect(legal_aid_application.reload.state_machine).to be_a PassportedStateMachine - end - context "when the provider chose no" do let(:has_evidence_of_benefit) { "false" } @@ -111,14 +95,6 @@ dwp_override = legal_aid_application.reload.dwp_override expect(dwp_override.has_evidence_of_benefit).to be false end - - it "redirects to the about financial means page" do - expect(response).to redirect_to(providers_legal_aid_application_about_financial_means_path(legal_aid_application)) - end - - it "updates the state machine type" do - expect(legal_aid_application.reload.state_machine).to be_a NonPassportedStateMachine - end end context "when the provider has chosen nothing" do diff --git a/spec/requests/providers/received_benefit_confirmations_controller_spec.rb b/spec/requests/providers/received_benefit_confirmations_controller_spec.rb index e3009c60c8..e5510633f5 100644 --- a/spec/requests/providers/received_benefit_confirmations_controller_spec.rb +++ b/spec/requests/providers/received_benefit_confirmations_controller_spec.rb @@ -87,11 +87,6 @@ expect { patch_request }.to change(DWPOverride, :count).by(-1) end end - - it "continue to the has_evidence_of_benefit page" do - patch_request - expect(response).to redirect_to(providers_legal_aid_application_has_evidence_of_benefit_path(application)) - end end context "when none of these selected" do @@ -101,11 +96,6 @@ expect { patch_request }.not_to change(DWPOverride, :count) end - it "continue to the about financial means page" do - patch_request - expect(response).to redirect_to(providers_legal_aid_application_about_financial_means_path(application)) - end - it "transitions the application state to applicant details checked" do patch_request expect(application.reload.state).to eq "applicant_details_checked" diff --git a/spec/services/flow/steps/provider_dwp_override/check_client_details_step_spec.rb b/spec/services/flow/steps/provider_dwp_override/check_client_details_step_spec.rb new file mode 100644 index 0000000000..29c4fb5aa9 --- /dev/null +++ b/spec/services/flow/steps/provider_dwp_override/check_client_details_step_spec.rb @@ -0,0 +1,11 @@ +require "rails_helper" + +RSpec.describe Flow::Steps::ProviderDWPOverride::CheckClientDetailsStep do + let(:legal_aid_application) { create(:legal_aid_application) } + + it "has expected flow step" do + expect(described_class).to have_flow_step_args(path: "/providers/applications/#{legal_aid_application.id}/check_client_details?locale=en", + forward: :received_benefit_confirmations, + check_answers: nil) + end +end diff --git a/spec/services/flow/steps/provider_dwp_override/confirm_dwp_non_passported_applications_step_spec.rb b/spec/services/flow/steps/provider_dwp_override/confirm_dwp_non_passported_applications_step_spec.rb new file mode 100644 index 0000000000..869749dfde --- /dev/null +++ b/spec/services/flow/steps/provider_dwp_override/confirm_dwp_non_passported_applications_step_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Flow::Steps::ProviderDWPOverride::ConfirmDWPNonPassportedApplicationsStep do + let(:legal_aid_application) { create(:legal_aid_application) } + let(:has_benefit) { true } + let(:args) { has_benefit } + + context "when the provider confirms the application is non passported" do + it "has expected flow step" do + expect(described_class).to have_flow_step_args(path: "/providers/applications/#{legal_aid_application.id}/confirm_dwp_non_passported_applications?locale=en", + forward: :about_financial_means, + check_answers: nil) + end + + it "sets the application's state machine to be the passported state machine when forward is called" do + described_class.forward.call(legal_aid_application, args) + expect(legal_aid_application.state_machine_proxy.type).to eq "NonPassportedStateMachine" + end + end + + context "when the provider confirms the application is passported" do + let(:has_benefit) { false } + + it "has expected flow step" do + expect(described_class).to have_flow_step_args(path: "/providers/applications/#{legal_aid_application.id}/confirm_dwp_non_passported_applications?locale=en", + forward: :check_client_details, + check_answers: nil) + end + + it "sets the application's state machine to be the non passported state machine when forward is called" do + described_class.forward.call(legal_aid_application, args) + expect(legal_aid_application.state_machine_proxy.type).to eq "PassportedStateMachine" + end + end +end diff --git a/spec/services/flow/steps/provider_dwp_override/has_evidence_of_benefits_step_spec.rb b/spec/services/flow/steps/provider_dwp_override/has_evidence_of_benefits_step_spec.rb new file mode 100644 index 0000000000..b67e0e4f4f --- /dev/null +++ b/spec/services/flow/steps/provider_dwp_override/has_evidence_of_benefits_step_spec.rb @@ -0,0 +1,52 @@ +require "rails_helper" + +RSpec.describe Flow::Steps::ProviderDWPOverride::HasEvidenceOfBenefitsStep do + let(:legal_aid_application) { create(:legal_aid_application) } + let(:has_evidence_of_benefits) { true } + let(:args) { has_evidence_of_benefits } + + context "when the provider has evidence that the applicant receives passported benefits" do + context "when the provider has used delegated functions" do + let(:legal_aid_application) { create(:legal_aid_application, :with_proceedings, :with_delegated_functions_on_proceedings, explicit_proceedings: [:da004], set_lead_proceeding: :da004, df_options: { DA004: [Time.zone.today, Time.zone.today] }) } + + it "has expected flow step" do + expect(described_class).to have_flow_step_args(path: "/providers/applications/#{legal_aid_application.id}/has_evidence_of_benefit?locale=en", + forward: :substantive_applications, + check_answers: nil) + end + + it "sets the application's state machine to be the passported state machine when forward is called" do + described_class.forward.call(legal_aid_application, args) + expect(legal_aid_application.state_machine_proxy.type).to eq "PassportedStateMachine" + end + end + + context "when the provider has not used delegated functions" do + it "has expected flow step" do + expect(described_class).to have_flow_step_args(path: "/providers/applications/#{legal_aid_application.id}/has_evidence_of_benefit?locale=en", + forward: :capital_introductions, + check_answers: nil) + end + + it "sets the application's state machine to be the passported state machine when forward is called" do + described_class.forward.call(legal_aid_application, args) + expect(legal_aid_application.state_machine_proxy.type).to eq "PassportedStateMachine" + end + end + end + + context "when the provider does not have evidence that the applicant receives passported bemefits" do + let(:has_evidence_of_benefits) { false } + + it "has expected flow step" do + expect(described_class).to have_flow_step_args(path: "/providers/applications/#{legal_aid_application.id}/has_evidence_of_benefit?locale=en", + forward: :about_financial_means, + check_answers: nil) + end + + it "sets the application's state machine to be the non passported state machine when forward is called" do + described_class.forward.call(legal_aid_application, args) + expect(legal_aid_application.state_machine_proxy.type).to eq "NonPassportedStateMachine" + end + end +end diff --git a/spec/services/flow/steps/provider_dwp_override/received_benefit_confirmations_step_spec.rb b/spec/services/flow/steps/provider_dwp_override/received_benefit_confirmations_step_spec.rb new file mode 100644 index 0000000000..f5c1a909c6 --- /dev/null +++ b/spec/services/flow/steps/provider_dwp_override/received_benefit_confirmations_step_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Flow::Steps::ProviderDWPOverride::ReceivedBenefitConfirmationsStep do + let(:legal_aid_application) { create(:legal_aid_application) } + let(:has_benefit) { true } + let(:args) { has_benefit } + + context "when the provider confirms the applicant is in receipt of passported benefit" do + it "has expected flow step" do + expect(described_class).to have_flow_step_args(path: "/providers/applications/#{legal_aid_application.id}/received_benefit_confirmation?locale=en", + forward: :has_evidence_of_benefits, + check_answers: nil) + end + + it "sets the application's state machine to be the passported state machine when forward is called" do + described_class.forward.call(legal_aid_application, args) + expect(legal_aid_application.state_machine_proxy.type).to eq "PassportedStateMachine" + end + end + + context "when the provider confirms the applicant is not in receipt of passported benefit" do + let(:has_benefit) { false } + + it "has expected flow step" do + expect(described_class).to have_flow_step_args(path: "/providers/applications/#{legal_aid_application.id}/received_benefit_confirmation?locale=en", + forward: :about_financial_means, + check_answers: nil) + end + + it "sets the application's state machine to be the non passported state machine when forward is called" do + described_class.forward.call(legal_aid_application, args) + expect(legal_aid_application.state_machine_proxy.type).to eq "NonPassportedStateMachine" + end + end +end diff --git a/spec/support/have_flow_steps_args.rb b/spec/support/have_flow_steps_args.rb new file mode 100644 index 0000000000..3cb6c36642 --- /dev/null +++ b/spec/support/have_flow_steps_args.rb @@ -0,0 +1,23 @@ +RSpec::Matchers.define :have_flow_step_args do |expected| + results = { path: nil, forward: nil, check_answers: nil } + + match do |actual| + results = [] + results << "expected #{actual.path.call(legal_aid_application)} to equal #{expected[:path]}\n" unless actual.path.call(legal_aid_application) == expected[:path] + if actual.forward.is_a?(Proc) + results << "expected #{actual.forward.call(legal_aid_application, args)} to equal #{expected[:forward]}\n" unless actual.forward.call(legal_aid_application, args) == expected[:forward] + else + results << "expected #{actual.forward} to equal #{expected[:forward]}\n" unless actual.forward == expected[:forward] + end + results << "expected #{actual.check_answers} to equal #{expected[:check_answers]}\n" unless actual.check_answers == expected[:check_answers] + results.empty? + end + + failure_message do |_actual| + results.join("\n") + end + + description do + "have matching flow step arguments" + end +end