Skip to content

Commit

Permalink
Add ConsentRequest
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomasleese committed Feb 23, 2024
1 parent b6484cd commit 2d27e42
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 19 deletions.
6 changes: 3 additions & 3 deletions app/models/concerns/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
19 changes: 19 additions & 0 deletions app/models/consent_request.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20240223065851_add_consent_requests.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 19 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions spec/factories/consent_requests.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions spec/models/consent_request_spec.rb
Original file line number Diff line number Diff line change
@@ -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
37 changes: 22 additions & 15 deletions spec/support/shared_examples/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2d27e42

Please sign in to comment.