Skip to content

Commit

Permalink
Add consent scopes
Browse files Browse the repository at this point in the history
This adds a number of scopes on the qualification request suitable for
querying the consent status of the request.
  • Loading branch information
thomasleese committed Feb 8, 2024
1 parent 090ea41 commit 6cb6d98
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def translatable?
end

def optional?
written_statement? && application_form.written_statement_optional
(signed_consent? && !documentable.signed_consent_document_required) ||
(written_statement? && application_form.written_statement_optional)
end

def for_further_information_request?
Expand Down
27 changes: 27 additions & 0 deletions app/models/qualification_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,37 @@ class QualificationRequest < ApplicationRecord

belongs_to :qualification

scope :consent_required, -> { where(signed_consent_document_required: true) }
scope :consent_requested, -> { where.not(consent_requested_at: nil) }
scope :consent_received, -> { where.not(consent_received_at: nil) }
scope :consent_respondable,
-> do
consent_required
.consent_requested
.where(consent_received_at: nil)
.merge(ApplicationForm.assessable)
end

scope :order_by_role, -> { order("qualifications.start_date": :desc) }
scope :order_by_user, -> { order("qualifications.created_at": :asc) }

def expires_after
6.weeks
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
27 changes: 27 additions & 0 deletions spec/models/qualification_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
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) }

Expand All @@ -57,4 +60,28 @@
subject(:expires_after) { described_class.new.expires_after }
it { is_expected.to eq(6.weeks) }
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
end
end

0 comments on commit 6cb6d98

Please sign in to comment.