diff --git a/app/models/application_form.rb b/app/models/application_form.rb index 62fc80ffbd..99dbdff203 100644 --- a/app/models/application_form.rb +++ b/app/models/application_form.rb @@ -289,12 +289,12 @@ def send_reminder_email(name, number_of_reminders_sent) end end - def expires_after - submitted? ? nil : 6.months + def expires_from + created_at end - def requested_at - created_at + def expires_after + submitted? ? nil : 6.months end private diff --git a/app/models/concerns/expirable.rb b/app/models/concerns/expirable.rb index 6b6fa64280..93ae7f4886 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 requested_at.nil? || expires_after.nil? + return nil if expires_from.nil? || expires_after.nil? - requested_at + expires_after + expires_from + expires_after end def days_until_expired diff --git a/app/models/concerns/requestable.rb b/app/models/concerns/requestable.rb index 112bb639a9..c3e485a853 100644 --- a/app/models/concerns/requestable.rb +++ b/app/models/concerns/requestable.rb @@ -18,6 +18,10 @@ module Requestable 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 diff --git a/spec/factories/qualification_requests.rb b/spec/factories/qualification_requests.rb index 8cb8256568..43cbd1ee91 100644 --- a/spec/factories/qualification_requests.rb +++ b/spec/factories/qualification_requests.rb @@ -39,6 +39,17 @@ association :assessment association :qualification, :completed + trait :consent_required do + signed_consent_document_required { true } + 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 :requested do requested_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end diff --git a/spec/models/qualification_request_spec.rb b/spec/models/qualification_request_spec.rb index 187344991c..45768f6c2f 100644 --- a/spec/models/qualification_request_spec.rb +++ b/spec/models/qualification_request_spec.rb @@ -56,9 +56,49 @@ 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) { described_class.new.expires_after } - it { is_expected.to eq(6.weeks) } + 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