Skip to content

Commit

Permalink
Move mid_cohort to describe block
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyheadford committed Jun 5, 2024
1 parent e54a049 commit f15ab72
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions spec/services/induction/amend_participant_cohort_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Induction::AmendParticipantCohort, mid_cohort: true do
RSpec.describe Induction::AmendParticipantCohort do
describe "#save" do
let(:participant_profile) {}
let(:source_cohort_start_year) { Cohort.previous.start_year }
Expand Down Expand Up @@ -380,41 +380,43 @@
end
end

%i[voided ineligible awaiting_clawback clawed_back].each do |declaration_state|
context "when the participant has #{declaration_state} declarations and no billable or changeable declarations" do
before do
participant_profile.participant_declarations.create!(declaration_date: Date.new(Cohort.previous.start_year, 10, 10),
declaration_type: :started,
state: declaration_state,
course_identifier: "ecf-induction",
cpd_lead_provider: create(:cpd_lead_provider),
user: participant_profile.user,
cohort: participant_profile.schedule.cohort)
end

it "executes the transfer" do
expect(form.save).to be_truthy
expect(participant_profile.reload.latest_induction_record.cohort_start_year).to eq(target_cohort_start_year)
end

it "returns true and set no errors" do
expect(form.save).to be_truthy
expect(form.errors).to be_empty
end

context "when the transfer is due to payments frozen in the cohort of the participant" do
describe "declaration states", mid_cohort: true do
%i[voided ineligible awaiting_clawback clawed_back].each do |declaration_state|
context "when the participant has #{declaration_state} declarations and no billable or changeable declarations" do
before do
source_cohort.update!(payments_frozen_at: Time.current)
allow(participant_profile).to receive(:eligible_to_change_cohort_and_continue_training?).and_return(true)
participant_profile.participant_declarations.create!(declaration_date: Date.new(Cohort.previous.start_year, 10, 10),
declaration_type: :started,
state: declaration_state,
course_identifier: "ecf-induction",
cpd_lead_provider: create(:cpd_lead_provider),
user: participant_profile.user,
cohort: participant_profile.schedule.cohort)
end

it "mark the participant as transferred for that reason" do
it "executes the transfer" do
expect(form.save).to be_truthy
expect(participant_profile).to be_cohort_changed_after_payments_frozen
expect(participant_profile.reload.latest_induction_record.cohort_start_year).to eq(target_cohort_start_year)
end

it "mark the participant as transferred from the original cohort" do
it "returns true and set no errors" do
expect(form.save).to be_truthy
expect(form.errors).to be_empty
end

context "when the transfer is due to payments frozen in the cohort of the participant" do
before do
source_cohort.update!(payments_frozen_at: Time.current)
allow(participant_profile).to receive(:eligible_to_change_cohort_and_continue_training?).and_return(true)
end

it "mark the participant as transferred for that reason" do
expect(form.save).to be_truthy
expect(participant_profile).to be_cohort_changed_after_payments_frozen
end

it "mark the participant as transferred from the original cohort" do
expect(form.save).to be_truthy
end
end
end
end
Expand Down

0 comments on commit f15ab72

Please sign in to comment.