Skip to content

Commit

Permalink
Merge pull request #1489 from ministryofjustice/EL-1631-remove-check-…
Browse files Browse the repository at this point in the history
…anwers-yml

EL-1631 Remove check_answers.yml file
  • Loading branch information
willc-work authored Sep 5, 2024
2 parents 77e7dae + d9798f0 commit bede3b8
Show file tree
Hide file tree
Showing 42 changed files with 1,758 additions and 683 deletions.
417 changes: 0 additions & 417 deletions app/lib/check_answers_fields.yml

This file was deleted.

36 changes: 36 additions & 0 deletions app/models/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ def under_eighteen?
Steps::Logic.client_under_eighteen?(session_data)
end

def under_eighteen_assets?
Steps::Logic.under_eighteen_assets?(session_data)
end

def under_eighteen_regular_income?
Steps::Logic.under_eighteen_regular_income?(session_data)
end

def aggregated_means?
Steps::Logic.aggregated_means?(session_data)
end

def investments_relevant?
investments_relevant
end
Expand Down Expand Up @@ -147,4 +159,28 @@ def consistent?
Steps::Helper.consistent?(session_data)
end
end

def non_means_tested?
Steps::Logic.non_means_tested?(session_data)
end

def skip_income_questions?
Steps::Logic.skip_income_questions?(session_data)
end

def partner?
Steps::Logic.partner?(session_data)
end

def controlled_clr?
Steps::Logic.controlled_clr?(session_data)
end

def owns_property_with_mortgage_or_loan?
Steps::Logic.owns_property_with_mortgage_or_loan?(session_data)
end

def owns_property_outright?
Steps::Logic.owns_property_outright?(session_data)
end
end
26 changes: 26 additions & 0 deletions app/services/check_answers/benefits_subsection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module CheckAnswers
class BenefitsSubsection
class << self
def tables(check:, status_field_name:, status_attribute_name:, benefits:, benefits_field_name:)
benefit_table =
Table.new(screen: status_field_name, skip_change_link: false, index: nil, disputed?: nil,
fields: [
FieldPresenter.new(table_label: status_field_name, attribute: status_attribute_name, type: :boolean, model: check),
])

benefits_add = (benefits || []).map.with_index do |model, index|
Table.new(screen: benefits_field_name, skip_change_link: false, index:, disputed?: nil,
fields: [
SubFieldPresenter.new(table_label: benefits_field_name, attribute: :benefit_type, type: :number_or_text, model:),
MoneySubFieldPresenter.new(table_label: benefits_field_name, attribute: :benefit_amount, model:, index:, disputed: false),
SubFieldPresenter.new(table_label: benefits_field_name, attribute: :benefit_frequency, type: :frequency, model:),
])
end

[benefit_table] + benefits_add
end
end
end
end
27 changes: 27 additions & 0 deletions app/services/check_answers/employment_subsection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module CheckAnswers
class EmploymentSubsection
class << self
def tables(check:, status_field_name:, incomes:, income_field_name:)
employment_status = Table.new(screen: status_field_name, index: nil,
disputed?: false, skip_change_link: false, fields: [
FieldPresenter.new(table_label: status_field_name, attribute: status_field_name, type: :select, model: check),
])

employments = (incomes || []).map.with_index do |model, index|
Table.new(screen: income_field_name, index:,
disputed?: false, skip_change_link: false,
fields: [
SubFieldPresenter.new(table_label: income_field_name, attribute: :income_type, type: :select, model:),
SubFieldPresenter.new(table_label: income_field_name, attribute: :income_frequency, type: :frequency, model:),
MoneySubFieldPresenter.new(table_label: income_field_name, attribute: :gross_income, index:, model:, disputed: false),
MoneySubFieldPresenter.new(table_label: income_field_name, attribute: :income_tax, index:, model:, disputed: false),
MoneySubFieldPresenter.new(table_label: income_field_name, attribute: :national_insurance, index:, model:, disputed: false),
])
end
[employment_status] + employments
end
end
end
end
26 changes: 26 additions & 0 deletions app/services/check_answers/field_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module CheckAnswers
class FieldPresenter
attr_reader :type

def initialize(table_label:, attribute:, type:, model:)
@table_label = table_label
@attribute = attribute
@type = type
@model = model
end

def screen
nil
end

def value
@model.public_send(@attribute)
end

def label
"#{@table_label}_fields.#{@attribute}"
end
end
end
12 changes: 12 additions & 0 deletions app/services/check_answers/field_with_screen_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module CheckAnswers
class FieldWithScreenPresenter < FieldPresenter
attr_reader :screen

def initialize(table_label:, attribute:, type:, model:, screen:)
super(table_label:, attribute:, type:, model:)
@screen = screen
end
end
end
19 changes: 19 additions & 0 deletions app/services/check_answers/money_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module CheckAnswers
class MoneyPresenter < FieldPresenter
def initialize(table_label:, attribute:, model:, disputed: false)
super(table_label:, attribute:, type: :money, model:)
@disputed = disputed
end

# top level field so never has an index
def index
nil
end

def disputed?
@disputed
end
end
end
17 changes: 17 additions & 0 deletions app/services/check_answers/money_sub_field_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module CheckAnswers
class MoneySubFieldPresenter < SubFieldPresenter
attr_reader :index

def initialize(table_label:, attribute:, model:, index:, disputed:)
super(table_label:, attribute:, type: :money, model:)
@disputed = disputed
@index = index
end

