Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CAPT-2030] Fix EY started_at timestamp #3437

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
claim.eligibility.practitioner_claim_started_at = journey_session.answers.practitioner_claim_started_at

Do we need this line? Is this not handled by the set_eligibility_attributes in the base class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I just tried and is needed and evident with failing test
  • the provider has already created the claim and eligibility at this time
  • unlike the other journeys where claim and eligibility are created once
  • therefore it skips main_eligibility on the line above (27)
  • which would have called set_eligibility_attributes which you mentioned

Copy link
Contributor Author

@asmega asmega Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh the existing code its a little bit spaghetti and a bit of a roundabout way. could probably delete most of the stuff and be explicit on what is needed, i think moving away from inheritance would help this

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