Skip to content

Commit

Permalink
Add consent document overview index page
Browse files Browse the repository at this point in the history
This adds the index page for viewing the qualification requests for a
consent document overview.
  • Loading branch information
thomasleese committed Feb 12, 2024
1 parent 502b440 commit 426c07c
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class QualificationRequestsController < BaseController
define_history_reset :index

def index
@view_object = QualificationRequestsViewObject.new(application_form:)
end
end
end
2 changes: 1 addition & 1 deletion app/lib/document_continue_redirection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ def further_information_request_url
end

def qualification_request_url
[:teacher_interface, :application_form, documentable]
%i[teacher_interface application_form qualification_requests]
end
end
1 change: 1 addition & 0 deletions app/models/qualification_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class QualificationRequest < ApplicationRecord
consent_required
.consent_requested
.where(consent_received_at: nil)
.joins(assessment: :application_form)
.merge(ApplicationForm.assessable)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ def request_professional_standing_certificate?
def request_qualification_consent?
return false if assessment.nil?

qualification_requests
.joins(assessment: :application_form)
.consent_respondable
.exists?
qualification_requests.consent_respondable.exists?
end

def show_work_history_under_submission_banner?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# frozen_string_literal: true

module TeacherInterface
class QualificationRequestsViewObject
include QualificationHelper

def initialize(application_form:)
@application_form = application_form
end

def task_list_sections
qualification_requests.map do |qualification_request|
{
title: qualification_title(qualification_request.qualification),
items: task_list_items(qualification_request),
}
end
end

private

attr_reader :application_form

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

def task_list_items(qualification_request)
institution_name = qualification_request.qualification.institution_name

[
{
link: [
:download,
:teacher_interface,
:application_form,
qualification_request,
],
name: "Download #{institution_name} consent document",
status:
download_unsigned_consent_document_status(qualification_request),
},
{
link: [
:teacher_interface,
:application_form,
qualification_request.signed_consent_document,
],
name: "Upload #{institution_name} consent document",
status: upload_signed_consent_document_status(qualification_request),
},
]
end

def download_unsigned_consent_document_status(qualification_request)
if qualification_request.unsigned_consent_document_downloaded
:completed
else
:not_started
end
end

def upload_signed_consent_document_status(qualification_request)
if qualification_request.unsigned_consent_document_downloaded
if qualification_request.signed_consent_document.completed?
:completed
else
:not_started
end
else
:cannot_start
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<% content_for :page_title, "Consent documents overview" %>
<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_path) %>

<h1 class="govuk-heading-l">Consent documents overview</h1>
<h1 class="govuk-heading-xl">Consent documents overview</h1>

<%= render(TaskList::Component.new(@view_object.task_list_sections)) %>

<%= govuk_button_link_to t("teacher_interface.application_forms.show.draft.save"), destroy_teacher_session_path, secondary: true %>
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,12 @@

resources :qualification_requests,
path: "/qualification-requests",
only: %i[index]
only: %i[index] do
member do
get "download"
get "upload"
end
end
end

resources :reference_requests,
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/document_continue_redirection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@

it do
is_expected.to eq(
[:teacher_interface, :application_form, qualification_request],
%i[teacher_interface application_form qualification_requests],
)
end
end
Expand All @@ -152,7 +152,7 @@

it do
is_expected.to eq(
[:teacher_interface, :application_form, qualification_request],
%i[teacher_interface application_form qualification_requests],
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module TeacherInterface
class QualificationRequests < SitePrism::Page
set_url "/teacher/application/qualification-requests"

section :task_list, TaskList, ".app-task-list"

element :check_your_answers_button,
".govuk-button:not(.govuk-button--secondary)"
element :save_and_sign_out_button, ".govuk-button.govuk-button--secondary"
Expand Down
12 changes: 12 additions & 0 deletions spec/system/teacher_interface/qualification_consent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
when_i_visit_the(:teacher_application_page)
then_i_see_the(:teacher_application_page)
and_i_see_qualification_consent_start_now_content

when_i_click_the_start_button
then_i_see_the(:teacher_qualification_requests_page)
and_i_see_the_download_and_upload_tasks
end

def given_there_is_an_application_form
Expand Down Expand Up @@ -55,6 +59,14 @@ def and_i_see_qualification_consent_sign_out_content
)
end

def and_i_see_the_download_and_upload_tasks
task_list = teacher_qualification_requests_page.task_list
expect(task_list.sections.count).to eq(1)

task_list_section = task_list.sections.first
expect(task_list_section.items.count).to eq(2)
end

def teacher
@teacher ||= create(:teacher)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe TeacherInterface::QualificationRequestsViewObject do
subject(:view_object) { described_class.new(application_form:) }

let(:application_form) do
create(:application_form, :verification_stage, :with_assessment)
end

describe "#task_list_sections" do
subject(:task_list_sections) { view_object.task_list_sections }

it { is_expected.to be_empty }

context "with a qualification request" do
let!(:qualification_request) do
create(
:qualification_request,
:consent_requested,
assessment: application_form.assessment,
qualification:
create(
:qualification,
application_form:,
title: "BSc Maths",
institution_name: "University of Maths",
),
)
end

it do
is_expected.to eq(
[
{
title: "BSc Maths (University of Maths)",
items: [
{
name: "Download University of Maths consent document",
link: [
:download,
:teacher_interface,
:application_form,
qualification_request,
],
status: :not_started,
},
{
name: "Upload University of Maths consent document",
link: [
:teacher_interface,
:application_form,
qualification_request.signed_consent_document,
],
status: :cannot_start,
},
],
},
],
)
end

context "when the unsigned consent document is downloaded" do
before do
qualification_request.update!(
unsigned_consent_document_downloaded: true,
)
end

it do
is_expected.to eq(
[
{
title: "BSc Maths (University of Maths)",
items: [
{
name: "Download University of Maths consent document",
link: [
:download,
:teacher_interface,
:application_form,
qualification_request,
],
status: :completed,
},
{
name: "Upload University of Maths consent document",
link: [
:teacher_interface,
:application_form,
qualification_request.signed_consent_document,
],
status: :not_started,
},
],
},
],
)
end

context "when the signed consent document is uploaded" do
before do
qualification_request.signed_consent_document.update!(
completed: true,
)
end

it do
is_expected.to eq(
[
{
title: "BSc Maths (University of Maths)",
items: [
{
name: "Download University of Maths consent document",
link: [
:download,
:teacher_interface,
:application_form,
qualification_request,
],
status: :completed,
},
{
name: "Upload University of Maths consent document",
link: [
:teacher_interface,
:application_form,
qualification_request.signed_consent_document,
],
status: :completed,
},
],
},
],
)
end
end
end
end
end
end

0 comments on commit 426c07c

Please sign in to comment.