Skip to content

Commit

Permalink
Merge pull request #3437 from DFE-Digital/fix-ey-meta-timestamps
Browse files Browse the repository at this point in the history
[CAPT-2030] Fix EY started_at timestamp
  • Loading branch information
asmega authored Nov 28, 2024
2 parents ad5783a + d525be5 commit f06e6ae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
6 changes: 1 addition & 5 deletions app/forms/claim_submission_base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main_eligibility
end

def build_claim
new_or_find_claim.tap do |claim|
Claim.new.tap do |claim|
claim.eligibility ||= main_eligibility
claim.started_at = journey_session.created_at
answers.attributes.each do |name, value|
Expand All @@ -50,10 +50,6 @@ def build_claim
end
end

def new_or_find_claim
Claim.new
end

def eligibilities
@eligibilities ||= journey::POLICIES.map do |policy|
policy::Eligibility.new.tap do |eligibility|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ def generate_policy_options_provided
[]
end

def new_or_find_claim
(Claim.find_by(reference: journey_session.answers.reference_number) || Claim.new).tap do |c|
if c.eligibility
c.eligibility.practitioner_claim_started_at = journey_session.answers.practitioner_claim_started_at
def existing_or_new_claim
Claim.find_by(reference: journey_session.answers.reference_number) || Claim.new
end

def build_claim
existing_or_new_claim.tap do |claim|
claim.eligibility ||= main_eligibility
claim.eligibility.practitioner_claim_started_at = journey_session.answers.practitioner_claim_started_at
answers.attributes.each do |name, value|
if claim.respond_to?(:"#{name}=")
claim.public_send(:"#{name}=", value)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
create(:journey_configuration, :early_years_payment_practitioner)
end

let(:journey) { Journeys::EarlyYearsPayment::Practitioner }
subject { described_class.new(journey_session: journey_session) }

let(:journey) { Journeys::EarlyYearsPayment::Practitioner }
let(:journey_session) { create(:early_years_payment_practitioner_session, answers: answers) }
let(:form) { described_class.new(journey_session: journey_session) }
let!(:existing_claim) { create(:claim, :early_years_provider_submitted, policy: Policies::EarlyYearsPayments) }
let!(:existing_claim) { create(:claim, :early_years_provider_submitted, policy: Policies::EarlyYearsPayments, started_at:) }
let(:started_at) { Time.new(2000, 1, 1, 12) }

describe "#save" do
subject { form.save }

let(:claim) { form.claim }
let(:claim) { subject.claim }
let(:eligibility) { claim.eligibility }
let(:answers) { build(:early_years_payment_practitioner_answers, :submittable, reference_number: existing_claim.reference) }

it { is_expected.to be_truthy }

it "saves some answers into the Claim model" do
subject
subject.save

expect(claim.submitted_at).to be_present
expect(claim.eligibility_type).to eq "Policies::EarlyYearsPayments::Eligibility"
expect(claim.first_name).to eq answers.first_name
Expand All @@ -35,8 +35,15 @@
end

it "saves some answers into the Eligibility model" do
subject
subject.save

expect(eligibility.practitioner_claim_started_at).to be_present
end

it "does not overwrite claim#started_at" do
expect {
subject.save
}.not_to change { existing_claim.reload.started_at }
end
end
end

0 comments on commit f06e6ae

Please sign in to comment.