Skip to content

Commit

Permalink
ap-4463: refactor has_evidence_of_benefits step
Browse files Browse the repository at this point in the history
  • Loading branch information
kmahern committed Nov 20, 2023
1 parent 4baa5a0 commit 100ccb4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 12 deletions.
13 changes: 1 addition & 12 deletions app/services/flow/flows/provider_dwp_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,7 @@ class ProviderDWPOverride < FlowSteps
confirm_dwp_non_passported_applications: Flow::Steps::ConfirmDWPNonPassportedApplicationsStep,
check_client_details: Flow::Steps::CheckClientDetailsStep,
received_benefit_confirmations: Flow::Steps::ReceivedBenefitConfirmationsStep,
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,
},
has_evidence_of_benefits: Flow::Steps::HasEvidenceOfBenefitsStep,
}.freeze
end
end
Expand Down
17 changes: 17 additions & 0 deletions app/services/flow/steps/has_evidence_of_benefits_step.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Flow
module Steps
HasEvidenceOfBenefitsStep = Step.new(
->(application) { urls.providers_legal_aid_application_has_evidence_of_benefit_path(application) },
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,
nil,
)
end
end
58 changes: 58 additions & 0 deletions spec/services/flow/steps/has_evidence_of_benefits_step_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require "rails_helper"

RSpec.describe Flow::Steps::HasEvidenceOfBenefitsStep do
let(:legal_aid_application) { create(:legal_aid_application) }

describe "#path" do
subject(:path) { described_class.path.call(legal_aid_application) }

it "returns the has_evidence_of_benefit_path when called" do
expect(path).to eq "/providers/applications/#{legal_aid_application.id}/has_evidence_of_benefit?locale=en"
end
end

describe "#forward" do
subject(:forward) { described_class.forward.call(legal_aid_application, has_evidence_of_benefits) }

let(:has_evidence_of_benefits) { true }

context "when the provider has evidence that the applicant receives passported bemefits" do
context "when the provider has used delegated functions for the application" 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 "returns the substantive_applications step when called" do
expect(forward).to eq(:substantive_applications)
end

it "sets the application's state machine to be the passported state machine" do
forward
expect(legal_aid_application.state_machine_proxy.type).to eq "PassportedStateMachine"
end
end

context "when the provider has not used delegated functions for the application" do
it "returns the capital_introductions step when called" do
expect(forward).to eq(:capital_introductions)
end

it "sets the application's state machine to be the passported state machine" do
forward
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 "returns the about_financial_means step when called" do
expect(forward).to eq(:about_financial_means)
end

it "sets the application's state machine to be the non passported state machine" do
forward
expect(legal_aid_application.state_machine_proxy.type).to eq "NonPassportedStateMachine"
end
end
end
end

0 comments on commit 100ccb4

Please sign in to comment.