Skip to content

Commit

Permalink
Add QualificationRequestsViewObject
Browse files Browse the repository at this point in the history
This adds a view object for the qualification requests.
  • Loading branch information
thomasleese committed Feb 15, 2024
1 parent 0d53032 commit 31b6891
Show file tree
Hide file tree
Showing 2 changed files with 267 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# frozen_string_literal: true

module AssessorInterface
class QualificationRequestsViewObject
include QualificationHelper

def initialize(application_form:)
@application_form = application_form
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

{ title: "Check and select consent method", href: "#", status: }
end

def task_items_for_qualification_request(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

def qualification_requests
@qualification_requests ||=
application_form.assessment.qualification_requests.order_by_user
end

def unsigned_consent_method_task_items(qualification_request)
[
{
title: "Generate consent document",
href: "#",
status:
(
if qualification_request.unsigned_consent_document_generated
"completed"
else
"not_started"
end
),
},
]
end

def signed_consent_method_task_items(qualification_request)
document_uploaded =
qualification_request.unsigned_consent_document.completed?

[
{
title: "Upload consent document",
href: "#",
status: document_uploaded ? "completed" : "not_started",
},
{
title: "Send consent document to applicant",
href: "#",
status:
if document_uploaded
if qualification_request.consent_requested?
"completed"
else
"not_started"
end
else
"cannot_start"
end,
},
{
title: "Record applicant response",
href: "#",
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.unsigned_consent_document_generated ||
qualification_request.consent_received?

[
{
title: "Request Ecctis verification",
href: "#",
status:
if can_start
qualification_request.requested? ? "completed" : "not_started"
else
"cannot_start"
end,
},
{
title: "Record Ecctis response",
href: "#",
status:
if can_start && qualification_request.requested?
qualification_request.received? ? "completed" : "not_started"
else
"cannot_start"
end,
},
]
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# 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_consent_methods_selected?" do
subject(:all_consent_methods_selected?) do
view_object.all_consent_methods_selected?
end

it { is_expected.to be false }

context "when consent methods are chosen" do
before { qualification_request.consent_method_unsigned! }

it { is_expected.to be true }
end
end

describe "#check_consent_method_task_item" do
subject(:check_consent_method_task_item) do
view_object.check_consent_method_task_item
end

it do
is_expected.to eq(
{
title: "Check and select consent method",
href: "#",
status: "not_started",
},
)
end

context "when consent methods are chosen" do
before { qualification_request.consent_method_unsigned! }

it do
is_expected.to eq(
{
title: "Check and select consent method",
href: "#",
status: "completed",
},
)
end
end
end

describe "#task_items_for_qualification_request" do
subject(:task_items_for_qualification_request) do
view_object.task_items_for_qualification_request(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(
[
{
title: "Generate consent document",
href: "#",
status: "not_started",
},
{
title: "Request Ecctis verification",
href: "#",
status: "cannot_start",
},
{
title: "Record Ecctis response",
href: "#",
status: "cannot_start",
},
],
)
end
end

context "when signed consent method" do
before { qualification_request.consent_method_signed_ecctis! }

it do
is_expected.to eq(
[
{
title: "Upload consent document",
href: "#",
status: "not_started",
},
{
title: "Send consent document to applicant",
href: "#",
status: "cannot_start",
},
{
title: "Record applicant response",
href: "#",
status: "cannot_start",
},
{
title: "Request Ecctis verification",
href: "#",
status: "cannot_start",
},
{
title: "Record Ecctis response",
href: "#",
status: "cannot_start",
},
],
)
end
end
end
end

0 comments on commit 31b6891

Please sign in to comment.