-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a view object for the qualification requests.
- Loading branch information
1 parent
9b08622
commit 3d5f648
Showing
4 changed files
with
334 additions
and
0 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
171 changes: 171 additions & 0 deletions
171
app/view_objects/assessor_interface/qualification_requests_view_object.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,171 @@ | ||
# frozen_string_literal: true | ||
|
||
module AssessorInterface | ||
class QualificationRequestsViewObject | ||
include QualificationHelper | ||
|
||
def initialize(application_form:) | ||
@application_form = application_form | ||
end | ||
|
||
def all_task_items | ||
items = [ | ||
check_consent_method_task_item, | ||
if generate_consent_document_in_all_qualifications? | ||
generate_consent_document_task_item | ||
end, | ||
].compact | ||
|
||
if show_individual_task_items? | ||
items | ||
else | ||
items + | ||
individual_task_items_for( | ||
qualification_request: qualification_requests.first, | ||
) | ||
end | ||
end | ||
|
||
def show_individual_task_items? | ||
all_consent_methods_selected? && qualification_requests.count > 1 | ||
end | ||
|
||
def individual_task_items_for(qualification_request:) | ||
return [] if qualification_request.consent_method_unknown? | ||
|
||
if qualification_request.consent_method_unsigned? | ||
unsigned_consent_method_task_items(qualification_request) | ||
else | ||
signed_consent_method_task_items(qualification_request) | ||
end + ecctis_task_items(qualification_request) | ||
end | ||
|
||
private | ||
|
||
attr_reader :application_form | ||
|
||
delegate :assessment, to: :application_form | ||
|
||
def qualification_requests | ||
@qualification_requests ||= | ||
application_form.assessment.qualification_requests.order_by_user | ||
end | ||
|
||
def all_consent_methods_selected? | ||
qualification_requests.none?(&:consent_method_unknown?) | ||
end | ||
|
||
def check_consent_method_task_item | ||
status = | ||
if qualification_requests.all?(&:consent_method_unknown?) | ||
"not_started" | ||
elsif all_consent_methods_selected? | ||
"completed" | ||
else | ||
"in_progress" | ||
end | ||
|
||
{ name: "Check and select consent method", link: "#", status: } | ||
end | ||
|
||
def generate_consent_document_in_all_qualifications? | ||
all_consent_methods_selected? && | ||
qualification_requests.consent_method_unsigned.count >= 2 | ||
end | ||
|
||
def generate_consent_document_task_item | ||
{ | ||
name: "Generate consent document", | ||
link: "#", | ||
status: | ||
( | ||
if assessment.unsigned_consent_document_generated | ||
"completed" | ||
else | ||
"not_started" | ||
end | ||
), | ||
} | ||
end | ||
|
||
def unsigned_consent_method_task_items(_qualification_request) | ||
if generate_consent_document_in_all_qualifications? | ||
[] | ||
else | ||
[generate_consent_document_task_item] | ||
end | ||
end | ||
|
||
def signed_consent_method_task_items(qualification_request) | ||
document_uploaded = | ||
qualification_request.unsigned_consent_document.completed? | ||
|
||
[ | ||
{ | ||
name: "Upload consent document", | ||
link: "#", | ||
status: document_uploaded ? "completed" : "not_started", | ||
}, | ||
{ | ||
name: "Send consent document to applicant", | ||
link: "#", | ||
status: | ||
if document_uploaded | ||
if qualification_request.consent_requested? | ||
"completed" | ||
else | ||
"not_started" | ||
end | ||
else | ||
"cannot_start" | ||
end, | ||
}, | ||
{ | ||
name: "Record applicant response", | ||
link: "#", | ||
status: | ||
if document_uploaded | ||
if qualification_request.consent_received? | ||
"completed" | ||
else | ||
"not_started" | ||
end | ||
else | ||
"cannot_start" | ||
end, | ||
}, | ||
] | ||
end | ||
|
||
def ecctis_task_items(qualification_request) | ||
can_start = | ||
( | ||
qualification_request.consent_method_unsigned? && | ||
assessment.unsigned_consent_document_generated | ||
) || qualification_request.consent_received? | ||
|
||
[ | ||
{ | ||
name: "Request Ecctis verification", | ||
link: "#", | ||
status: | ||
if can_start | ||
qualification_request.requested? ? "completed" : "not_started" | ||
else | ||
"cannot_start" | ||
end, | ||
}, | ||
{ | ||
name: "Record Ecctis response", | ||
link: "#", | ||
status: | ||
if can_start && qualification_request.requested? | ||
qualification_request.received? ? "completed" : "not_started" | ||
else | ||
"cannot_start" | ||
end, | ||
}, | ||
] | ||
end | ||
end | ||
end |
158 changes: 158 additions & 0 deletions
158
spec/view_objects/assessor_interface/qualification_requests_view_object_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,158 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe AssessorInterface::QualificationRequestsViewObject do | ||
subject(:view_object) { described_class.new(application_form:) } | ||
|
||
let(:application_form) do | ||
create(:application_form, :verification_stage, :with_assessment) | ||
end | ||
|
||
let!(:qualification_request) do | ||
create( | ||
:qualification_request, | ||
assessment: application_form.assessment, | ||
qualification: create(:qualification, application_form:), | ||
) | ||
end | ||
|
||
describe "#all_task_items" do | ||
subject(:all_task_items) { view_object.all_task_items } | ||
|
||
it do | ||
is_expected.to eq( | ||
[ | ||
{ | ||
name: "Check and select consent method", | ||
link: "#", | ||
status: "not_started", | ||
}, | ||
], | ||
) | ||
end | ||
|
||
context "when consent methods are chosen" do | ||
before { qualification_request.consent_method_unsigned! } | ||
|
||
it do | ||
is_expected.to eq( | ||
[ | ||
{ | ||
name: "Check and select consent method", | ||
link: "#", | ||
status: "completed", | ||
}, | ||
{ | ||
name: "Generate consent document", | ||
link: "#", | ||
status: "not_started", | ||
}, | ||
{ | ||
name: "Request Ecctis verification", | ||
link: "#", | ||
status: "cannot_start", | ||
}, | ||
{ | ||
name: "Record Ecctis response", | ||
link: "#", | ||
status: "cannot_start", | ||
}, | ||
], | ||
) | ||
end | ||
end | ||
end | ||
|
||
describe "#show_individual_task_items?" do | ||
subject(:show_individual_task_items?) do | ||
view_object.show_individual_task_items? | ||
end | ||
|
||
it { is_expected.to be false } | ||
|
||
context "with more than one qualification request" do | ||
before do | ||
qualification_request.consent_method_unsigned! | ||
create( | ||
:qualification_request, | ||
assessment: application_form.assessment, | ||
consent_method: "unsigned", | ||
qualification: create(:qualification, application_form:), | ||
) | ||
end | ||
|
||
it { is_expected.to be true } | ||
end | ||
end | ||
|
||
describe "#individual_task_items_for" do | ||
subject(:individual_task_items_for) do | ||
view_object.individual_task_items_for(qualification_request:) | ||
end | ||
|
||
it { is_expected.to be_empty } | ||
|
||
context "when unsigned consent method" do | ||
before { qualification_request.consent_method_unsigned! } | ||
|
||
it do | ||
is_expected.to eq( | ||
[ | ||
{ | ||
name: "Generate consent document", | ||
link: "#", | ||
status: "not_started", | ||
}, | ||
{ | ||
name: "Request Ecctis verification", | ||
link: "#", | ||
status: "cannot_start", | ||
}, | ||
{ | ||
name: "Record Ecctis response", | ||
link: "#", | ||
status: "cannot_start", | ||
}, | ||
], | ||
) | ||
end | ||
end | ||
|
||
context "when signed consent method" do | ||
before { qualification_request.consent_method_signed_ecctis! } | ||
|
||
it do | ||
is_expected.to eq( | ||
[ | ||
{ | ||
name: "Upload consent document", | ||
link: "#", | ||
status: "not_started", | ||
}, | ||
{ | ||
name: "Send consent document to applicant", | ||
link: "#", | ||
status: "cannot_start", | ||
}, | ||
{ | ||
name: "Record applicant response", | ||
link: "#", | ||
status: "cannot_start", | ||
}, | ||
{ | ||
name: "Request Ecctis verification", | ||
link: "#", | ||
status: "cannot_start", | ||
}, | ||
{ | ||
name: "Record Ecctis response", | ||
link: "#", | ||
status: "cannot_start", | ||
}, | ||
], | ||
) | ||
end | ||
end | ||
end | ||
end |