Skip to content

Commit

Permalink
Add review recommendation
Browse files Browse the repository at this point in the history
This adds a new assessment recommendation called review which is used
when we need to send an application to review after verification.
  • Loading branch information
thomasleese committed Oct 5, 2023
1 parent eacc04f commit e47ea99
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 125 deletions.
57 changes: 35 additions & 22 deletions app/models/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,23 @@ 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,
inclusion: {
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
Expand All @@ -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
Expand All @@ -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? ||
Expand All @@ -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

Expand Down
227 changes: 124 additions & 103 deletions spec/models/assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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? }

Expand Down Expand Up @@ -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 }

Expand Down

0 comments on commit e47ea99

Please sign in to comment.