-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a service class which we can use to mark a requestable as verified.
- Loading branch information
1 parent
a1099e4
commit b41de1c
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |