Skip to content

Commit

Permalink
CST-2575: allow participants to be sit in payments-frozen cohort
Browse files Browse the repository at this point in the history
  • Loading branch information
ltello committed May 29, 2024
1 parent bdc3c58 commit f6f333b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
6 changes: 5 additions & 1 deletion app/models/participant_profile/ecf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ def self.archivable(for_cohort_start_year:, restrict_to_participant_ids: [])
end

# Instance Methods
def eligible_to_change_cohort_and_continue_training?(in_cohort_start_year:)
def eligible_to_change_cohort_and_continue_training?(cohort:)
self.class.eligible_to_change_cohort_and_continue_training(in_cohort_start_year:, restrict_to_participant_ids: [id]).exists?
end

def eligible_to_change_cohort_back_to_their_payments_frozen_original?(cohort:)
true
end

def archivable?(for_cohort_start_year:)
self.class.archivable(for_cohort_start_year:, restrict_to_participant_ids: [id]).exists?
end
Expand Down
5 changes: 0 additions & 5 deletions app/services/induction/amend_participant_cohort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class AmendParticipantCohort
validates :participant_profile,
active_participant_profile: true

validate :target_cohort_payments_active, unless: :back_to_payments_frozen_cohort?
validate :transfer_from_payments_frozen_cohort, if: :transfer_from_payments_frozen_cohort?
validate :transfer_to_payments_frozen_cohort, if: :back_to_payments_frozen_cohort?

Expand Down Expand Up @@ -209,10 +208,6 @@ def transfer_from_payments_frozen_cohort?

# Validations

def target_cohort_payments_active
errors.add(:target_cohort_start_year, :payments_frozen) if target_cohort&.payments_frozen?
end

def transfer_from_payments_frozen_cohort
unless participant_profile.eligible_to_change_cohort_and_continue_training?(cohort: target_cohort)
errors.add(:participant_profile, :not_eligible_to_be_transferred_from_current_cohort)
Expand Down
18 changes: 4 additions & 14 deletions spec/services/induction/amend_participant_cohort_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,15 @@
end
end

context "when the participant is transferring to a payments-frozen cohort" do
context "when they are transferring back to their original cohort" do
before do
target_cohort.update!(payments_frozen_at: 1.month.ago)
participant_profile.update!(cohort_changed_after_payments_frozen: true)
end

context "when they are transferring back to their original cohort" do
before do
participant_profile.update!(cohort_changed_after_payments_frozen: true)
end

it "do not set errors" do
expect(form.save).to be_falsey
expect(form.errors.map(&:attribute)).not_to include(:target_cohort_start_year)
end
end

it "set errors" do
it "do not set errors" do
expect(form.save).to be_falsey
expect(form.errors[:target_cohort_start_year]).to include("Not permitted. The cohort is frozen for payments")
expect(form.errors.map(&:attribute)).not_to include(:target_cohort_start_year)
end
end

Expand Down

0 comments on commit f6f333b

Please sign in to comment.