def disputed?
@disputed
end
end
end
12 changes: 12 additions & 0 deletions app/services/check_answers/money_with_frequency_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module CheckAnswers
class MoneyWithFrequencyPresenter < FieldPresenter
attr_reader :frequency_value

def initialize(table_label:, attribute:, model:, frequency_value:)
super(table_label:, attribute:, type: :money_with_frequency, model:)
@frequency_value = frequency_value
end
end
end
16 changes: 16 additions & 0 deletions app/services/check_answers/optional_money_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module CheckAnswers
class OptionalMoneyPresenter < FieldPresenter
attr_reader :relevancy_value

def initialize(table_label:, attribute:, model:, relevancy_value:)
super(table_label:, attribute:, type: :optional_money, model:)
@relevancy_value = relevancy_value
end

def disputed?
false
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module CheckAnswers
class OptionalMoneyWithFrequencyPresenter < FieldPresenter
attr_reader :frequency_value, :relevancy_value

def initialize(table_label:, attribute:, model:, frequency_value:, relevancy_value:)
super(table_label:, attribute:, type: :optional_money_with_frequency, model:)
@frequency_value = frequency_value
@relevancy_value = relevancy_value
end
end
end
43 changes: 43 additions & 0 deletions app/services/check_answers/other_income_subsection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

module CheckAnswers
class OtherIncomeSubsection
class << self
def tables(check:, other_income_field:, attribute_prefix:)
other_income =
Table.new(screen: other_income_field, skip_change_link: false, index: nil, disputed?: nil,
fields: [
OptionalMoneyWithFrequencyPresenter.new(table_label: other_income_field,
attribute: "#{attribute_prefix}friends_or_family_conditional_value".to_sym,
model: check,
frequency_value: check.public_send("#{attribute_prefix}friends_or_family_frequency".to_sym),
relevancy_value: check.public_send("#{attribute_prefix}friends_or_family_relevant".to_sym)),
OptionalMoneyWithFrequencyPresenter.new(table_label: other_income_field,
attribute: "#{attribute_prefix}maintenance_conditional_value".to_sym,
model: check,
frequency_value: check.public_send("#{attribute_prefix}maintenance_frequency".to_sym),
relevancy_value: check.public_send("#{attribute_prefix}maintenance_relevant".to_sym)),
OptionalMoneyWithFrequencyPresenter.new(table_label: other_income_field,
attribute: "#{attribute_prefix}property_or_lodger_conditional_value".to_sym,
model: check,
frequency_value: check.public_send("#{attribute_prefix}property_or_lodger_frequency".to_sym),
relevancy_value: check.public_send("#{attribute_prefix}property_or_lodger_relevant".to_sym)),
OptionalMoneyWithFrequencyPresenter.new(table_label: other_income_field,
attribute: "#{attribute_prefix}pension_conditional_value".to_sym,
model: check,
frequency_value: check.public_send("#{attribute_prefix}pension_frequency".to_sym),
relevancy_value: check.public_send("#{attribute_prefix}pension_relevant".to_sym)),
OptionalMoneyPresenter.new(table_label: other_income_field,
attribute: "#{attribute_prefix}student_finance_conditional_value".to_sym,
model: check,
relevancy_value: check.public_send("#{attribute_prefix}student_finance_relevant".to_sym)),
OptionalMoneyPresenter.new(table_label: other_income_field,
attribute: "#{attribute_prefix}other_conditional_value".to_sym,
model: check,
relevancy_value: check.public_send("#{attribute_prefix}other_relevant".to_sym)),
])
[other_income]
end
end
end
end
32 changes: 32 additions & 0 deletions app/services/check_answers/outgoings_subsection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module CheckAnswers
class OutgoingsSubsection
class << self
def tables(check:, label:, attribute_prefix:)
table = Table.new screen: label,
skip_change_link: false, index: nil, disputed?: nil,
fields: [
if check.eligible_for_childcare_costs?
OptionalMoneyWithFrequencyPresenter.new(table_label: label,
attribute: "#{attribute_prefix}childcare_payments_conditional_value".to_sym,
model: check,
frequency_value: check.public_send("#{attribute_prefix}childcare_payments_frequency".to_sym),
relevancy_value: check.public_send("#{attribute_prefix}childcare_payments_relevant".to_sym))
end,
OptionalMoneyWithFrequencyPresenter.new(table_label: label,
attribute: "#{attribute_prefix}maintenance_payments_conditional_value".to_sym,
model: check,
frequency_value: check.public_send("#{attribute_prefix}maintenance_payments_frequency".to_sym),
relevancy_value: check.public_send("#{attribute_prefix}maintenance_payments_relevant".to_sym)),
OptionalMoneyWithFrequencyPresenter.new(table_label: label,
attribute: "#{attribute_prefix}legal_aid_payments_conditional_value".to_sym,
model: check,
frequency_value: check.public_send("#{attribute_prefix}legal_aid_payments_frequency".to_sym),
relevancy_value: check.public_send("#{attribute_prefix}legal_aid_payments_relevant".to_sym)),
].compact
[table]
end
end
end
end
30 changes: 30 additions & 0 deletions app/services/check_answers/partner_dependant_field_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module CheckAnswers
class PartnerDependantFieldPresenter
attr_reader :type

def initialize(table_label:, attribute:, type:, model:)
@table_label = table_label
@attribute = attribute
@type = type
@model = model
end

def screen
nil
end

def value
@model.public_send(@attribute)
end

def label
if @model.partner
"#{@table_label}_fields.#{@attribute}_partner"
else
"#{@table_label}_fields.#{@attribute}"
end
end
end
end
Loading

0 comments on commit bede3b8

Please sign in to comment.