-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ap-4463: refactor has_evidence_of_benefits step
- Loading branch information
Showing
3 changed files
with
76 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
spec/services/flow/steps/has_evidence_of_benefits_step_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |