Skip to content

Commit

Permalink
Handle consent expiration
Browse files Browse the repository at this point in the history
This makes it possible for consent qualification request to expire after
6 weeks, and a normal qualification request to expire after 6 weeks as
well.
  • Loading branch information
thomasleese committed Feb 13, 2024
1 parent 29d20c8 commit 8d7ab1b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/expirable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/factories/qualification_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 42 additions & 2 deletions spec/models/qualification_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d7ab1b

Please sign in to comment.