Skip to content

Commit

Permalink
Add VerifyRequestable
Browse files Browse the repository at this point in the history
This adds a service class which we can use to mark a requestable as
verified.
  • Loading branch information
thomasleese committed Oct 4, 2023
1 parent a1099e4 commit b41de1c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/concerns/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ def after_received(user:)
def after_reviewed(user:)
# implement logic after this requestable has been reviewed
end

def after_verified(user:)
# implement logic after this requestable has been verified
end
end
44 changes: 44 additions & 0 deletions app/services/verify_requestable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

class VerifyRequestable
include ServicePattern

def initialize(requestable:, user:, passed:, note:)
@requestable = requestable
@user = user
@passed = passed
@note = note
end

def call
ActiveRecord::Base.transaction do
requestable.update!(
verify_passed: passed,
verify_note: note,
verified_at: Time.zone.now,
)

requestable.after_verified(user:)
application_form.reload

create_timeline_event

ApplicationFormStatusUpdater.call(application_form:, user:)
end
end

private

attr_reader :requestable, :user, :passed, :note

def create_timeline_event
TimelineEvent.create!(
creator: user,
event_type: "requestable_verified",
requestable:,
application_form:,
)
end

delegate :application_form, to: :requestable
end
44 changes: 44 additions & 0 deletions spec/services/verify_requestable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe VerifyRequestable do
let(:requestable) { create(:professional_standing_request, :received) }
let(:user) { create(:staff) }
let(:passed) { true }
let(:note) { "Note" }

subject(:call) { described_class.call(requestable:, user:, passed:, note:) }

describe "requestable verify decision" do
subject { requestable.verify_passed }

it { is_expected.to be_nil }

context "after calling the service" do
before { call }

it { is_expected.to be true }
end
end

describe "requestable verify note" do
subject { requestable.verify_note }

it { is_expected.to be_blank }

context "after calling the service" do
before { call }

it { is_expected.to eq("Note") }
end
end

it "records a timeline event" do
expect { call }.to have_recorded_timeline_event(
:requestable_verified,
creator: user,
requestable:,
)
end
end

0 comments on commit b41de1c

Please sign in to comment.