diff --git a/app/models/assessment.rb b/app/models/assessment.rb index 91853284c3..3c6925187f 100644 --- a/app/models/assessment.rb +++ b/app/models/assessment.rb @@ -43,12 +43,12 @@ class Assessment < ApplicationRecord enum :recommendation, { award: "award", - verify: "verify", decline: "decline", request_further_information: "request_further_information", + review: "review", unknown: "unknown", - }, - default: :unknown + verify: "verify", + } validates :recommendation, presence: true, @@ -56,18 +56,10 @@ class Assessment < ApplicationRecord in: recommendations.values, } - def unknown! - update!(recommendation: "unknown", recommended_at: nil) - end - def award! update!(recommendation: "award", recommended_at: Time.zone.now) end - def verify! - update!(recommendation: "verify", recommended_at: Time.zone.now) - end - def decline! update!(recommendation: "decline", recommended_at: Time.zone.now) end @@ -79,6 +71,18 @@ def request_further_information! ) end + def review! + update!(recommendation: "review", recommended_at: Time.zone.now) + end + + def unknown! + update!(recommendation: "unknown", recommended_at: nil) + end + + def verify! + update!(recommendation: "verify", recommended_at: Time.zone.now) + end + def completed? award? || decline? end @@ -99,14 +103,6 @@ def can_award? end end - def can_verify? - return false unless application_form.created_under_new_regulations? - - return false if skip_verification? - - all_sections_or_further_information_requests_passed? - end - def can_decline? if unknown? any_preliminary_section_failed? || @@ -130,19 +126,36 @@ def can_request_further_information? end end + def can_review? + return false unless application_form.created_under_new_regulations? + + return false if skip_verification? + + false + end + + def can_verify? + return false unless application_form.created_under_new_regulations? + + return false if skip_verification? + + all_sections_or_further_information_requests_passed? + end + def recommendable? - can_award? || can_verify? || can_decline? || - can_request_further_information? + can_award? || can_decline? || can_request_further_information? || + can_review? || can_verify? end def available_recommendations [].tap do |recommendations| recommendations << "award" if can_award? - recommendations << "verify" if can_verify? recommendations << "decline" if can_decline? if can_request_further_information? recommendations << "request_further_information" end + recommendations << "review" if can_review? + recommendations << "verify" if can_verify? end end diff --git a/spec/models/assessment_spec.rb b/spec/models/assessment_spec.rb index ffa38c9b01..4f27d29499 100644 --- a/spec/models/assessment_spec.rb +++ b/spec/models/assessment_spec.rb @@ -52,11 +52,12 @@ it do is_expected.to define_enum_for(:recommendation).with_values( - unknown: "unknown", award: "award", - verify: "verify", decline: "decline", request_further_information: "request_further_information", + review: "review", + unknown: "unknown", + verify: "verify", ).backed_by_column_of_type(:string) end end @@ -192,107 +193,6 @@ end end - describe "#can_verify?" do - subject(:can_verify?) { assessment.can_verify? } - - context "with an application under new regulations" do - let(:application_form) { create(:application_form) } - - context "with an unknown assessment" do - before do - create(:assessment_section, :personal_information, assessment:) - end - it { is_expected.to be false } - end - - context "with a passed assessment" do - before do - create( - :assessment_section, - :personal_information, - :passed, - assessment:, - ) - end - it { is_expected.to be true } - end - - context "with a passed assessment and reduced evidence" do - before do - application_form.update!(reduced_evidence_accepted: true) - create( - :assessment_section, - :personal_information, - :passed, - assessment:, - ) - end - it { is_expected.to be false } - end - - context "with a passed assessment and work history not required" do - before do - application_form.update!(needs_work_history: false) - create( - :assessment_section, - :personal_information, - :passed, - assessment:, - ) - end - it { is_expected.to be false } - end - - context "with a failed assessment" do - before do - create( - :assessment_section, - :personal_information, - :failed, - assessment:, - ) - end - it { is_expected.to be false } - - context "when further information was requested" do - before { assessment.request_further_information! } - - context "with a passed further information request" do - before do - create(:further_information_request, :passed, assessment:) - end - it { is_expected.to be true } - end - - context "with a failed further information request" do - before do - create(:further_information_request, :failed, assessment:) - end - it { is_expected.to be false } - end - end - end - - context "with a mixture of assessments" do - before do - create( - :assessment_section, - :personal_information, - :passed, - assessment:, - ) - create(:assessment_section, :qualifications, :failed, assessment:) - end - it { is_expected.to be false } - end - end - - context "with an application under old regulations" do - let(:application_form) { create(:application_form, :old_regs) } - it { is_expected.to be false } - end - end - describe "#can_decline?" do subject(:can_decline?) { assessment.can_decline? } @@ -430,6 +330,127 @@ end end + describe "#can_review?" do + subject(:can_review?) { assessment.can_review? } + + context "with an application under new regulations" do + let(:application_form) { create(:application_form) } + + context "with an unknown assessment" do + before do + create(:assessment_section, :personal_information, assessment:) + end + it { is_expected.to be false } + end + end + + context "with an application under old regulations" do + let(:application_form) { create(:application_form, :old_regs) } + it { is_expected.to be false } + end + end + + describe "#can_verify?" do + subject(:can_verify?) { assessment.can_verify? } + + context "with an application under new regulations" do + let(:application_form) { create(:application_form) } + + context "with an unknown assessment" do + before do + create(:assessment_section, :personal_information, assessment:) + end + it { is_expected.to be false } + end + + context "with a passed assessment" do + before do + create( + :assessment_section, + :personal_information, + :passed, + assessment:, + ) + end + it { is_expected.to be true } + end + + context "with a passed assessment and reduced evidence" do + before do + application_form.update!(reduced_evidence_accepted: true) + create( + :assessment_section, + :personal_information, + :passed, + assessment:, + ) + end + it { is_expected.to be false } + end + + context "with a passed assessment and work history not required" do + before do + application_form.update!(needs_work_history: false) + create( + :assessment_section, + :personal_information, + :passed, + assessment:, + ) + end + it { is_expected.to be false } + end + + context "with a failed assessment" do + before do + create( + :assessment_section, + :personal_information, + :failed, + assessment:, + ) + end + it { is_expected.to be false } + + context "when further information was requested" do + before { assessment.request_further_information! } + + context "with a passed further information request" do + before do + create(:further_information_request, :passed, assessment:) + end + it { is_expected.to be true } + end + + context "with a failed further information request" do + before do + create(:further_information_request, :failed, assessment:) + end + it { is_expected.to be false } + end + end + end + + context "with a mixture of assessments" do + before do + create( + :assessment_section, + :personal_information, + :passed, + assessment:, + ) + create(:assessment_section, :qualifications, :failed, assessment:) + end + it { is_expected.to be false } + end + end + + context "with an application under old regulations" do + let(:application_form) { create(:application_form, :old_regs) } + it { is_expected.to be false } + end + end + describe "#available_recommendations" do subject(:available_recommendations) { assessment.available_recommendations }