From 2d27e42f3162eb9057601ccf101b6d3f1036bbe3 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Fri, 23 Feb 2024 08:17:33 +0100 Subject: [PATCH 1/3] Add ConsentRequest This adds a model for representing a consent request to the applicant where we need their signed consent before we can send the documents to Ecctis. --- app/models/concerns/requestable.rb | 6 +-- app/models/consent_request.rb | 19 ++++++++++ config/analytics.yml | 13 +++++++ .../20240223065851_add_consent_requests.rb | 16 ++++++++ db/schema.rb | 20 +++++++++- spec/factories/consent_requests.rb | 36 ++++++++++++++++++ spec/models/consent_request_spec.rb | 15 ++++++++ spec/support/shared_examples/requestable.rb | 37 +++++++++++-------- 8 files changed, 143 insertions(+), 19 deletions(-) create mode 100644 app/models/consent_request.rb create mode 100644 db/migrate/20240223065851_add_consent_requests.rb create mode 100644 spec/factories/consent_requests.rb create mode 100644 spec/models/consent_request_spec.rb diff --git a/app/models/concerns/requestable.rb b/app/models/concerns/requestable.rb index c3e485a853..75e7bc139a 100644 --- a/app/models/concerns/requestable.rb +++ b/app/models/concerns/requestable.rb @@ -39,15 +39,15 @@ def received? end def reviewed? - review_passed != nil + try(:review_passed) != nil end def review_passed? - review_passed == true + try(:review_passed) == true end def review_failed? - review_passed == false + try(:review_passed) == false end def verified? diff --git a/app/models/consent_request.rb b/app/models/consent_request.rb new file mode 100644 index 0000000000..32ff570021 --- /dev/null +++ b/app/models/consent_request.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class ConsentRequest < ApplicationRecord + ATTACHABLE_DOCUMENT_TYPES = %w[signed_consent unsigned_consent].freeze + + include Documentable + include Requestable + + belongs_to :qualification + + scope :order_by_role, + -> { joins(:qualification).order("qualifications.start_date": :desc) } + scope :order_by_user, + -> { joins(:qualification).order("qualifications.created_at": :asc) } + + def expires_after + 6.weeks + end +end diff --git a/config/analytics.yml b/config/analytics.yml index a5b1a7ba2e..b61e96c43e 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -86,6 +86,19 @@ - working_days_started_to_recommendation - working_days_submission_to_recommendation - working_days_submission_to_started + :consent_requests: + - assessment_id + - created_at + - expired_at + - id + - qualification_id + - received_at + - requested_at + - unsigned_document_downloaded + - updated_at + - verified_at + - verify_note + - verify_passed :countries: - code - created_at diff --git a/db/migrate/20240223065851_add_consent_requests.rb b/db/migrate/20240223065851_add_consent_requests.rb new file mode 100644 index 0000000000..3bd240f984 --- /dev/null +++ b/db/migrate/20240223065851_add_consent_requests.rb @@ -0,0 +1,16 @@ +class AddConsentRequests < ActiveRecord::Migration[7.1] + def change + create_table :consent_requests do |t| + t.datetime :received_at + t.datetime :requested_at + t.datetime :expired_at + t.boolean :unsigned_document_downloaded, default: false, null: false + t.datetime :verified_at + t.text :verify_note, default: "", null: false + t.boolean :verify_passed + t.references :assessment, null: false, foreign_key: true + t.references :qualification, null: false, foreign_key: true + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 80dd710571..7c8538ae8c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_16_114800) do +ActiveRecord::Schema[7.1].define(version: 2024_02_23_065851) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -146,6 +146,22 @@ t.index ["application_form_id"], name: "index_assessments_on_application_form_id" end + create_table "consent_requests", force: :cascade do |t| + t.datetime "received_at" + t.datetime "requested_at" + t.datetime "expired_at" + t.boolean "unsigned_document_downloaded", default: false, null: false + t.datetime "verified_at" + t.text "verify_note", default: "", null: false + t.boolean "verify_passed" + t.bigint "assessment_id", null: false + t.bigint "qualification_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["assessment_id"], name: "index_consent_requests_on_assessment_id" + t.index ["qualification_id"], name: "index_consent_requests_on_qualification_id" + end + create_table "countries", force: :cascade do |t| t.string "code", null: false t.datetime "created_at", null: false @@ -551,6 +567,8 @@ add_foreign_key "application_forms", "teachers" add_foreign_key "assessment_sections", "assessments" add_foreign_key "assessments", "application_forms" + add_foreign_key "consent_requests", "assessments" + add_foreign_key "consent_requests", "qualifications" add_foreign_key "dqt_trn_requests", "application_forms" add_foreign_key "eligibility_checks", "regions" add_foreign_key "further_information_request_items", "work_histories" diff --git a/spec/factories/consent_requests.rb b/spec/factories/consent_requests.rb new file mode 100644 index 0000000000..c41b6017fe --- /dev/null +++ b/spec/factories/consent_requests.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :consent_request do + association :assessment + association :qualification, :completed + + trait :with_unsigned_upload do + after(:create) do |consent_request, _evaluator| + create(:upload, document: consent_request.unsigned_consent_document) + end + end + + trait :with_signed_upload do + after(:create) do |consent_request, _evaluator| + create(:upload, document: consent_request.signed_consent_document) + end + end + + trait :requested do + with_unsigned_upload + requested_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } + end + + trait :received do + requested + with_signed_upload + received_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } + end + + trait :expired do + requested + expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } + end + end +end diff --git a/spec/models/consent_request_spec.rb b/spec/models/consent_request_spec.rb new file mode 100644 index 0000000000..ee3a0abdb5 --- /dev/null +++ b/spec/models/consent_request_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe ConsentRequest, type: :model do + subject(:consent_request) { create(:consent_request) } + + it_behaves_like "a documentable" + it_behaves_like "a requestable" + + describe "#expires_after" do + subject(:expires_after) { consent_request.expires_after } + it { is_expected.to eq(6.weeks) } + end +end diff --git a/spec/support/shared_examples/requestable.rb b/spec/support/shared_examples/requestable.rb index 954386ab23..3495f835ba 100644 --- a/spec/support/shared_examples/requestable.rb +++ b/spec/support/shared_examples/requestable.rb @@ -9,7 +9,6 @@ it { is_expected.to_not validate_presence_of(:requested_at) } it { is_expected.to_not validate_presence_of(:received_at) } it { is_expected.to_not validate_presence_of(:expired_at) } - it { is_expected.to_not validate_presence_of(:reviewed_at) } end describe "#requested!" do @@ -49,16 +48,6 @@ end describe "#status" do - it "is completed when review passed is true" do - subject.review_passed = true - expect(subject.status).to eq("accepted") - end - - it "is rejected when review passed is false" do - subject.review_passed = false - expect(subject.status).to eq("rejected") - end - it "is received when received at is set" do subject.received_at = Time.zone.now expect(subject.status).to eq("received") @@ -81,13 +70,17 @@ describe "#review_status" do it "is accepted when passed is true" do - subject.review_passed = true - expect(subject.review_status).to eq("accepted") + if subject.respond_to?(:review_passed) + subject.review_passed = true + expect(subject.review_status).to eq("accepted") + end end it "is rejected when passed is false" do - subject.review_passed = false - expect(subject.review_status).to eq("rejected") + if subject.respond_to?(:review_passed) + subject.review_passed = false + expect(subject.review_status).to eq("rejected") + end end it "is not started if not reviewed" do @@ -96,6 +89,20 @@ end describe "#verify_status" do + it "is accepted when passed is true" do + if subject.respond_to?(:verify_passed) + subject.verify_passed = true + expect(subject.verify_status).to eq("accepted") + end + end + + it "is rejected when passed is false" do + if subject.respond_to?(:verify_passed) + subject.verify_passed = false + expect(subject.verify_status).to eq("rejected") + end + end + it "is not started if not verified" do expect(subject.verify_status).to eq("not_started") end From b0777e4490b6aadcb6c5f9b74cc59bd8ca7d4e97 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Fri, 23 Feb 2024 08:30:18 +0100 Subject: [PATCH 2/3] Remove consent fields from QualificationRequests These are being replaced by the consent requests table so we can remove these fields. --- app/models/consent_request.rb | 27 +++++ app/models/qualification_request.rb | 69 +++--------- config/analytics.yml | 3 - ...ove_consent_from_qualification_requests.rb | 12 ++ db/schema.rb | 5 +- spec/factories/consent_requests.rb | 27 +++++ spec/factories/qualification_requests.rb | 63 +++-------- spec/models/consent_request_spec.rb | 27 +++++ spec/models/qualification_request_spec.rb | 106 +++--------------- 9 files changed, 144 insertions(+), 195 deletions(-) create mode 100644 db/migrate/20240223071958_remove_consent_from_qualification_requests.rb diff --git a/app/models/consent_request.rb b/app/models/consent_request.rb index 32ff570021..bc2fd40dcf 100644 --- a/app/models/consent_request.rb +++ b/app/models/consent_request.rb @@ -1,5 +1,32 @@ # frozen_string_literal: true +# == Schema Information +# +# Table name: consent_requests +# +# id :bigint not null, primary key +# expired_at :datetime +# received_at :datetime +# requested_at :datetime +# unsigned_document_downloaded :boolean default(FALSE), not null +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null +# +# Indexes +# +# index_consent_requests_on_assessment_id (assessment_id) +# index_consent_requests_on_qualification_id (qualification_id) +# +# Foreign Keys +# +# fk_rails_... (assessment_id => assessments.id) +# fk_rails_... (qualification_id => qualifications.id) +# class ConsentRequest < ApplicationRecord ATTACHABLE_DOCUMENT_TYPES = %w[signed_consent unsigned_consent].freeze diff --git a/app/models/qualification_request.rb b/app/models/qualification_request.rb index fc32ba8ca5..3bc858577a 100644 --- a/app/models/qualification_request.rb +++ b/app/models/qualification_request.rb @@ -4,25 +4,22 @@ # # Table name: qualification_requests # -# id :bigint not null, primary key -# consent_method :string default("unknown"), not null -# consent_received_at :datetime -# consent_requested_at :datetime -# expired_at :datetime -# location_note :text default(""), not null -# received_at :datetime -# requested_at :datetime -# review_note :string default(""), not null -# review_passed :boolean -# reviewed_at :datetime -# unsigned_consent_document_downloaded :boolean default(FALSE), not null -# verified_at :datetime -# verify_note :text default(""), not null -# verify_passed :boolean -# created_at :datetime not null -# updated_at :datetime not null -# assessment_id :bigint not null -# qualification_id :bigint not null +# id :bigint not null, primary key +# consent_method :string default("unknown"), not null +# expired_at :datetime +# location_note :text default(""), not null +# received_at :datetime +# requested_at :datetime +# review_note :string default(""), not null +# review_passed :boolean +# reviewed_at :datetime +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null # # Indexes # @@ -35,9 +32,6 @@ # fk_rails_... (qualification_id => qualifications.id) # class QualificationRequest < ApplicationRecord - ATTACHABLE_DOCUMENT_TYPES = %w[signed_consent unsigned_consent].freeze - - include Documentable include Requestable belongs_to :qualification @@ -50,21 +44,6 @@ class QualificationRequest < ApplicationRecord }, _prefix: true - scope :consent_method_signed, - -> do - consent_method_signed_ecctis.or(consent_method_signed_institution) - end - - scope :consent_requested, -> { where.not(consent_requested_at: nil) } - scope :consent_received, -> { where.not(consent_received_at: nil) } - scope :consent_respondable, - -> do - consent_requested - .where(consent_received_at: nil) - .joins(assessment: :application_form) - .merge(ApplicationForm.assessable) - end - scope :order_by_role, -> { joins(:qualification).order("qualifications.start_date": :desc) } scope :order_by_user, @@ -77,20 +56,4 @@ def expires_after def consent_method_signed? consent_method_signed_ecctis? || consent_method_signed_institution? end - - def consent_requested! - update!(consent_requested_at: Time.zone.now) - end - - def consent_requested? - consent_requested_at != nil - end - - def consent_received! - update!(consent_received_at: Time.zone.now) - end - - def consent_received? - consent_received_at != nil - end end diff --git a/config/analytics.yml b/config/analytics.yml index b61e96c43e..7a3a3d7115 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -223,8 +223,6 @@ :qualification_requests: - assessment_id - consent_method - - consent_received_at - - consent_requested_at - created_at - expired_at - id @@ -235,7 +233,6 @@ - review_note - review_passed - reviewed_at - - unsigned_consent_document_downloaded - updated_at - verified_at - verify_note diff --git a/db/migrate/20240223071958_remove_consent_from_qualification_requests.rb b/db/migrate/20240223071958_remove_consent_from_qualification_requests.rb new file mode 100644 index 0000000000..c5167167ac --- /dev/null +++ b/db/migrate/20240223071958_remove_consent_from_qualification_requests.rb @@ -0,0 +1,12 @@ +class RemoveConsentFromQualificationRequests < ActiveRecord::Migration[7.1] + def change + change_table :qualification_requests, bulk: true do |t| + t.remove :consent_received_at, type: :datetime + t.remove :consent_requested_at, type: :datetime + t.remove :unsigned_consent_document_downloaded, + type: :boolean, + default: false, + null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 7c8538ae8c..9eb15d7fc1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_23_065851) do +ActiveRecord::Schema[7.1].define(version: 2024_02_23_071958) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -307,9 +307,6 @@ t.boolean "verify_passed" t.text "verify_note", default: "", null: false t.datetime "verified_at" - t.boolean "unsigned_consent_document_downloaded", default: false, null: false - t.datetime "consent_received_at" - t.datetime "consent_requested_at" t.string "consent_method", default: "unknown", null: false t.index ["assessment_id"], name: "index_qualification_requests_on_assessment_id" t.index ["qualification_id"], name: "index_qualification_requests_on_qualification_id" diff --git a/spec/factories/consent_requests.rb b/spec/factories/consent_requests.rb index c41b6017fe..be30784cfb 100644 --- a/spec/factories/consent_requests.rb +++ b/spec/factories/consent_requests.rb @@ -1,5 +1,32 @@ # frozen_string_literal: true +# == Schema Information +# +# Table name: consent_requests +# +# id :bigint not null, primary key +# expired_at :datetime +# received_at :datetime +# requested_at :datetime +# unsigned_document_downloaded :boolean default(FALSE), not null +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null +# +# Indexes +# +# index_consent_requests_on_assessment_id (assessment_id) +# index_consent_requests_on_qualification_id (qualification_id) +# +# Foreign Keys +# +# fk_rails_... (assessment_id => assessments.id) +# fk_rails_... (qualification_id => qualifications.id) +# FactoryBot.define do factory :consent_request do association :assessment diff --git a/spec/factories/qualification_requests.rb b/spec/factories/qualification_requests.rb index 067f2b5d2b..a2202af505 100644 --- a/spec/factories/qualification_requests.rb +++ b/spec/factories/qualification_requests.rb @@ -4,25 +4,22 @@ # # Table name: qualification_requests # -# id :bigint not null, primary key -# consent_method :string default("unknown"), not null -# consent_received_at :datetime -# consent_requested_at :datetime -# expired_at :datetime -# location_note :text default(""), not null -# received_at :datetime -# requested_at :datetime -# review_note :string default(""), not null -# review_passed :boolean -# reviewed_at :datetime -# unsigned_consent_document_downloaded :boolean default(FALSE), not null -# verified_at :datetime -# verify_note :text default(""), not null -# verify_passed :boolean -# created_at :datetime not null -# updated_at :datetime not null -# assessment_id :bigint not null -# qualification_id :bigint not null +# id :bigint not null, primary key +# consent_method :string default("unknown"), not null +# expired_at :datetime +# location_note :text default(""), not null +# received_at :datetime +# requested_at :datetime +# review_note :string default(""), not null +# review_passed :boolean +# reviewed_at :datetime +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null # # Indexes # @@ -39,34 +36,8 @@ association :assessment association :qualification, :completed - trait :consent_required do + trait :consent_method_signed do consent_method { %i[signed_ecctis signed_institution].sample } - - after(:create) do |qualification_request, _evaluator| - create( - :upload, - document: qualification_request.unsigned_consent_document, - ) - end - end - - trait :consent_requested do - consent_required - consent_requested_at do - Faker::Time.between(from: 1.month.ago, to: Time.zone.now) - end - end - - trait :consent_received do - consent_requested - consent_received_at do - Faker::Time.between(from: 1.month.ago, to: Time.zone.now) - end - end - - trait :consent_expired do - consent_requested - expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end trait :requested do diff --git a/spec/models/consent_request_spec.rb b/spec/models/consent_request_spec.rb index ee3a0abdb5..cae5cab76e 100644 --- a/spec/models/consent_request_spec.rb +++ b/spec/models/consent_request_spec.rb @@ -1,5 +1,32 @@ # frozen_string_literal: true +# == Schema Information +# +# Table name: consent_requests +# +# id :bigint not null, primary key +# expired_at :datetime +# received_at :datetime +# requested_at :datetime +# unsigned_document_downloaded :boolean default(FALSE), not null +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null +# +# Indexes +# +# index_consent_requests_on_assessment_id (assessment_id) +# index_consent_requests_on_qualification_id (qualification_id) +# +# Foreign Keys +# +# fk_rails_... (assessment_id => assessments.id) +# fk_rails_... (qualification_id => qualifications.id) +# require "rails_helper" RSpec.describe ConsentRequest, type: :model do diff --git a/spec/models/qualification_request_spec.rb b/spec/models/qualification_request_spec.rb index e99ae97e22..fc4de5ed04 100644 --- a/spec/models/qualification_request_spec.rb +++ b/spec/models/qualification_request_spec.rb @@ -4,25 +4,22 @@ # # Table name: qualification_requests # -# id :bigint not null, primary key -# consent_method :string default("unknown"), not null -# consent_received_at :datetime -# consent_requested_at :datetime -# expired_at :datetime -# location_note :text default(""), not null -# received_at :datetime -# requested_at :datetime -# review_note :string default(""), not null -# review_passed :boolean -# reviewed_at :datetime -# unsigned_consent_document_downloaded :boolean default(FALSE), not null -# verified_at :datetime -# verify_note :text default(""), not null -# verify_passed :boolean -# created_at :datetime not null -# updated_at :datetime not null -# assessment_id :bigint not null -# qualification_id :bigint not null +# id :bigint not null, primary key +# consent_method :string default("unknown"), not null +# expired_at :datetime +# location_note :text default(""), not null +# received_at :datetime +# requested_at :datetime +# review_note :string default(""), not null +# review_passed :boolean +# reviewed_at :datetime +# verified_at :datetime +# verify_note :text default(""), not null +# verify_passed :boolean +# created_at :datetime not null +# updated_at :datetime not null +# assessment_id :bigint not null +# qualification_id :bigint not null # # Indexes # @@ -39,8 +36,6 @@ RSpec.describe QualificationRequest, type: :model do subject(:qualification_request) { create(:qualification_request) } - it_behaves_like "a documentable" - it_behaves_like "a requestable" do subject { create(:qualification_request, :receivable) } end @@ -60,9 +55,6 @@ end describe "validations" do - it { is_expected.to_not validate_presence_of(:consent_requested_at) } - it { is_expected.to_not validate_presence_of(:consent_received_at) } - context "when received" do subject { build(:qualification_request, :received) } @@ -70,72 +62,8 @@ end end - describe "#expires_from" do - subject(:expires_from) { qualification_request.expires_from } - - context "when consent has been requested" do - let(:qualification_request) do - create( - :qualification_request, - consent_requested_at: Date.new(2020, 1, 1), - ) - end - - it { is_expected.to eq(Date.new(2020, 1, 1)) } - end - - context "when verification has been requested" do - let(:qualification_request) do - create( - :qualification_request, - consent_requested_at: Date.new(2020, 1, 1), - requested_at: Date.new(2021, 1, 1), - ) - end - - it { is_expected.to eq(Date.new(2021, 1, 1)) } - end - end - describe "#expires_after" do subject(:expires_after) { qualification_request.expires_after } - - context "when consent has been requested" do - let(:qualification_request) do - create(:qualification_request, :consent_requested) - end - - it { is_expected.to eq(6.weeks) } - end - - context "when verification has been requested" do - let(:qualification_request) { create(:qualification_request, :requested) } - - it { is_expected.to eq(6.weeks) } - end - end - - describe "#consent_requested!" do - let(:call) { subject.consent_requested! } - - it "sets the consent requested at date" do - freeze_time do - expect { call }.to change(subject, :consent_requested_at).from(nil).to( - Time.zone.now, - ) - end - end - end - - describe "#consent_received!" do - let(:call) { subject.consent_received! } - - it "sets the consent received at date" do - freeze_time do - expect { call }.to change(subject, :consent_received_at).from(nil).to( - Time.zone.now, - ) - end - end + it { is_expected.to eq(6.weeks) } end end From b3449314efaeadca56c1acf9fda2d10408ec13c1 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Fri, 23 Feb 2024 09:30:53 +0100 Subject: [PATCH 3/3] Switch to consent requests This refactors all the code related to qualification requests to use consent requests where necessary. --- .../teacher_interface/base_controller.rb | 7 +- .../consent_requests_controller.rb | 75 +++++++++++++ .../qualification_requests_controller.rb | 77 ------------- .../upload_unsigned_consent_document_form.rb | 6 +- ...download_unsigned_consent_document_form.rb | 15 +++ .../qualification_request_download_form.rb | 19 ---- app/lib/application_form_status_updater.rb | 20 ++-- app/lib/document_continue_redirection.rb | 8 +- app/mailers/teacher_mailer.rb | 14 +-- app/models/application_form.rb | 13 ++- app/models/assessment.rb | 4 +- app/models/concerns/expirable.rb | 4 +- app/models/concerns/requestable.rb | 14 +-- app/models/document.rb | 7 +- app/models/timeline_event.rb | 1 + .../qualification_requests_view_object.rb | 37 ++++--- .../application_form_view_object.rb | 14 +-- .../consent_requests_view_object.rb | 92 ++++++++++++++++ .../qualification_requests_view_object.rb | 103 ------------------ .../_request_qualification_consent.html.erb | 2 +- .../check.html.erb | 4 +- .../edit_download.html.erb | 6 +- .../index.html.erb | 2 +- config/locales/components.en.yml | 8 ++ config/locales/teacher_interface.en.yml | 2 +- config/routes.rb | 8 +- lib/tasks/example_data.rake | 7 +- spec/factories/assessments.rb | 10 ++ ...oad_unsigned_consent_document_form_spec.rb | 10 +- ...ad_unsigned_consent_document_form_spec.rb} | 20 ++-- .../lib/document_continue_redirection_spec.rb | 20 +--- spec/mailers/teacher_mailer_spec.rb | 11 +- spec/models/application_form_spec.rb | 12 +- .../services/destroy_application_form_spec.rb | 4 +- ..._requests.rb => check_consent_requests.rb} | 4 +- ...cation_requests.rb => consent_requests.rb} | 4 +- ...ownload.rb => download_consent_request.rb} | 4 +- spec/support/page_helpers.rb | 30 ++--- ...cation_consent_spec.rb => consent_spec.rb} | 63 +++++------ ...qualification_requests_view_object_spec.rb | 12 +- ...b => consent_requests_view_object_spec.rb} | 32 +++--- 41 files changed, 381 insertions(+), 424 deletions(-) create mode 100644 app/controllers/teacher_interface/consent_requests_controller.rb delete mode 100644 app/controllers/teacher_interface/qualification_requests_controller.rb create mode 100644 app/forms/teacher_interface/download_unsigned_consent_document_form.rb delete mode 100644 app/forms/teacher_interface/qualification_request_download_form.rb create mode 100644 app/view_objects/teacher_interface/consent_requests_view_object.rb delete mode 100644 app/view_objects/teacher_interface/qualification_requests_view_object.rb rename app/views/teacher_interface/{qualification_requests => consent_requests}/check.html.erb (89%) rename app/views/teacher_interface/{qualification_requests => consent_requests}/edit_download.html.erb (80%) rename app/views/teacher_interface/{qualification_requests => consent_requests}/index.html.erb (92%) rename spec/forms/teacher_interface/{qualification_request_download_form_spec.rb => download_unsigned_consent_document_form_spec.rb} (51%) rename spec/support/autoload/page_objects/teacher_interface/{check_qualification_requests.rb => check_consent_requests.rb} (66%) rename spec/support/autoload/page_objects/teacher_interface/{qualification_requests.rb => consent_requests.rb} (75%) rename spec/support/autoload/page_objects/teacher_interface/{qualification_request_download.rb => download_consent_request.rb} (71%) rename spec/system/teacher_interface/{qualification_consent_spec.rb => consent_spec.rb} (69%) rename spec/view_objects/teacher_interface/{qualification_requests_view_object_spec.rb => consent_requests_view_object_spec.rb} (80%) diff --git a/app/controllers/teacher_interface/base_controller.rb b/app/controllers/teacher_interface/base_controller.rb index 5a8956c5d6..fda443ac09 100644 --- a/app/controllers/teacher_interface/base_controller.rb +++ b/app/controllers/teacher_interface/base_controller.rb @@ -27,7 +27,7 @@ def document .assessment &.further_information_requests &.flat_map(&:items) || [] - ) + (application_form.assessment&.qualification_requests || []), + ) + (application_form.assessment&.consent_requests || []), ).find(params[:document_id] || params[:id]) end @@ -42,9 +42,8 @@ def redirect_unless_draft_or_additional_information unless document.documentable.further_information_request.requested? redirect_to %i[teacher_interface application_form] end - elsif document.for_qualification_request? - if document.documentable.consent_requested_at.nil? || - document.documentable.consent_received_at.present? + elsif document.for_consent_request? + if !document.documentable.requested? || document.documentable.received? redirect_to %i[teacher_interface application_form] end else diff --git a/app/controllers/teacher_interface/consent_requests_controller.rb b/app/controllers/teacher_interface/consent_requests_controller.rb new file mode 100644 index 0000000000..57c2959793 --- /dev/null +++ b/app/controllers/teacher_interface/consent_requests_controller.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +module TeacherInterface + class ConsentRequestsController < BaseController + include HandleApplicationFormSection + include HistoryTrackable + + before_action :load_consent_request, only: %i[edit_download update_download] + + define_history_check :check + define_history_origin :index + define_history_reset :index + + def index + @view_object = ConsentRequestsViewObject.new(application_form:) + end + + def check + @view_object = ConsentRequestsViewObject.new(application_form:) + end + + def submit + ActiveRecord::Base.transaction do + application_form.assessment.consent_requests.each do |requestable| + ReceiveRequestable.call(requestable:, user: current_teacher) + end + end + + TeacherMailer.with(application_form:).consent_submitted.deliver_later + + redirect_to %i[teacher_interface application_form] + end + + def edit_download + @form = + DownloadUnsignedConsentDocumentForm.new( + consent_request:, + downloaded: consent_request.unsigned_document_downloaded, + ) + end + + def update_download + @form = + DownloadUnsignedConsentDocumentForm.new( + consent_request:, + downloaded: + params.dig( + :teacher_interface_download_unsigned_consent_document_form, + :downloaded, + ), + ) + + handle_application_form_section( + form: @form, + if_success_then_redirect: + teacher_interface_application_form_consent_requests_path, + if_failure_then_render: :edit_download, + ) + end + + private + + attr_reader :consent_request + + def load_consent_request + @consent_request = + ConsentRequest + .joins(assessment: :application_form) + .includes(:qualification, :application_form) + .find_by!(id: params[:id], assessment: { application_form: }) + + @qualification = consent_request.qualification + end + end +end diff --git a/app/controllers/teacher_interface/qualification_requests_controller.rb b/app/controllers/teacher_interface/qualification_requests_controller.rb deleted file mode 100644 index e2d311e2cd..0000000000 --- a/app/controllers/teacher_interface/qualification_requests_controller.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -module TeacherInterface - class QualificationRequestsController < BaseController - include HandleApplicationFormSection - include HistoryTrackable - - before_action :load_qualification_request, - only: %i[edit_download update_download] - - define_history_origin :index - define_history_reset :index - - def index - @view_object = QualificationRequestsViewObject.new(application_form:) - end - - def check - @view_object = QualificationRequestsViewObject.new(application_form:) - end - - def submit - @qualification_requests ||= - application_form - .assessment - .qualification_requests - .consent_respondable - .update_all(consent_received_at: Time.zone.now) - - TeacherMailer.with(application_form:).consent_submitted.deliver_later - - redirect_to %i[teacher_interface application_form] - end - - def edit_download - @form = - QualificationRequestDownloadForm.new( - qualification_request:, - downloaded: - qualification_request.unsigned_consent_document_downloaded, - ) - end - - def update_download - @form = - QualificationRequestDownloadForm.new( - qualification_request:, - downloaded: - params.dig( - :teacher_interface_qualification_request_download_form, - :downloaded, - ), - ) - - handle_application_form_section( - form: @form, - if_success_then_redirect: - teacher_interface_application_form_qualification_requests_path, - if_failure_then_render: :edit_download, - ) - end - - private - - attr_reader :qualification_request - - def load_qualification_request - @qualification_request = - QualificationRequest - .joins(assessment: :application_form) - .includes(:qualification, :application_form) - .find_by!(id: params[:id], assessment: { application_form: }) - - @qualification = qualification_request.qualification - end - end -end diff --git a/app/forms/assessor_interface/upload_unsigned_consent_document_form.rb b/app/forms/assessor_interface/upload_unsigned_consent_document_form.rb index 87612b8e16..d8e01513ae 100644 --- a/app/forms/assessor_interface/upload_unsigned_consent_document_form.rb +++ b/app/forms/assessor_interface/upload_unsigned_consent_document_form.rb @@ -5,8 +5,8 @@ class AssessorInterface::UploadUnsignedConsentDocumentForm include ActiveModel::Attributes include UploadableForm - attr_accessor :qualification_request - validates :qualification_request, presence: true + attr_accessor :consent_request + validates :consent_request, presence: true def save return false if invalid? @@ -17,6 +17,6 @@ def save end def document - qualification_request&.unsigned_consent_document + consent_request&.unsigned_consent_document end end diff --git a/app/forms/teacher_interface/download_unsigned_consent_document_form.rb b/app/forms/teacher_interface/download_unsigned_consent_document_form.rb new file mode 100644 index 0000000000..ca4798bc8e --- /dev/null +++ b/app/forms/teacher_interface/download_unsigned_consent_document_form.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module TeacherInterface + class DownloadUnsignedConsentDocumentForm < BaseForm + attr_accessor :consent_request + attribute :downloaded, :boolean + + validates :consent_request, presence: true + validates :downloaded, presence: true + + def update_model + consent_request.update!(unsigned_document_downloaded: true) if downloaded + end + end +end diff --git a/app/forms/teacher_interface/qualification_request_download_form.rb b/app/forms/teacher_interface/qualification_request_download_form.rb deleted file mode 100644 index 656dc2b157..0000000000 --- a/app/forms/teacher_interface/qualification_request_download_form.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module TeacherInterface - class QualificationRequestDownloadForm < BaseForm - attr_accessor :qualification_request - attribute :downloaded, :boolean - - validates :qualification_request, presence: true - validates :downloaded, presence: true - - def update_model - if downloaded - qualification_request.update!( - unsigned_consent_document_downloaded: true, - ) - end - end - end -end diff --git a/app/lib/application_form_status_updater.rb b/app/lib/application_form_status_updater.rb index ab966585bd..c1a5964d78 100644 --- a/app/lib/application_form_status_updater.rb +++ b/app/lib/application_form_status_updater.rb @@ -172,7 +172,7 @@ def requestable_statuses end def overdue_consent - overdue?(requestables: qualification_requests.reject(&:requested?)) + overdue?(requestables: consent_requests) end def overdue_further_information @@ -193,12 +193,7 @@ def overdue_reference end def received_consent - qualification_requests - .reject(&:verified?) - .reject(&:reviewed?) - .reject(&:expired?) - .reject(&:requested?) - .any?(&:consent_received?) + received?(requestables: consent_requests) end def received_further_information @@ -239,12 +234,7 @@ def received_reference end def waiting_on_consent - qualification_requests - .reject(&:verified?) - .reject(&:reviewed?) - .reject(&:expired?) - .reject(&:consent_received?) - .any?(&:consent_requested?) + waiting_on?(requestables: consent_requests) end def waiting_on_further_information @@ -263,6 +253,10 @@ def waiting_on_reference waiting_on?(requestables: reference_requests) end + def consent_requests + @consent_requests ||= assessment&.consent_requests.to_a + end + def further_information_requests @further_information_requests ||= assessment&.further_information_requests.to_a diff --git a/app/lib/document_continue_redirection.rb b/app/lib/document_continue_redirection.rb index bd3287fdf6..459b735ae3 100644 --- a/app/lib/document_continue_redirection.rb +++ b/app/lib/document_continue_redirection.rb @@ -10,8 +10,8 @@ def initialize(document:) def call if document.for_further_information_request? further_information_request_url - elsif document.for_qualification_request? - qualification_request_url + elsif document.for_consent_request? + consent_request_url else send("#{document.document_type}_url") end @@ -68,7 +68,7 @@ def further_information_request_url ] end - def qualification_request_url - %i[teacher_interface application_form qualification_requests] + def consent_request_url + %i[teacher_interface application_form consent_requests] end end diff --git a/app/mailers/teacher_mailer.rb b/app/mailers/teacher_mailer.rb index 16129261da..f0040275f7 100644 --- a/app/mailers/teacher_mailer.rb +++ b/app/mailers/teacher_mailer.rb @@ -57,12 +57,7 @@ def application_received end def consent_reminder - @expires_at = - assessment - .qualification_requests - .consent_method_signed - .map(&:expires_at) - .max + @expires_at = assessment.consent_requests.map(&:expires_at).max view_mail( GOVUK_NOTIFY_TEMPLATE_ID, @@ -72,12 +67,7 @@ def consent_reminder end def consent_requested - @expires_at = - assessment - .qualification_requests - .consent_method_signed - .map(&:expires_at) - .max + @expires_at = assessment.consent_requests.map(&:expires_at).max view_mail( GOVUK_NOTIFY_TEMPLATE_ID, diff --git a/app/models/application_form.rb b/app/models/application_form.rb index c64a0cb994..86a1090838 100644 --- a/app/models/application_form.rb +++ b/app/models/application_form.rb @@ -256,8 +256,8 @@ def should_send_reminder_email?(name, number_of_reminders_sent) case name when "consent" number_of_reminders_sent.zero? && - consent_requests_not_yet_received.any? do |qualification_request| - qualification_request.days_until_expired <= 21 + consent_requests_not_yet_received_or_rejected.any? do |consent_request| + consent_request.days_until_expired <= 21 end when "expiration" return false if days_until_expired.nil? @@ -296,7 +296,7 @@ def send_reminder_email(name, number_of_reminders_sent) end end - def expires_from + def requested_at created_at end @@ -314,10 +314,11 @@ def reference_requests_not_yet_received_or_rejected .where(received_at: nil, verify_passed: nil, review_passed: nil) end - def consent_requests_not_yet_received - QualificationRequest + def consent_requests_not_yet_received_or_rejected + ConsentRequest .joins(:qualification) .where(qualifications: { application_form_id: id }) - .consent_respondable + .where.not(requested_at: nil) + .where(received_at: nil, verify_passed: nil) end end diff --git a/app/models/assessment.rb b/app/models/assessment.rb index d021178497..79e0161c1e 100644 --- a/app/models/assessment.rb +++ b/app/models/assessment.rb @@ -37,10 +37,12 @@ class Assessment < ApplicationRecord belongs_to :application_form has_many :sections, class_name: "AssessmentSection", dependent: :destroy + + has_many :consent_requests, dependent: :destroy has_many :further_information_requests, dependent: :destroy has_one :professional_standing_request, dependent: :destroy, required: false - has_many :reference_requests, dependent: :destroy has_many :qualification_requests, dependent: :destroy + has_many :reference_requests, dependent: :destroy enum :recommendation, { diff --git a/app/models/concerns/expirable.rb b/app/models/concerns/expirable.rb index 93ae7f4886..6b6fa64280 100644 --- a/app/models/concerns/expirable.rb +++ b/app/models/concerns/expirable.rb @@ -4,9 +4,9 @@ module Expirable extend ActiveSupport::Concern def expires_at - return nil if expires_from.nil? || expires_after.nil? + return nil if requested_at.nil? || expires_after.nil? - expires_from + expires_after + requested_at + expires_after end def days_until_expired diff --git a/app/models/concerns/requestable.rb b/app/models/concerns/requestable.rb index 75e7bc139a..0afab4020a 100644 --- a/app/models/concerns/requestable.rb +++ b/app/models/concerns/requestable.rb @@ -10,18 +10,14 @@ module Requestable scope :requested, -> { where.not(requested_at: nil) } scope :received, -> { where.not(received_at: nil) } + scope :not_received, -> { where(received_at: nil) } scope :respondable, - -> do - requested.where(received_at: nil).merge(ApplicationForm.assessable) - end + -> { requested.not_received.merge(ApplicationForm.assessable) } + scope :verified, -> { where.not(verified_at: nil) } has_one :application_form, through: :assessment end - def expires_from - requested_at || try(:consent_requested_at) - end - def requested! update!(requested_at: Time.zone.now) end @@ -62,7 +58,7 @@ def verify_failed? try(:verify_passed) == false end - def status + def status(not_requested: "not_started") if review_passed? || review_failed? review_status elsif verify_passed? @@ -78,7 +74,7 @@ def status elsif requested? "waiting_on" else - "not_started" + not_requested end end diff --git a/app/models/document.rb b/app/models/document.rb index d7ff699243..2c1230c3fc 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -68,16 +68,15 @@ def allow_multiple_uploads? end def optional? - (signed_consent? && !documentable.consent_method_signed?) || - (written_statement? && application_form.written_statement_optional) + written_statement? && application_form.written_statement_optional end def for_further_information_request? documentable.is_a?(FurtherInformationRequestItem) end - def for_qualification_request? - documentable.is_a?(QualificationRequest) + def for_consent_request? + documentable.is_a?(ConsentRequest) end def application_form diff --git a/app/models/timeline_event.rb b/app/models/timeline_event.rb index decfcee80b..0a46250669 100644 --- a/app/models/timeline_event.rb +++ b/app/models/timeline_event.rb @@ -131,6 +131,7 @@ class TimelineEvent < ApplicationRecord validates :requestable_type, presence: true, inclusion: %w[ + ConsentRequest FurtherInformationRequest ProfessionalStandingRequest QualificationRequest diff --git a/app/view_objects/assessor_interface/qualification_requests_view_object.rb b/app/view_objects/assessor_interface/qualification_requests_view_object.rb index 63ed1843ea..84829c89ed 100644 --- a/app/view_objects/assessor_interface/qualification_requests_view_object.rb +++ b/app/view_objects/assessor_interface/qualification_requests_view_object.rb @@ -38,6 +38,11 @@ def qualification_requests application_form.assessment.qualification_requests.order_by_role end + def consent_requests + @consent_requests ||= + application_form.assessment.consent_requests.order_by_role + end + def individual_task_items_for(qualification_request:) return [] if qualification_request.consent_method_unknown? @@ -106,8 +111,7 @@ def unsigned_consent_method_task_items(_qualification_request) end def send_consent_document_in_all_qualifications? - all_consent_methods_selected? && - qualification_requests.consent_method_signed.count >= 2 + all_consent_methods_selected? && consent_requests.count >= 2 end def send_consent_document_task_item @@ -115,14 +119,10 @@ def send_consent_document_task_item name: "Send consent document to applicant", link: "#", status: - if qualification_requests.map(&:unsigned_consent_document).all?( + if consent_requests.map(&:unsigned_consent_document).all?( &:completed? ) - if qualification_requests.all(&:consent_requested?) - "completed" - else - "not_started" - end + consent_requests.all?(&:requested?) ? "completed" : "not_started" else "cannot_start" end, @@ -130,13 +130,18 @@ def send_consent_document_task_item end def signed_consent_method_task_items(qualification_request) + consent_request = + consent_requests.find_by!( + qualification: qualification_request.qualification, + ) + [ { name: "Upload consent document", link: "#", status: ( - if qualification_request.unsigned_consent_document.completed? + if consent_request.unsigned_consent_document.completed? "completed" else "not_started" @@ -149,14 +154,7 @@ def signed_consent_method_task_items(qualification_request) { name: "Record applicant response", link: "#", - status: - if qualification_request.consent_received? - "completed" - elsif qualification_request.consent_requested? - "not_started" - else - "cannot_start" - end, + status: consent_request.status(not_requested: "cannot_start"), }, ] end @@ -166,7 +164,10 @@ def ecctis_task_items(qualification_request) ( qualification_request.consent_method_unsigned? && assessment.unsigned_consent_document_generated - ) || qualification_request.consent_received? + ) || + consent_requests.verified.exists?( + qualification: qualification_request.qualification, + ) [ { diff --git a/app/view_objects/teacher_interface/application_form_view_object.rb b/app/view_objects/teacher_interface/application_form_view_object.rb index 8ed849452f..5badcfd6f0 100644 --- a/app/view_objects/teacher_interface/application_form_view_object.rb +++ b/app/view_objects/teacher_interface/application_form_view_object.rb @@ -149,18 +149,13 @@ def request_professional_standing_certificate? def request_qualification_consent? return false if assessment.nil? - qualification_requests.consent_respondable.exists? + consent_requests.requested.not_received.exists? end def qualification_consent_submitted? - return false if assessment.nil? - - required_qualification_requests = - qualification_requests.consent_method_signed - - return false if required_qualification_requests.empty? + return false if assessment.nil? || consent_requests.empty? - required_qualification_requests.all?(&:consent_received?) + consent_requests.all?(&:received?) end def show_work_history_under_submission_banner? @@ -182,7 +177,8 @@ def show_work_history_under_induction_banner? :requires_preliminary_check, to: :application_form - delegate :professional_standing_request, + delegate :consent_requests, + :professional_standing_request, :qualification_requests, to: :assessment, allow_nil: true diff --git a/app/view_objects/teacher_interface/consent_requests_view_object.rb b/app/view_objects/teacher_interface/consent_requests_view_object.rb new file mode 100644 index 0000000000..eeef5942a4 --- /dev/null +++ b/app/view_objects/teacher_interface/consent_requests_view_object.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +module TeacherInterface + class ConsentRequestsViewObject + include QualificationHelper + + def initialize(application_form:) + @application_form = application_form + end + + def task_list_sections + consent_requests.map do |consent_request| + { + title: qualification_title(consent_request.qualification), + items: task_list_items(consent_request), + } + end + end + + def can_submit? + consent_requests.all? do |consent_request| + consent_request.unsigned_document_downloaded && + consent_request.signed_consent_document.completed? + end + end + + def check_your_answers_fields + consent_requests.each_with_object({}) do |consent_request, memo| + memo[consent_request.id] = { + title: qualification_title(consent_request.qualification), + value: consent_request.signed_consent_document, + href: [ + :teacher_interface, + :application_form, + consent_request.signed_consent_document, + ], + } + end + end + + private + + attr_reader :application_form + + def consent_requests + @consent_requests ||= + application_form.assessment.consent_requests.requested.order_by_user + end + + def task_list_items(consent_request) + institution_name = consent_request.qualification.institution_name + + [ + { + link: [ + :download, + :teacher_interface, + :application_form, + consent_request, + ], + name: "Download #{institution_name} consent document", + status: download_unsigned_consent_document_status(consent_request), + }, + { + link: [ + :teacher_interface, + :application_form, + consent_request.signed_consent_document, + ], + name: "Upload #{institution_name} consent document", + status: upload_signed_consent_document_status(consent_request), + }, + ] + end + + def download_unsigned_consent_document_status(consent_request) + consent_request.unsigned_document_downloaded ? :completed : :not_started + end + + def upload_signed_consent_document_status(consent_request) + if consent_request.unsigned_document_downloaded + if consent_request.signed_consent_document.completed? + :completed + else + :not_started + end + else + :cannot_start + end + end + end +end diff --git a/app/view_objects/teacher_interface/qualification_requests_view_object.rb b/app/view_objects/teacher_interface/qualification_requests_view_object.rb deleted file mode 100644 index c781843214..0000000000 --- a/app/view_objects/teacher_interface/qualification_requests_view_object.rb +++ /dev/null @@ -1,103 +0,0 @@ -# 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 - - def can_submit? - qualification_requests.all? do |qualification_request| - qualification_request.unsigned_consent_document_downloaded && - qualification_request.signed_consent_document.completed? - end - end - - def check_your_answers_fields - qualification_requests.each_with_object( - {}, - ) do |qualification_request, memo| - memo[qualification_request.id] = { - title: qualification_title(qualification_request.qualification), - value: qualification_request.signed_consent_document, - href: [ - :teacher_interface, - :application_form, - qualification_request.signed_consent_document, - ], - } - 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 diff --git a/app/views/teacher_interface/application_forms/show/_request_qualification_consent.html.erb b/app/views/teacher_interface/application_forms/show/_request_qualification_consent.html.erb index 624207f747..7024f927d7 100644 --- a/app/views/teacher_interface/application_forms/show/_request_qualification_consent.html.erb +++ b/app/views/teacher_interface/application_forms/show/_request_qualification_consent.html.erb @@ -15,4 +15,4 @@
  • upload the signed document
  • -<%= govuk_start_button(text: "Start now", href: %i[teacher_interface application_form qualification_requests]) %> +<%= govuk_start_button(text: "Start now", href: %i[teacher_interface application_form consent_requests]) %> diff --git a/app/views/teacher_interface/qualification_requests/check.html.erb b/app/views/teacher_interface/consent_requests/check.html.erb similarity index 89% rename from app/views/teacher_interface/qualification_requests/check.html.erb rename to app/views/teacher_interface/consent_requests/check.html.erb index 2b28dc4865..9d16f447db 100644 --- a/app/views/teacher_interface/qualification_requests/check.html.erb +++ b/app/views/teacher_interface/consent_requests/check.html.erb @@ -1,5 +1,5 @@ <% content_for :page_title, "Check your uploaded consent documents" %> -<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_qualification_requests_path) %> +<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_consent_requests_path) %>

    Check your uploaded consent documents

    @@ -14,5 +14,5 @@

    Submit your consent documents

    By selecting the ‘Submit’ button you confirm that, to the best of your knowledge, the details you’ve provided are correct.

    You will not be able to change your response, add new documents, or delete anything once you submit.

    - <%= govuk_button_to "Submit", submit_teacher_interface_application_form_qualification_requests_path %> + <%= govuk_button_to "Submit", submit_teacher_interface_application_form_consent_requests_path %> <% end %> diff --git a/app/views/teacher_interface/qualification_requests/edit_download.html.erb b/app/views/teacher_interface/consent_requests/edit_download.html.erb similarity index 80% rename from app/views/teacher_interface/qualification_requests/edit_download.html.erb rename to app/views/teacher_interface/consent_requests/edit_download.html.erb index b059fc3aed..87dda315c2 100644 --- a/app/views/teacher_interface/qualification_requests/edit_download.html.erb +++ b/app/views/teacher_interface/consent_requests/edit_download.html.erb @@ -1,7 +1,7 @@ <% content_for :page_title, "Download consent document" %> -<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_qualification_requests_path) %> +<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_consent_requests_path) %> -<%= form_with model: @form, url: [:download, :teacher_interface, :application_form, @qualification_request] do |f| %> +<%= form_with model: @form, url: [:download, :teacher_interface, :application_form, @consent_request] do |f| %> <%= f.govuk_error_summary %>

    Download consent document

    @@ -11,7 +11,7 @@

    Download the consent document

    -

    <%= document_link_to(@qualification_request.unsigned_consent_document) %>

    +

    <%= document_link_to(@consent_request.unsigned_consent_document) %>

    diff --git a/app/views/teacher_interface/qualification_requests/index.html.erb b/app/views/teacher_interface/consent_requests/index.html.erb similarity index 92% rename from app/views/teacher_interface/qualification_requests/index.html.erb rename to app/views/teacher_interface/consent_requests/index.html.erb index 96cc62cd37..ea06d5a73e 100644 --- a/app/views/teacher_interface/qualification_requests/index.html.erb +++ b/app/views/teacher_interface/consent_requests/index.html.erb @@ -7,7 +7,7 @@
    <% if @view_object.can_submit? %> - <%= govuk_button_link_to "Continue", check_teacher_interface_application_form_qualification_requests_path %> + <%= govuk_button_link_to "Continue", check_teacher_interface_application_form_consent_requests_path %> <% end %> <%= govuk_button_link_to t("teacher_interface.application_forms.show.draft.save"), destroy_teacher_session_path, secondary: true %> diff --git a/config/locales/components.en.yml b/config/locales/components.en.yml index 2ddb621875..40925f8167 100644 --- a/config/locales/components.en.yml +++ b/config/locales/components.en.yml @@ -63,26 +63,31 @@ en: note_created: Note created reviewer_assigned: Reviewer assigned requestable_requested: + ConsentRequest: Consent requested FurtherInformationRequest: Further information requested ProfessionalStandingRequest: Professional standing requested QualificationRequest: Qualification requested ReferenceRequest: Reference requested requestable_received: + ConsentRequest: Consent received FurtherInformationRequest: Further information received ProfessionalStandingRequest: Professional standing received QualificationRequest: Qualification received ReferenceRequest: Reference received requestable_expired: + ConsentRequest: Consent expired FurtherInformationRequest: Further information expired ProfessionalStandingRequest: Professional standing expired QualificationRequest: Qualification expired ReferenceRequest: Reference expired requestable_reviewed: + ConsentRequest: Consent reviewed FurtherInformationRequest: Further information assessed ProfessionalStandingRequest: Professional standing reviewed QualificationRequest: Qualification reviewed ReferenceRequest: Reference reviewed requestable_verified: + ConsentRequest: Consent verified FurtherInformationRequest: Further information verified ProfessionalStandingRequest: Professional standing verified QualificationRequest: Qualification verified @@ -96,16 +101,19 @@ en: note_created: "%{text}" reviewer_assigned: "%{assignee_name} is assigned as the reviewer." requestable_requested: + ConsentRequest: Consent has been requested. FurtherInformationRequest: Further information has been requested. ProfessionalStandingRequest: The professional standing has been requested. QualificationRequest: A qualification has been requested. ReferenceRequest: A reference has been requested. requestable_received: + ConsentRequest: A consent request has been received. FurtherInformationRequest: Further information requested on %{requested_at} has been received. ProfessionalStandingRequest: "The professional standing has been received: %{location_note}" QualificationRequest: A qualification has been received. ReferenceRequest: A reference has been received. requestable_expired: + ConsentRequest: A consent request has expired. FurtherInformationRequest: Further information requested on %{requested_at} has expired. Application has been declined. ProfessionalStandingRequest: The professional standing request has expired. QualificationRequest: A qualification request has expired. diff --git a/config/locales/teacher_interface.en.yml b/config/locales/teacher_interface.en.yml index a562ccaa5d..8a3c6d3f5f 100644 --- a/config/locales/teacher_interface.en.yml +++ b/config/locales/teacher_interface.en.yml @@ -300,7 +300,7 @@ en: invalid: Enter the certificate date in the format 27 3 1980 future: Certificate date must be in the past comparison: Certificate date must be after completion date - teacher_interface/qualification_request_download_form: + teacher_interface/download_unsigned_consent_document_form: attributes: downloaded: blank: Confirm that you have downloaded the consent document. diff --git a/config/routes.rb b/config/routes.rb index 8ed78b5f95..b4397b8042 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -348,12 +348,10 @@ only: %i[edit update] end - resources :qualification_requests, - path: "/qualification-requests", - only: %i[index] do + resources :consent_requests, path: "/consent-requests", only: %i[index] do member do - get "download", to: "qualification_requests#edit_download" - post "download", to: "qualification_requests#update_download" + get "download", to: "consent_requests#edit_download" + post "download", to: "consent_requests#update_download" end collection do diff --git a/lib/tasks/example_data.rake b/lib/tasks/example_data.rake index bd8357fc0f..08f1369b62 100644 --- a/lib/tasks/example_data.rake +++ b/lib/tasks/example_data.rake @@ -30,6 +30,7 @@ namespace :example_data do TimelineEvent.delete_all DQTTRNRequest.delete_all ReminderEmail.delete_all + ConsentRequest.delete_all FurtherInformationRequestItem.delete_all FurtherInformationRequest.delete_all ProfessionalStandingRequest.delete_all @@ -182,10 +183,14 @@ def create_requestables(application_form, assessment, state) qualifications.each do |qualification| FactoryBot.create( :qualification_request, - [state, "consent_#{state}"].sample, + state, assessment:, qualification:, ) + + next unless rand(2).zero? + + FactoryBot.create(:consent_request, state, assessment:, qualification:) end assessment.verify! diff --git a/spec/factories/assessments.rb b/spec/factories/assessments.rb index ac4c00d259..1f4d07748f 100644 --- a/spec/factories/assessments.rb +++ b/spec/factories/assessments.rb @@ -74,6 +74,16 @@ end end + trait :with_consent_request do + after(:create) do |assessment, _evaluator| + create( + :consent_request, + assessment:, + qualification: assessment.application_form.qualifications.first, + ) + end + end + trait :with_further_information_request do after(:create) do |assessment, _evaluator| create( diff --git a/spec/forms/assessor_interface/upload_unsigned_consent_document_form_spec.rb b/spec/forms/assessor_interface/upload_unsigned_consent_document_form_spec.rb index 62d66d72b6..5fab3b0f64 100644 --- a/spec/forms/assessor_interface/upload_unsigned_consent_document_form_spec.rb +++ b/spec/forms/assessor_interface/upload_unsigned_consent_document_form_spec.rb @@ -4,15 +4,13 @@ RSpec.describe AssessorInterface::UploadUnsignedConsentDocumentForm, type: :model do - subject(:form) do - described_class.new(qualification_request:, original_attachment:) - end + subject(:form) { described_class.new(consent_request:, original_attachment:) } - let(:qualification_request) { create(:qualification_request) } - let(:document) { qualification_request.unsigned_consent_document } + let(:consent_request) { create(:consent_request) } + let(:document) { consent_request.unsigned_consent_document } let(:original_attachment) { nil } - it { is_expected.to validate_presence_of(:qualification_request) } + it { is_expected.to validate_presence_of(:consent_request) } describe "validations" do it { is_expected.to validate_absence_of(:written_in_english) } diff --git a/spec/forms/teacher_interface/qualification_request_download_form_spec.rb b/spec/forms/teacher_interface/download_unsigned_consent_document_form_spec.rb similarity index 51% rename from spec/forms/teacher_interface/qualification_request_download_form_spec.rb rename to spec/forms/teacher_interface/download_unsigned_consent_document_form_spec.rb index 7158cd8b21..cc2c18f712 100644 --- a/spec/forms/teacher_interface/qualification_request_download_form_spec.rb +++ b/spec/forms/teacher_interface/download_unsigned_consent_document_form_spec.rb @@ -2,16 +2,16 @@ require "rails_helper" -RSpec.describe TeacherInterface::QualificationRequestDownloadForm, +RSpec.describe TeacherInterface::DownloadUnsignedConsentDocumentForm, type: :model do - let(:qualification_request) { create(:qualification_request) } + let(:consent_request) { create(:consent_request) } - subject(:form) { described_class.new(qualification_request:, downloaded:) } + subject(:form) { described_class.new(consent_request:, downloaded:) } describe "validations" do let(:downloaded) { "" } - it { is_expected.to validate_presence_of(:qualification_request) } + it { is_expected.to validate_presence_of(:consent_request) } it { is_expected.to validate_presence_of(:downloaded) } end @@ -21,10 +21,10 @@ context "with a positive response" do let(:downloaded) { "true" } - it "sets unsigned_consent_document_downloaded" do + it "sets unsigned_document_downloaded" do expect { save }.to change( - qualification_request, - :unsigned_consent_document_downloaded, + consent_request, + :unsigned_document_downloaded, ).to(true) end end @@ -32,10 +32,10 @@ context "with a negative response" do let(:downloaded) { "false" } - it "doesn't set unsigned_consent_document_downloaded" do + it "doesn't set unsigned_document_downloaded" do expect { save }.to_not change( - qualification_request, - :unsigned_consent_document_downloaded, + consent_request, + :unsigned_document_downloaded, ) end end diff --git a/spec/lib/document_continue_redirection_spec.rb b/spec/lib/document_continue_redirection_spec.rb index 876e7bbf37..fafb8e1640 100644 --- a/spec/lib/document_continue_redirection_spec.rb +++ b/spec/lib/document_continue_redirection_spec.rb @@ -128,31 +128,23 @@ end context "with an signed consent document" do - let(:qualification_request) { create(:qualification_request) } - let(:document) do - create(:document, :signed_consent, documentable: qualification_request) - end + let(:documentable) { create(:consent_request) } + let(:document) { create(:document, :signed_consent, documentable:) } it do is_expected.to eq( - %i[teacher_interface application_form qualification_requests], + %i[teacher_interface application_form consent_requests], ) end end context "with an unsigned consent document" do - let(:qualification_request) { create(:qualification_request) } - let(:document) do - create( - :document, - :unsigned_consent, - documentable: qualification_request, - ) - end + let(:documentable) { create(:consent_request) } + let(:document) { create(:document, :unsigned_consent, documentable:) } it do is_expected.to eq( - %i[teacher_interface application_form qualification_requests], + %i[teacher_interface application_form consent_requests], ) end end diff --git a/spec/mailers/teacher_mailer_spec.rb b/spec/mailers/teacher_mailer_spec.rb index f4a8856d0c..9115228fbf 100644 --- a/spec/mailers/teacher_mailer_spec.rb +++ b/spec/mailers/teacher_mailer_spec.rb @@ -263,10 +263,10 @@ before do create( - :qualification_request, - :consent_requested, + :consent_request, + :requested, assessment:, - consent_requested_at: Date.new(2020, 1, 1), + requested_at: Date.new(2020, 1, 1), qualification:, ) end @@ -309,10 +309,9 @@ before do create( - :qualification_request, - :consent_requested, + :consent_request, assessment:, - consent_requested_at: Date.new(2020, 1, 1), + requested_at: Date.new(2020, 1, 1), qualification:, ) end diff --git a/spec/models/application_form_spec.rb b/spec/models/application_form_spec.rb index 39a8269d07..cbb35c2e66 100644 --- a/spec/models/application_form_spec.rb +++ b/spec/models/application_form_spec.rb @@ -429,26 +429,26 @@ let(:number_of_reminders_sent) { 0 } it { is_expected.to be false } - context "with a qualification request" do + context "with a consent request" do before do create( - :qualification_request, + :consent_request, assessment:, qualification:, - consent_requested_at: 1.week.ago, + requested_at: 1.week.ago, ) end it { is_expected.to be false } end - context "with a qualification request older than 3 weeks ago" do + context "with a consent request older than 3 weeks ago" do before do create( - :qualification_request, + :consent_request, assessment:, qualification:, - consent_requested_at: 4.weeks.ago, + requested_at: 4.weeks.ago, ) end diff --git a/spec/services/destroy_application_form_spec.rb b/spec/services/destroy_application_form_spec.rb index 9d1161e8c1..7642bf144b 100644 --- a/spec/services/destroy_application_form_spec.rb +++ b/spec/services/destroy_application_form_spec.rb @@ -16,10 +16,11 @@ assessment = create( :assessment, + :with_consent_request, :with_further_information_request, :with_professional_standing_request, - :with_reference_request, :with_qualification_request, + :with_reference_request, application_form:, ) @@ -43,6 +44,7 @@ include_examples "deletes model", ApplicationForm include_examples "deletes model", Assessment include_examples "deletes model", AssessmentSection + include_examples "deletes model", ConsentRequest include_examples "deletes model", DQTTRNRequest include_examples "deletes model", Document, 20, 10 include_examples "deletes model", FurtherInformationRequest diff --git a/spec/support/autoload/page_objects/teacher_interface/check_qualification_requests.rb b/spec/support/autoload/page_objects/teacher_interface/check_consent_requests.rb similarity index 66% rename from spec/support/autoload/page_objects/teacher_interface/check_qualification_requests.rb rename to spec/support/autoload/page_objects/teacher_interface/check_consent_requests.rb index a390584cb7..9a2d654712 100644 --- a/spec/support/autoload/page_objects/teacher_interface/check_qualification_requests.rb +++ b/spec/support/autoload/page_objects/teacher_interface/check_consent_requests.rb @@ -2,8 +2,8 @@ module PageObjects module TeacherInterface - class CheckQualificationRequests < SitePrism::Page - set_url "/teacher/application/qualification-requests/check" + class CheckConsentRequests < SitePrism::Page + set_url "/teacher/application/consent-requests/check" element :heading, "h1" section :summary_card, GovukSummaryCard, ".govuk-summary-card" diff --git a/spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb b/spec/support/autoload/page_objects/teacher_interface/consent_requests.rb similarity index 75% rename from spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb rename to spec/support/autoload/page_objects/teacher_interface/consent_requests.rb index 53db529dbe..2afb6f9187 100644 --- a/spec/support/autoload/page_objects/teacher_interface/qualification_requests.rb +++ b/spec/support/autoload/page_objects/teacher_interface/consent_requests.rb @@ -2,8 +2,8 @@ module PageObjects module TeacherInterface - class QualificationRequests < SitePrism::Page - set_url "/teacher/application/qualification-requests" + class ConsentRequests < SitePrism::Page + set_url "/teacher/application/consent-requests" section :task_list, TaskList, ".app-task-list" diff --git a/spec/support/autoload/page_objects/teacher_interface/qualification_request_download.rb b/spec/support/autoload/page_objects/teacher_interface/download_consent_request.rb similarity index 71% rename from spec/support/autoload/page_objects/teacher_interface/qualification_request_download.rb rename to spec/support/autoload/page_objects/teacher_interface/download_consent_request.rb index 3ae1638c18..4385a8f679 100644 --- a/spec/support/autoload/page_objects/teacher_interface/qualification_request_download.rb +++ b/spec/support/autoload/page_objects/teacher_interface/download_consent_request.rb @@ -2,8 +2,8 @@ module PageObjects module TeacherInterface - class QualificationRequestDownload < SitePrism::Page - set_url "/teacher/application/qualification-requests/{id}/download" + class DownloadConsentRequest < SitePrism::Page + set_url "/teacher/application/consent-requests/{id}/download" element :downloaded_checkbox, ".govuk-checkboxes__input", visible: false diff --git a/spec/support/page_helpers.rb b/spec/support/page_helpers.rb index fad7dd1bbc..f4c6e201db 100644 --- a/spec/support/page_helpers.rb +++ b/spec/support/page_helpers.rb @@ -346,6 +346,11 @@ def teacher_application_page @teacher_application_page = PageObjects::TeacherInterface::Application.new end + def teacher_check_consent_requests_page + @teacher_check_consent_requests_page = + PageObjects::TeacherInterface::CheckConsentRequests.new + end + def teacher_check_document_page @teacher_check_document_page = PageObjects::TeacherInterface::CheckDocument.new @@ -375,11 +380,6 @@ def teacher_check_qualification_page PageObjects::TeacherInterface::CheckQualification.new end - def teacher_check_qualification_requests_page - @teacher_check_qualification_requests_page = - PageObjects::TeacherInterface::CheckQualificationRequests.new - end - def teacher_check_qualifications_page @teacher_check_qualifications_page ||= PageObjects::TeacherInterface::CheckQualifications.new @@ -415,6 +415,11 @@ def teacher_check_your_uploads_page PageObjects::TeacherInterface::CheckYourUploads.new end + def teacher_consent_requests_page + @teacher_consent_requests_page = + PageObjects::TeacherInterface::ConsentRequests.new + end + def teacher_declined_application_page @teacher_declined_application_page ||= PageObjects::TeacherInterface::DeclinedApplication.new @@ -435,6 +440,11 @@ def teacher_document_available_page PageObjects::TeacherInterface::DocumentAvailable.new end + def teacher_download_consent_request_page + @teacher_download_consent_request_page = + PageObjects::TeacherInterface::DownloadConsentRequest.new + end + def teacher_edit_qualification_page @teacher_edit_qualification_page ||= PageObjects::TeacherInterface::EditQualification.new @@ -569,16 +579,6 @@ def teacher_personal_information_summary_page PageObjects::TeacherInterface::PersonalInformationSummary.new end - def teacher_qualification_requests_page - @teacher_qualification_requests_page = - PageObjects::TeacherInterface::QualificationRequests.new - end - - def teacher_qualification_request_download_page - @teacher_qualification_request_download_page = - PageObjects::TeacherInterface::QualificationRequestDownload.new - end - def teacher_reference_received_page @teacher_reference_received_page ||= PageObjects::TeacherInterface::ReferenceReceived.new diff --git a/spec/system/teacher_interface/qualification_consent_spec.rb b/spec/system/teacher_interface/consent_spec.rb similarity index 69% rename from spec/system/teacher_interface/qualification_consent_spec.rb rename to spec/system/teacher_interface/consent_spec.rb index f1e106f43b..e1fed8cae3 100644 --- a/spec/system/teacher_interface/qualification_consent_spec.rb +++ b/spec/system/teacher_interface/consent_spec.rb @@ -1,11 +1,11 @@ require "rails_helper" -RSpec.describe "Teacher qualification consent", type: :system do +RSpec.describe "Teacher consent", type: :system do before do given_the_service_is_open given_i_am_authorized_as_a_user(teacher) given_there_is_an_application_form - given_there_is_a_qualification_request + given_there_is_a_consent_request end it "save and sign out" do @@ -14,7 +14,7 @@ and_i_see_qualification_consent_start_now_content when_i_click_the_start_button - then_i_see_the(:teacher_qualification_requests_page) + then_i_see_the(:teacher_consent_requests_page) when_i_click_the_save_and_sign_out_button then_i_see_the(:teacher_signed_out_page) @@ -27,17 +27,17 @@ and_i_see_qualification_consent_start_now_content when_i_click_the_start_button - then_i_see_the(:teacher_qualification_requests_page) + then_i_see_the(:teacher_consent_requests_page) and_i_see_the_download_and_upload_tasks when_i_click_the_download_task then_i_see_the( - :teacher_qualification_request_download_page, - id: qualification_request.id, + :teacher_download_consent_request_page, + id: consent_request.id, ) when_i_check_the_downloaded_checkbox - then_i_see_the(:teacher_qualification_requests_page) + then_i_see_the(:teacher_consent_requests_page) when_i_click_the_upload_task then_i_see_the(:teacher_upload_document_page) @@ -46,10 +46,10 @@ then_i_see_the(:teacher_check_document_page) when_i_dont_need_to_upload_another_file - then_i_see_the(:teacher_qualification_requests_page) + then_i_see_the(:teacher_consent_requests_page) when_i_click_check_your_answers - then_i_see_the(:teacher_check_qualification_requests_page) + then_i_see_the(:teacher_check_consent_requests_page) and_i_see_the_documents when_i_click_submit @@ -61,8 +61,8 @@ def given_there_is_an_application_form application_form end - def given_there_is_a_qualification_request - qualification_request + def given_there_is_a_consent_request + consent_request end def and_i_see_qualification_consent_start_now_content @@ -76,7 +76,7 @@ def when_i_click_the_start_button end def when_i_click_the_save_and_sign_out_button - teacher_qualification_requests_page.save_and_sign_out_button.click + teacher_consent_requests_page.save_and_sign_out_button.click end def and_i_see_qualification_consent_sign_out_content @@ -86,7 +86,7 @@ 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 + task_list = teacher_consent_requests_page.task_list expect(task_list.sections.count).to eq(1) task_list_section = task_list.sections.first @@ -94,28 +94,16 @@ def and_i_see_the_download_and_upload_tasks end def when_i_click_the_download_task - teacher_qualification_requests_page - .task_list - .sections - .first - .items - .first - .click + teacher_consent_requests_page.task_list.sections.first.items.first.click end def when_i_check_the_downloaded_checkbox - teacher_qualification_request_download_page.downloaded_checkbox.check - teacher_qualification_request_download_page.continue_button.click + teacher_download_consent_request_page.downloaded_checkbox.check + teacher_download_consent_request_page.continue_button.click end def when_i_click_the_upload_task - teacher_qualification_requests_page - .task_list - .sections - .first - .items - .second - .click + teacher_consent_requests_page.task_list.sections.first.items.second.click end def when_i_upload_a_file @@ -130,15 +118,15 @@ def when_i_dont_need_to_upload_another_file end def when_i_click_check_your_answers - teacher_qualification_requests_page.check_your_answers_button.click + teacher_consent_requests_page.check_your_answers_button.click end def and_i_see_the_documents - expect(teacher_check_qualification_requests_page.summary_card).to be_visible + expect(teacher_check_consent_requests_page.summary_card).to be_visible end def when_i_click_submit - teacher_check_qualification_requests_page.submit_button.click + teacher_check_consent_requests_page.submit_button.click end def and_i_see_the_consent_submitted_status @@ -161,17 +149,18 @@ def application_form :submitted, :with_assessment, :with_teaching_qualification, - statuses: %w[waiting_on_qualification], + statuses: %w[waiting_on_consent], teacher:, ) end - def qualification_request - @qualification_request ||= + def consent_request + @consent_request ||= create( - :qualification_request, - :consent_requested, + :consent_request, + :requested, assessment: application_form.assessment, + qualification: application_form.qualifications.first, ) end end diff --git a/spec/view_objects/assessor_interface/qualification_requests_view_object_spec.rb b/spec/view_objects/assessor_interface/qualification_requests_view_object_spec.rb index 615237b38c..86bda626c1 100644 --- a/spec/view_objects/assessor_interface/qualification_requests_view_object_spec.rb +++ b/spec/view_objects/assessor_interface/qualification_requests_view_object_spec.rb @@ -15,13 +15,10 @@ end let(:assessment) { application_form.assessment } + let(:qualification) { application_form.qualifications.first } let!(:qualification_request) do - create( - :qualification_request, - assessment:, - qualification: application_form.qualifications.first, - ) + create(:qualification_request, assessment:, qualification:) end describe "#all_task_items" do @@ -139,7 +136,10 @@ end context "when signed consent method" do - before { qualification_request.consent_method_signed_ecctis! } + before do + qualification_request.consent_method_signed_ecctis! + create(:consent_request, assessment:, qualification:) + end it do is_expected.to eq( diff --git a/spec/view_objects/teacher_interface/qualification_requests_view_object_spec.rb b/spec/view_objects/teacher_interface/consent_requests_view_object_spec.rb similarity index 80% rename from spec/view_objects/teacher_interface/qualification_requests_view_object_spec.rb rename to spec/view_objects/teacher_interface/consent_requests_view_object_spec.rb index 8b3a0e8882..18eefa64fe 100644 --- a/spec/view_objects/teacher_interface/qualification_requests_view_object_spec.rb +++ b/spec/view_objects/teacher_interface/consent_requests_view_object_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -RSpec.describe TeacherInterface::QualificationRequestsViewObject do +RSpec.describe TeacherInterface::ConsentRequestsViewObject do subject(:view_object) { described_class.new(application_form:) } let(:application_form) do @@ -14,11 +14,11 @@ it { is_expected.to be_empty } - context "with a qualification request" do - let!(:qualification_request) do + context "with a consent request" do + let!(:consent_request) do create( - :qualification_request, - :consent_requested, + :consent_request, + :requested, assessment: application_form.assessment, qualification: create( @@ -42,7 +42,7 @@ :download, :teacher_interface, :application_form, - qualification_request, + consent_request, ], status: :not_started, }, @@ -51,7 +51,7 @@ link: [ :teacher_interface, :application_form, - qualification_request.signed_consent_document, + consent_request.signed_consent_document, ], status: :cannot_start, }, @@ -62,11 +62,7 @@ end context "when the unsigned consent document is downloaded" do - before do - qualification_request.update!( - unsigned_consent_document_downloaded: true, - ) - end + before { consent_request.update!(unsigned_document_downloaded: true) } it do is_expected.to eq( @@ -80,7 +76,7 @@ :download, :teacher_interface, :application_form, - qualification_request, + consent_request, ], status: :completed, }, @@ -89,7 +85,7 @@ link: [ :teacher_interface, :application_form, - qualification_request.signed_consent_document, + consent_request.signed_consent_document, ], status: :not_started, }, @@ -101,9 +97,7 @@ context "when the signed consent document is uploaded" do before do - qualification_request.signed_consent_document.update!( - completed: true, - ) + consent_request.signed_consent_document.update!(completed: true) end it do @@ -118,7 +112,7 @@ :download, :teacher_interface, :application_form, - qualification_request, + consent_request, ], status: :completed, }, @@ -127,7 +121,7 @@ link: [ :teacher_interface, :application_form, - qualification_request.signed_consent_document, + consent_request.signed_consent_document, ], status: :completed, },