Skip to content

Commit

Permalink
Fix declaration cohort outside of factory
Browse files Browse the repository at this point in the history
I wanted to do this in the factory originally, but it creates a cyclic
dependency on the `participant_profile -> cohort` so we need to define it
explicitly for now.
  • Loading branch information
ethax-ross committed May 20, 2024
1 parent 397ed9d commit 30e3704
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/factories/participant_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FactoryBot.define do
factory :participant_declaration do
declaration_type { "started" }
cohort { participant_profile.schedule.cohort || Cohort.current || create(:cohort, :current) }
cohort { Cohort.current || create(:cohort, :current) }

declaration_date do
participant_profile.schedule.milestones.find_by!(declaration_type:).start_date
Expand Down
3 changes: 2 additions & 1 deletion spec/factories/services/npq/npq_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
declaration_type: "started",
participant_profile: npq_application.profile,
course_identifier: npq_application.npq_course.identifier,
cpd_lead_provider: npq_application.npq_lead_provider.cpd_lead_provider)
cpd_lead_provider: npq_application.npq_lead_provider.cpd_lead_provider,
cohort: npq_application.cohort)
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/services/api/v3/participant_declarations_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile1,
delivery_partner: delivery_partner1,
cohort: participant_profile1.schedule.cohort,
)

ParticipantDeclaration.where(id: declaration.id).select(:id, :created_at).first
Expand All @@ -56,6 +57,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile2,
delivery_partner: delivery_partner2,
cohort: participant_profile2.schedule.cohort,
)

ParticipantDeclaration.where(id: declaration.id).select(:id, :created_at).first
Expand All @@ -70,6 +72,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile3,
delivery_partner: delivery_partner2,
cohort: participant_profile3.schedule.cohort,
)

ParticipantDeclaration.where(id: declaration.id).select(:id, :created_at).first
Expand All @@ -84,6 +87,7 @@
cpd_lead_provider: cpd_lead_provider2,
participant_profile: participant_profile4,
delivery_partner: delivery_partner1,
cohort: participant_profile4.schedule.cohort,
)

ParticipantDeclaration.where(id: declaration.id).select(:id, :created_at).first
Expand All @@ -110,6 +114,7 @@
cpd_lead_provider: cpd_lead_provider2,
participant_profile: transfer_induction_record.participant_profile,
delivery_partner: delivery_partner1,
cohort: transfer_induction_record.participant_profile.schedule.cohort,
)

ParticipantDeclaration.where(id: declaration.id).select(:id, :created_at).first
Expand Down Expand Up @@ -300,6 +305,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile1,
delivery_partner: delivery_partner1,
cohort: participant_profile1.schedule.cohort,
)
end
end
Expand All @@ -312,6 +318,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile2,
delivery_partner: delivery_partner2,
cohort: participant_profile2.schedule.cohort,
)
end
end
Expand All @@ -324,6 +331,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile3,
delivery_partner: delivery_partner2,
cohort: participant_profile3.schedule.cohort,
)
end
end
Expand All @@ -336,6 +344,7 @@
cpd_lead_provider: cpd_lead_provider2,
participant_profile: participant_profile4,
delivery_partner: delivery_partner1,
cohort: participant_profile4.schedule.cohort,
)
end
end
Expand Down Expand Up @@ -373,6 +382,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile1,
delivery_partner: delivery_partner1,
cohort: participant_profile1.schedule.cohort,
)
end

Expand Down Expand Up @@ -402,6 +412,7 @@
cpd_lead_provider: cpd_lead_provider2,
participant_profile: transfer_induction_record.participant_profile,
delivery_partner: delivery_partner1,
cohort: transfer_induction_record.participant_profile.schedule.cohort,
)
end

Expand Down

0 comments on commit 30e3704

Please sign in to comment.