Skip to content

Commit

Permalink
Fix flakey test(s) due to statement factory dates
Browse files Browse the repository at this point in the history
  • Loading branch information
rwrrll committed Dec 19, 2024
1 parent 8186886 commit 2d9c055
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions spec/factories/statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
end

month { Faker::Number.between(from: 1, to: 12) }
year { Faker::Number.between(from: 2021, to: 2024) }
deadline_date { Faker::Date.forward(days: 30) }
payment_date { Faker::Date.forward(days: 30) }
year { Faker::Number.between(from: 2022, to: 2024) }
deadline_date { Date.new(year, month, 1) - 6.days }
payment_date { Date.new(year, month, 25) }
cohort { create(:cohort, :current) }
lead_provider { declaration&.lead_provider || build(:lead_provider) }
reconcile_amount { Faker::Number.decimal(l_digits: 3, r_digits: 2) }
Expand All @@ -22,7 +22,7 @@
output_fee { true }

trait(:next_output_fee) do
deadline_date { 1.day.from_now }
next_period
output_fee { true }
end

Expand Down
14 changes: 10 additions & 4 deletions spec/services/declarations/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe Declarations::Create, type: :model do
let(:lead_provider) { LeadProvider.all.sample }
let(:cohort) { create(:cohort, :current) }
let(:cohort) { create(:cohort, start_year: 2022) }
let(:course_group) { CourseGroup.find_by(name: "leadership") || create(:course_group, name: "leadership") }
let(:course) { create(:course, :senior_leadership, course_group:) }
let!(:schedule) { create(:schedule, :npq_leadership_autumn, course_group:, cohort:) }
Expand Down Expand Up @@ -120,9 +120,13 @@
end

context "with an fundable participant" do
let(:application) { create(:application, :eligible_for_funded_place, cohort:, course:, lead_provider:) }
let(:existing_declaration) { Declaration.last }

before do
cohort.update! funding_cap: true
application.update! eligible_for_funding: true
end

%w[eligible payable paid].each do |state|
context "when the state is #{state}" do
before { existing_declaration.update!(state:) }
Expand Down Expand Up @@ -248,7 +252,7 @@
end

context "when there are no available output fee statements" do
before { lead_provider.next_output_fee_statement(cohort).update!(output_fee: false) }
before { lead_provider.next_output_fee_statement(cohort).try(:update!, { output_fee: false }) }

context "when the declarations is submitted" do
it { is_expected.to be_valid }
Expand Down Expand Up @@ -299,7 +303,9 @@
it "calls `StatementAttacher`" do
expect_any_instance_of(Declarations::StatementAttacher).to receive(:attach)

subject
travel_to statement.deadline_date - 1.day do
subject
end
end
end

Expand Down

0 comments on commit 2d9c055

Please sign in to comment.