Skip to content

Commit

Permalink
Extra spec and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyheadford committed Dec 6, 2022
1 parent 9769213 commit e2eee97
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/services/participants/determine_eligibility_status.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# frozen_string_literal: true

##
# Determine the +status+ and +reason+ for a participant's +ECFParticipantEligibility+ record
# Uses the flags stored on the +ECFParticipantEligibility+ and related info from the
# associated +ParticipantProfile+
# If the +manually_validated+ attribute is set then the eligibility will not be re-evaluated. Use the <tt>force_validation: true</tt>
# param to override this behaviour.
#
# == Parameters
# @param :ecf_participant_eligibility [ECFParticipantEligibility] the record to determine eligibilty for
# @param :save_record [Boolean] whether to save the record after setting the +status+ and +reason+ attributes. Default is +true+
# @param :force_validation [Boolean] override the +manually_validated+ guard flag if set. Default is +false+
#
# == Usage:
# <tt>Participants::DetermineEligibilityStatus.call(ecf_participant_eligibility: eligibility_record)</tt>
#
class Participants::DetermineEligibilityStatus < BaseService
delegate :active_flags?,
:previous_participation?,
Expand Down
16 changes: 15 additions & 1 deletion spec/services/participants/determine_eligibility_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe Participants::DetermineEligibilityStatus do
let(:participant_profile) { create(:ect_participant_profile) }
let(:eligibility) { create(:ecf_participant_eligibility, participant_profile:, active_flags: false, previous_participation: false, previous_induction: false, qts: true) }
let(:eligibility) { create(:ecf_participant_eligibility, participant_profile:) }
let(:save_record) { true }
let(:force_validation) { false }
subject(:service_call) { described_class.call(ecf_participant_eligibility: eligibility, save_record:, force_validation:) }
Expand Down Expand Up @@ -38,6 +38,20 @@
end
end

context "when save_record is false" do
let(:save_record) { false }

before do
eligibility.active_flags = true
service_call
end

it "does not persist the changes" do
expect(eligibility).to be_manual_check_status
expect(eligibility.reload).to be_eligible_status
end
end

context "when active_flags are true" do
before do
eligibility.active_flags = true
Expand Down

0 comments on commit e2eee97

Please sign in to comment.