From 03b04d5eeef3cbe1b2fab243bdf4a4e2dda842c2 Mon Sep 17 00:00:00 2001 From: Joel Sugarman Date: Mon, 16 Dec 2024 09:23:56 +0000 Subject: [PATCH] AP-5531: Add appeal court type quesion 3 and 4 Add the controllers, forms, views and steps to complete the ECCT question flow as per the designs. --- .../base_appeal_court_types_controller.rb | 35 ++++ .../first_appeal_court_types_controller.rb | 11 ++ .../second_appeal_court_types_controller.rb | 11 ++ .../base_appeal_court_type_form.rb | 21 +++ .../first_appeal_court_type_form.rb | 15 ++ .../original_judge_level_form.rb | 14 ++ .../second_appeal_court_type_form.rb | 15 ++ .../second_appeal_form.rb | 16 +- app/services/flow/flows/provider_merits.rb | 2 + .../first_appeal_court_types_step.rb | 13 ++ .../original_judge_levels_step.rb | 33 ++-- .../second_appeal_court_types_step.rb | 13 ++ .../provider_merits/second_appeals_step.rb | 7 +- .../first_appeal_court_types/show.html.erb | 25 +++ .../second_appeal_court_types/show.html.erb | 25 +++ .../check_answers/_second_appeal.html.erb | 9 +- config/locales/en/activemodel.yml | 3 + config/locales/en/providers.yml | 38 ++++- config/locales/en/shared.yml | 1 + config/routes.rb | 2 + .../providers/check_merits_answers.feature | 44 ++++- .../merits_appeal_question_flow.feature | 62 ++++++- .../step_definitions/check_merits_answers.rb | 1 + spec/factories/legal_aid_applications.rb | 4 +- .../first_appeal_court_type_form_spec.rb | 28 +++ .../original_judge_level_form_spec.rb | 11 ++ .../second_appeal_court_type_form_spec.rb | 30 ++++ .../second_appeal_form_spec.rb | 33 +++- ...ed_examples_for_appeal_court_type_forms.rb | 111 ++++++++++++ ...irst_appeal_court_types_controller_spec.rb | 159 ++++++++++++++++++ ...cond_appeal_court_types_controller_spec.rb | 159 ++++++++++++++++++ .../first_appeal_court_types_step_spec.rb | 29 ++++ .../original_judge_levels_step_spec.rb | 62 ++++++- .../second_appeal_court_types_step_spec.rb | 29 ++++ .../second_appeals_step_spec.rb | 6 +- 35 files changed, 1015 insertions(+), 62 deletions(-) create mode 100644 app/controllers/providers/application_merits_task/base_appeal_court_types_controller.rb create mode 100644 app/controllers/providers/application_merits_task/first_appeal_court_types_controller.rb create mode 100644 app/controllers/providers/application_merits_task/second_appeal_court_types_controller.rb create mode 100644 app/forms/providers/application_merits_task/base_appeal_court_type_form.rb create mode 100644 app/forms/providers/application_merits_task/first_appeal_court_type_form.rb create mode 100644 app/forms/providers/application_merits_task/second_appeal_court_type_form.rb create mode 100644 app/services/flow/steps/provider_merits/first_appeal_court_types_step.rb create mode 100644 app/services/flow/steps/provider_merits/second_appeal_court_types_step.rb create mode 100644 app/views/providers/application_merits_task/first_appeal_court_types/show.html.erb create mode 100644 app/views/providers/application_merits_task/second_appeal_court_types/show.html.erb create mode 100644 spec/forms/providers/application_merits_task/first_appeal_court_type_form_spec.rb create mode 100644 spec/forms/providers/application_merits_task/second_appeal_court_type_form_spec.rb create mode 100644 spec/forms/providers/application_merits_task/shared_examples_for_appeal_court_type_forms.rb create mode 100644 spec/requests/providers/application_merits_task/first_appeal_court_types_controller_spec.rb create mode 100644 spec/requests/providers/application_merits_task/second_appeal_court_types_controller_spec.rb create mode 100644 spec/services/flow/steps/provider_merits/first_appeal_court_types_step_spec.rb create mode 100644 spec/services/flow/steps/provider_merits/second_appeal_court_types_step_spec.rb diff --git a/app/controllers/providers/application_merits_task/base_appeal_court_types_controller.rb b/app/controllers/providers/application_merits_task/base_appeal_court_types_controller.rb new file mode 100644 index 0000000000..8c6206d365 --- /dev/null +++ b/app/controllers/providers/application_merits_task/base_appeal_court_types_controller.rb @@ -0,0 +1,35 @@ +module Providers + module ApplicationMeritsTask + class BaseAppealCourtTypesController < ProviderBaseController + def show + @form = form.new(model: appeal) + end + + def update + @form = form.new(form_params) + + render :show unless update_task_save_continue_or_draft(:application, :second_appeal) + end + + private + + # :nocov: + def form + raise "Implement in subclass" + end + # :nocov: + + def appeal + legal_aid_application.appeal + end + + def form_params + merge_with_model(appeal) do + return {} unless params[:application_merits_task_appeal] + + params.require(:application_merits_task_appeal).permit(:court_type) + end + end + end + end +end diff --git a/app/controllers/providers/application_merits_task/first_appeal_court_types_controller.rb b/app/controllers/providers/application_merits_task/first_appeal_court_types_controller.rb new file mode 100644 index 0000000000..d66f48ffe3 --- /dev/null +++ b/app/controllers/providers/application_merits_task/first_appeal_court_types_controller.rb @@ -0,0 +1,11 @@ +module Providers + module ApplicationMeritsTask + class FirstAppealCourtTypesController < BaseAppealCourtTypesController + private + + def form + FirstAppealCourtTypeForm + end + end + end +end diff --git a/app/controllers/providers/application_merits_task/second_appeal_court_types_controller.rb b/app/controllers/providers/application_merits_task/second_appeal_court_types_controller.rb new file mode 100644 index 0000000000..7d3923ffa2 --- /dev/null +++ b/app/controllers/providers/application_merits_task/second_appeal_court_types_controller.rb @@ -0,0 +1,11 @@ +module Providers + module ApplicationMeritsTask + class SecondAppealCourtTypesController < BaseAppealCourtTypesController + private + + def form + SecondAppealCourtTypeForm + end + end + end +end diff --git a/app/forms/providers/application_merits_task/base_appeal_court_type_form.rb b/app/forms/providers/application_merits_task/base_appeal_court_type_form.rb new file mode 100644 index 0000000000..52c1f6c9c9 --- /dev/null +++ b/app/forms/providers/application_merits_task/base_appeal_court_type_form.rb @@ -0,0 +1,21 @@ +module Providers + module ApplicationMeritsTask + class BaseAppealCourtTypeForm < BaseForm + SECOND_APPEAL_COURT_TYPES = %w[ + court_of_appeal + supreme_court + ].freeze + + FIRST_APPEAL_COURT_TYPES = + SECOND_APPEAL_COURT_TYPES + %w[ + other_court + ].freeze + + # :nocov: + def court_types + raise "Implement in subclass" + end + # :nocov: + end + end +end diff --git a/app/forms/providers/application_merits_task/first_appeal_court_type_form.rb b/app/forms/providers/application_merits_task/first_appeal_court_type_form.rb new file mode 100644 index 0000000000..35385e57e6 --- /dev/null +++ b/app/forms/providers/application_merits_task/first_appeal_court_type_form.rb @@ -0,0 +1,15 @@ +module Providers + module ApplicationMeritsTask + class FirstAppealCourtTypeForm < BaseAppealCourtTypeForm + form_for ::ApplicationMeritsTask::Appeal + + attr_accessor :court_type + + validates :court_type, presence: true, inclusion: { in: FIRST_APPEAL_COURT_TYPES }, unless: :draft? + + def court_types + FIRST_APPEAL_COURT_TYPES + end + end + end +end diff --git a/app/forms/providers/application_merits_task/original_judge_level_form.rb b/app/forms/providers/application_merits_task/original_judge_level_form.rb index 9f9f841498..e63087f40e 100644 --- a/app/forms/providers/application_merits_task/original_judge_level_form.rb +++ b/app/forms/providers/application_merits_task/original_judge_level_form.rb @@ -5,6 +5,8 @@ class OriginalJudgeLevelForm < BaseForm attr_accessor :original_judge_level + set_callback :save, :before, :sync_court_type + JUDGE_LEVELS = %w[ family_panel_magistrates deputy_district_judge @@ -18,6 +20,18 @@ class OriginalJudgeLevelForm < BaseForm def judge_levels JUDGE_LEVELS end + + private + + def sync_court_type + if original_judge_level_changed? + attributes["court_type"] = nil + end + end + + def original_judge_level_changed? + attributes["original_judge_level"] != model.original_judge_level + end end end end diff --git a/app/forms/providers/application_merits_task/second_appeal_court_type_form.rb b/app/forms/providers/application_merits_task/second_appeal_court_type_form.rb new file mode 100644 index 0000000000..7ccdc76cc4 --- /dev/null +++ b/app/forms/providers/application_merits_task/second_appeal_court_type_form.rb @@ -0,0 +1,15 @@ +module Providers + module ApplicationMeritsTask + class SecondAppealCourtTypeForm < BaseAppealCourtTypeForm + form_for ::ApplicationMeritsTask::Appeal + + attr_accessor :court_type + + validates :court_type, presence: true, inclusion: { in: SECOND_APPEAL_COURT_TYPES }, unless: :draft? + + def court_types + SECOND_APPEAL_COURT_TYPES + end + end + end +end diff --git a/app/forms/providers/application_merits_task/second_appeal_form.rb b/app/forms/providers/application_merits_task/second_appeal_form.rb index c6b2efd744..f7107776b8 100644 --- a/app/forms/providers/application_merits_task/second_appeal_form.rb +++ b/app/forms/providers/application_merits_task/second_appeal_form.rb @@ -7,19 +7,19 @@ class SecondAppealForm < BaseForm validates :second_appeal, presence: true, unless: :draft? - set_callback :save, :before, :sync_original_judge_level - - # Alternative callback - # set_callback :validation, :after, :sync_original_judge_level + set_callback :save, :before, :sync_second_appeal_details private - def sync_original_judge_level - attributes["original_judge_level"] = nil if second_appeal? + def sync_second_appeal_details + if second_appeal_changed? + attributes["original_judge_level"] = nil + attributes["court_type"] = nil + end end - def second_appeal? - attributes["second_appeal"] == "true" + def second_appeal_changed? + attributes["second_appeal"] != model.second_appeal.to_s end end end diff --git a/app/services/flow/flows/provider_merits.rb b/app/services/flow/flows/provider_merits.rb index 2d63e2f153..e18383bd63 100644 --- a/app/services/flow/flows/provider_merits.rb +++ b/app/services/flow/flows/provider_merits.rb @@ -23,6 +23,8 @@ class ProviderMerits < FlowSteps nature_of_urgencies: Steps::ProviderMerits::NatureOfUrgenciesStep, matter_opposed_reasons: Steps::ProviderMerits::MatterOpposedReasonsStep, second_appeals: Steps::ProviderMerits::SecondAppealsStep, + second_appeal_court_types: Steps::ProviderMerits::SecondAppealCourtTypesStep, + first_appeal_court_types: Steps::ProviderMerits::FirstAppealCourtTypesStep, original_judge_levels: Steps::ProviderMerits::OriginalJudgeLevelsStep, chances_of_success: Steps::ProviderMerits::ChancesOfSuccessStep, success_prospects: Steps::ProviderMerits::SuccessProspectsStep, diff --git a/app/services/flow/steps/provider_merits/first_appeal_court_types_step.rb b/app/services/flow/steps/provider_merits/first_appeal_court_types_step.rb new file mode 100644 index 0000000000..e185a43e70 --- /dev/null +++ b/app/services/flow/steps/provider_merits/first_appeal_court_types_step.rb @@ -0,0 +1,13 @@ +module Flow + module Steps + module ProviderMerits + FirstAppealCourtTypesStep = Step.new( + path: ->(application) { Steps.urls.providers_legal_aid_application_first_appeal_court_type_path(application) }, + forward: lambda do |application| + Flow::MeritsLoop.forward_flow(application, :application) + end, + check_answers: :check_merits_answers, + ) + end + end +end diff --git a/app/services/flow/steps/provider_merits/original_judge_levels_step.rb b/app/services/flow/steps/provider_merits/original_judge_levels_step.rb index 8c152aac65..a756081d36 100644 --- a/app/services/flow/steps/provider_merits/original_judge_levels_step.rb +++ b/app/services/flow/steps/provider_merits/original_judge_levels_step.rb @@ -4,28 +4,19 @@ module ProviderMerits OriginalJudgeLevelsStep = Step.new( path: ->(application) { Steps.urls.providers_legal_aid_application_original_judge_level_path(application) }, forward: lambda do |application| - Flow::MeritsLoop.forward_flow(application, :application) - # TODO: AP-5531/5532 - should goto question 4 or Next question - # NOTE: should/could use same form but setup with different options/content for "second" or "first" appeal court - # - # if application.appeal.original_judge_level.in?(%i[family_panel_magistrates deputy_district_judge district_judge]) - # :appeal_court - # elsif application.appeal.original_judge_level.in?(%i[recorder_circuit_judge high_court_judge]) - # :second_appeal_court - # else - # Flow::MeritsLoop.forward_flow(application, :application) - # end - # - # OR - # - # if application.appeal.original_judge_level.present? - # :appeal_court # And let that form handle difference between 3 and 4 based on second_appeal true (question 3) or false (question 4) - # else - # Flow::MeritsLoop.forward_flow(application, :application) - # end + if application.appeal.original_judge_level.in?(%w[recorder_circuit_judge high_court_judge]) + :first_appeal_court_types + else + Flow::MeritsLoop.forward_flow(application, :application) + end + end, + check_answers: lambda do |application| + if application.appeal.original_judge_level.in?(%w[recorder_circuit_judge high_court_judge]) + :first_appeal_court_types + else + :check_merits_answers + end end, - # TODO: AP-5531/5532 - should goto question 4 or Next question - check_answers: :check_merits_answers, ) end end diff --git a/app/services/flow/steps/provider_merits/second_appeal_court_types_step.rb b/app/services/flow/steps/provider_merits/second_appeal_court_types_step.rb new file mode 100644 index 0000000000..39dc198d66 --- /dev/null +++ b/app/services/flow/steps/provider_merits/second_appeal_court_types_step.rb @@ -0,0 +1,13 @@ +module Flow + module Steps + module ProviderMerits + SecondAppealCourtTypesStep = Step.new( + path: ->(application) { Steps.urls.providers_legal_aid_application_second_appeal_court_type_path(application) }, + forward: lambda do |application| + Flow::MeritsLoop.forward_flow(application, :application) + end, + check_answers: :check_merits_answers, + ) + end + end +end diff --git a/app/services/flow/steps/provider_merits/second_appeals_step.rb b/app/services/flow/steps/provider_merits/second_appeals_step.rb index 505eb5a157..fc16e4b4b1 100644 --- a/app/services/flow/steps/provider_merits/second_appeals_step.rb +++ b/app/services/flow/steps/provider_merits/second_appeals_step.rb @@ -5,17 +5,14 @@ module ProviderMerits path: ->(application) { Steps.urls.providers_legal_aid_application_second_appeal_path(application) }, forward: lambda do |application| if application.appeal.second_appeal? - # TODO: AP-5531/5532 - should go to question 3 "Which court will the second appeal be heard in?" - Flow::MeritsLoop.forward_flow(application, :application) + :second_appeal_court_types else :original_judge_levels end end, check_answers: lambda do |application| if application.appeal.second_appeal? - # TODO: AP-5531/5532 - should go to question 3 "Which court will the second appeal be heard in?" - # :appeal_court - :check_merits_answers + :second_appeal_court_types else :original_judge_levels end diff --git a/app/views/providers/application_merits_task/first_appeal_court_types/show.html.erb b/app/views/providers/application_merits_task/first_appeal_court_types/show.html.erb new file mode 100644 index 0000000000..3eda32a279 --- /dev/null +++ b/app/views/providers/application_merits_task/first_appeal_court_types/show.html.erb @@ -0,0 +1,25 @@ +<%= form_with( + url: providers_legal_aid_application_first_appeal_court_type_path, + model: @form, + method: :patch, + local: true, + ) do |form| %> + <%= page_template page_title: t(".page_title"), + template: :basic, + form: do %> + + <%= form.govuk_radio_buttons_fieldset(:court_type, + legend: { text: content_for(:page_title), tag: "h1", size: "xl" }, + hint: { text: t(".hint") })do %> + + <% form.object.court_types.each_with_index do |court_type, idx| %> + <%= form.govuk_radio_button :court_type, + court_type, + link_errors: idx.zero?, + label: { text: t(".#{court_type}.label") } %> + <% end %> + <% end %> + + <%= next_action_buttons(show_draft: true, form:) %> + <% end %> +<% end %> diff --git a/app/views/providers/application_merits_task/second_appeal_court_types/show.html.erb b/app/views/providers/application_merits_task/second_appeal_court_types/show.html.erb new file mode 100644 index 0000000000..c2f37276c4 --- /dev/null +++ b/app/views/providers/application_merits_task/second_appeal_court_types/show.html.erb @@ -0,0 +1,25 @@ +<%= form_with( + url: providers_legal_aid_application_second_appeal_court_type_path, + model: @form, + method: :patch, + local: true, + ) do |form| %> + <%= page_template page_title: t(".page_title"), + template: :basic, + form: do %> + + <%= form.govuk_radio_buttons_fieldset(:court_type, + legend: { text: content_for(:page_title), tag: "h1", size: "xl" }, + hint: { text: t(".hint") })do %> + + <% form.object.court_types.each_with_index do |court_type, idx| %> + <%= form.govuk_radio_button :court_type, + court_type, + link_errors: idx.zero?, + label: { text: t(".#{court_type}.label") } %> + <% end %> + <% end %> + + <%= next_action_buttons(show_draft: true, form:) %> + <% end %> +<% end %> diff --git a/app/views/shared/check_answers/_second_appeal.html.erb b/app/views/shared/check_answers/_second_appeal.html.erb index d95adbde85..7b0058594e 100644 --- a/app/views/shared/check_answers/_second_appeal.html.erb +++ b/app/views/shared/check_answers/_second_appeal.html.erb @@ -15,7 +15,14 @@ <% unless @legal_aid_application.appeal.second_appeal? %> <%= summary_list.with_row(html_attributes: { id: "app-check-your-answers__original_judge_level-row" }) do |row| %> <%= row.with_key(text: t(".original_judge_level_question"), classes: "govuk-!-width-one-half") %> - <%= row.with_value(text: t("providers.application_merits_task.original_judge_levels.show.#{@legal_aid_application.appeal.original_judge_level}.label")) %> + <%= row.with_value(text: t("original_judge_levels.#{@legal_aid_application.appeal.original_judge_level}")) %> + <% end %> + <% end %> + + <% if @legal_aid_application.appeal.court_type? %> + <%= summary_list.with_row(html_attributes: { id: "app-check-your-answers__court_type-row" }) do |row| %> + <%= row.with_key(text: t(".court_type_question"), classes: "govuk-!-width-one-half") %> + <%= row.with_value(text: t("appeal_court_types.#{@legal_aid_application.appeal.court_type}")) %> <% end %> <% end %> <% end %> diff --git a/config/locales/en/activemodel.yml b/config/locales/en/activemodel.yml index a081a7803e..14b4afc3cc 100644 --- a/config/locales/en/activemodel.yml +++ b/config/locales/en/activemodel.yml @@ -295,6 +295,9 @@ en: original_judge_level: blank: Select what level of judge heard the original case inclusion: Select what level of judge heard the original case from the available list + court_type: + blank: Select which court the appeal will be heard in + inclusion: Select which court the appeal will be heard in from the available list opponent: attributes: police_notified_details_true: diff --git a/config/locales/en/providers.yml b/config/locales/en/providers.yml index 5cb896a41f..48ba937b29 100644 --- a/config/locales/en/providers.yml +++ b/config/locales/en/providers.yml @@ -1,5 +1,15 @@ --- en: + appeal_court_types: + supreme_court: &supreme_court Supreme court + court_of_appeal: &court_of_appeal Court of appeal + other_court: &other_court Any other court + original_judge_levels: + family_panel_magistrates: &family_panel_magistrates Family Panel Magistrates (Justices/JP) + deputy_district_judge: &deputy_district_judge Deputy District Judge (DDJ) + district_judge: &district_judge District Judge (DJ) + recorder_circuit_judge: &recorder_circuit_judge Recorder Circuit Judge (HHJ) + high_court_judge: &high_court_judge High Court Judge (J) providers: previous_references: show: @@ -664,25 +674,43 @@ en: show: page_title: Is this a second appeal? hint: This question will help us decide if a specialist caseworker should review your application. + second_appeal_court_types: + show: + page_title: Which court will the second appeal be heard in? + hint: This question will help us decide if a specialist caseworker should review your application. + court_of_appeal: + label: *court_of_appeal + supreme_court: + label: *supreme_court original_judge_levels: show: page_title: What level of judge heard the original case? hint: This question will help us decide if a specialist caseworker should review your application. family_panel_magistrates: - label: Family Panel Magistrates (Justices/JP) + label: *family_panel_magistrates label_hint: "" deputy_district_judge: - label: Deputy District Judge (DDJ) + label: *deputy_district_judge label_hint: "" district_judge: - label: District Judge (DJ) + label: *district_judge label_hint: "" recorder_circuit_judge: - label: Recorder Circuit Judge (HHJ) + label: *recorder_circuit_judge label_hint: "" high_court_judge: - label: High Court Judge (J) + label: *high_court_judge label_hint: Including those sitting as such with s9 ticket + first_appeal_court_types: + show: + page_title: Which court will the appeal be heard in? + hint: This question will help us decide if a specialist caseworker should review your application. + court_of_appeal: + label: *court_of_appeal + supreme_court: + label: *supreme_court + other_court: + label: *other_court partners: about_financial_means: show: diff --git a/config/locales/en/shared.yml b/config/locales/en/shared.yml index 19586db0c8..4651ceb91a 100644 --- a/config/locales/en/shared.yml +++ b/config/locales/en/shared.yml @@ -546,6 +546,7 @@ en: heading: Second appeal second_appeal_question: Second appeal? original_judge_level_question: Original case heard by + court_type_question: Appeal will be heard in merits_proceeding_section: attempts_to_settle: What attempts have been made to settle the matter? chances_of_success_details: Details on the chance of a successful outcome diff --git a/config/routes.rb b/config/routes.rb index a66a4c6a9f..5bad9bd23b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -370,6 +370,8 @@ end resource :second_appeal, only: %i[show update] resource :original_judge_level, only: %i[show update], path: "original_case_judge_level" + resource :first_appeal_court_type, only: %i[show update], path: "appeal_court_type" + resource :second_appeal_court_type, only: %i[show update] end end diff --git a/features/providers/check_merits_answers.feature b/features/providers/check_merits_answers.feature index c0bb96b4fc..d6fc66c587 100644 --- a/features/providers/check_merits_answers.feature +++ b/features/providers/check_merits_answers.feature @@ -34,7 +34,11 @@ Feature: Check merits answers | question | answer | | Second appeal? | No | | Original case heard by | Recorder Circuit Judge (HHJ) | + | Appeal will be heard in | Any other court | + ################################# + # ECCT question 1 and 3 only needed + ################################# When I click Check Your Answers Change link for 'second_appeal_heading' Then I should be on a page with title "Is this a second appeal?" And I should be on a page showing "Is this a second appeal?" @@ -42,17 +46,24 @@ Feature: Check merits answers When I choose "Yes" And I click "Save and continue" + Then I should be on the 'second_appeal_court_type' page showing 'Which court will the second appeal be heard in?' + + When I choose "Supreme court" + And I click "Save and continue" - # TODO: AP-5531/5532 - should go to question 3 "Which court will the second appeal be heard in?" Then I should be on the 'check_merits_answers' page showing 'Check your answers' And the "Second appeal" check your answers section should contain: | question | answer | | Second appeal? | Yes | + | Appeal will be heard in | Supreme court | And the "Second appeal" check your answers section should not contain: | question | | Original case heard by | + ################################# + # ECCT question 1 and 2 only needed + ################################# When I click Check Your Answers Change link for 'second_appeal_heading' Then I should be on a page with title "Is this a second appeal?" @@ -63,10 +74,6 @@ Feature: Check merits answers And I should be on a page showing "What level of judge heard the original case?" And I should see "This question will help us decide if a specialist caseworker should review your application." - # Test the old value was cleared - When I click "Save and continue" - Then I should see govuk error summary "Select what level of judge heard the original case" - When I choose "Deputy District Judge (DDJ)" And I click "Save and continue" Then I should be on the 'check_merits_answers' page showing 'Check your answers' @@ -74,3 +81,30 @@ Feature: Check merits answers | question | answer | | Second appeal? | No | | Original case heard by | Deputy District Judge (DDJ) | + + And the "Second appeal" check your answers section should not contain: + | question | + | Appeal will be heard in | + + ##################################### + # ECCT question 1, 2 and 4 needed + ##################################### + When I click Check Your Answers Change link for 'second_appeal_heading' + Then I should be on a page with title "Is this a second appeal?" + + When I choose "No" + And I click "Save and continue" + Then I should be on a page with title "What level of judge heard the original case?" + + When I choose "High Court Judge (J)" + And I click "Save and continue" + Then I should be on the 'appeal_court_type' page showing 'Which court will the appeal be heard in?' + + When I choose "Any other court" + And I click "Save and continue" + Then I should be on the 'check_merits_answers' page showing 'Check your answers' + And the "Second appeal" check your answers section should contain: + | question | answer | + | Second appeal? | No | + | Original case heard by | High Court Judge (J) | + | Appeal will be heard in | Any other court | diff --git a/features/providers/public_law_family/merits_appeal_question_flow.feature b/features/providers/public_law_family/merits_appeal_question_flow.feature index 323a84da49..f10b772464 100644 --- a/features/providers/public_law_family/merits_appeal_question_flow.feature +++ b/features/providers/public_law_family/merits_appeal_question_flow.feature @@ -65,6 +65,13 @@ Feature: Public law family merits appeal question flow # Original (case) judge level ############################# Then I should be on the 'original_case_judge_level' page showing 'What level of judge heard the original case?' + And I should see "This question will help us decide if a specialist caseworker should review your application." + And I should be on a page showing "Family Panel Magistrates (Justices/JP)" + And I should be on a page showing "Deputy District Judge (DDJ)" + And I should be on a page showing "District Judge (DJ)" + And I should be on a page showing "Recorder Circuit Judge (HHJ)" + And I should be on a page showing "High Court Judge (J)" + And I should see "Including those sitting as such with s9 ticket" # Test the error When I click "Save and continue" @@ -73,7 +80,21 @@ Feature: Public law family merits appeal question flow When I choose "Recorder Circuit Judge (HHJ)" And I click "Save and continue" - # TODO: 5532 - should go to appeal court type question 4 or next merit loop flow question + ############################# + # First appeal court type + ############################# + Then I should be on the 'appeal_court_type' page showing 'Which court will the appeal be heard in?' + And I should see "This question will help us decide if a specialist caseworker should review your application." + And I should see "Court of appeal" + And I should see "Supreme court" + And I should see "Any other court" + + # Test the error + And I click "Save and continue" + Then I should see govuk error summary "Select which court the appeal will be heard in" + + When I choose "Any other court" + And I click "Save and continue" Then I should be on the 'merits_task_list' page showing 'Provide details of the case' ############################ @@ -85,7 +106,21 @@ Feature: Public law family merits appeal question flow When I choose "Yes" And I click "Save and continue" - # TODO: 5531 - should go to appeal court type question 3 + ############################# + # Second appeal court type + ############################# + Then I should be on the 'second_appeal_court_type' page showing 'Which court will the second appeal be heard in?' + And I should see "This question will help us decide if a specialist caseworker should review your application." + And I should see "Court of appeal" + And I should see "Supreme court" + And I should not see "Any other court" + + # Test the error + And I click "Save and continue" + Then I should see govuk error summary "Select which court the appeal will be heard in" + + When I choose "Court of appeal" + And I click "Save and continue" Then I should be on the 'merits_task_list' page showing 'Provide details of the case' ############################ @@ -104,3 +139,26 @@ Feature: Public law family merits appeal question flow Then I should be on the 'original_case_judge_level' page showing 'What level of judge heard the original case?' When I click "Save and continue" Then I should see govuk error summary "Select what level of judge heard the original case" + + When I choose "High Court Judge (J)" + And I click "Save and continue" + + ################################ + # First appeal court + # Test the old value was cleared + ################################ + Then I should be on the 'appeal_court_type' page showing 'Which court will the appeal be heard in?' + When I click "Save and continue" + Then I should see govuk error summary "Select which court the appeal will be heard in" + + + ################################ + # Original (case) judge level + # Test next question flow + ################################ + When I click link "Back" + Then I should be on the 'original_case_judge_level' page showing 'What level of judge heard the original case?' + + When I choose "Family Panel Magistrates (Justices/JP)" + And I click "Save and continue" + Then I should be on the 'merits_task_list' page showing 'Provide details of the case' diff --git a/features/step_definitions/check_merits_answers.rb b/features/step_definitions/check_merits_answers.rb index 094c7765f3..966dc0a9f8 100644 --- a/features/step_definitions/check_merits_answers.rb +++ b/features/step_definitions/check_merits_answers.rb @@ -14,6 +14,7 @@ set_lead_proceeding: :pbm01a, second_appeal: false, original_judge_level: "recorder_circuit_judge", + court_type: "other_court", ) create(:legal_framework_merits_task_list, :pbm01a_as_applicant, legal_aid_application: @legal_aid_application) diff --git a/spec/factories/legal_aid_applications.rb b/spec/factories/legal_aid_applications.rb index 418888ae58..726b0864df 100644 --- a/spec/factories/legal_aid_applications.rb +++ b/spec/factories/legal_aid_applications.rb @@ -654,13 +654,15 @@ transient do second_appeal { nil } original_judge_level { nil } + court_type { nil } end after(:create) do |application, evaluator| create(:appeal, legal_aid_application: application, second_appeal: evaluator.second_appeal, - original_judge_level: evaluator.original_judge_level) + original_judge_level: evaluator.original_judge_level, + court_type: evaluator.court_type) end end diff --git a/spec/forms/providers/application_merits_task/first_appeal_court_type_form_spec.rb b/spec/forms/providers/application_merits_task/first_appeal_court_type_form_spec.rb new file mode 100644 index 0000000000..c34efed075 --- /dev/null +++ b/spec/forms/providers/application_merits_task/first_appeal_court_type_form_spec.rb @@ -0,0 +1,28 @@ +require "rails_helper" +require_relative "shared_examples_for_appeal_court_type_forms" + +RSpec.describe Providers::ApplicationMeritsTask::FirstAppealCourtTypeForm do + let(:appeal) { create(:appeal, second_appeal: false, court_type: nil) } + + let(:params) do + { + model: appeal, + court_type:, + } + end + + it_behaves_like "appeal court type selector form" + + # NOTE: This tests difference from shared validation and saving logic only + describe "#validate" do + subject(:form) { described_class.new(params) } + + context "when court_type is other_court" do + let(:court_type) { "other_court" } + + it "is valid" do + expect(form).to be_valid + end + end + end +end diff --git a/spec/forms/providers/application_merits_task/original_judge_level_form_spec.rb b/spec/forms/providers/application_merits_task/original_judge_level_form_spec.rb index b6cff5c9d5..71be878480 100644 --- a/spec/forms/providers/application_merits_task/original_judge_level_form_spec.rb +++ b/spec/forms/providers/application_merits_task/original_judge_level_form_spec.rb @@ -79,6 +79,17 @@ .to("district_judge") end end + + context "when value changed and court_type already exists" do + let(:appeal) { create(:appeal, original_judge_level: "high_court_judge", court_type: "other_court") } + let(:original_judge_level) { "district_judge" } + + it "clears the court_type" do + expect { save_form }.to change { appeal.reload.court_type } + .from("other_court") + .to(nil) + end + end end describe "#save_as_draft" do diff --git a/spec/forms/providers/application_merits_task/second_appeal_court_type_form_spec.rb b/spec/forms/providers/application_merits_task/second_appeal_court_type_form_spec.rb new file mode 100644 index 0000000000..255b190809 --- /dev/null +++ b/spec/forms/providers/application_merits_task/second_appeal_court_type_form_spec.rb @@ -0,0 +1,30 @@ +require "rails_helper" +require_relative "shared_examples_for_appeal_court_type_forms" + +RSpec.describe Providers::ApplicationMeritsTask::SecondAppealCourtTypeForm do + let(:appeal) { create(:appeal, second_appeal: true, court_type: nil) } + + let(:params) do + { + model: appeal, + court_type:, + } + end + + it_behaves_like "appeal court type selector form" + + # NOTE: This tests difference from shared validation and saving logic only + describe "#validate" do + subject(:form) { described_class.new(params) } + + context "when court_type is other_court" do + let(:court_type) { "other_court" } + + it "is invalid" do + expect(form).not_to be_valid + expect(form.errors).to be_added(:court_type, :inclusion, value: "other_court") + expect(form.errors.messages[:court_type]).to include("Select which court the appeal will be heard in from the available list") + end + end + end +end diff --git a/spec/forms/providers/application_merits_task/second_appeal_form_spec.rb b/spec/forms/providers/application_merits_task/second_appeal_form_spec.rb index e1d950d505..f518ecb925 100644 --- a/spec/forms/providers/application_merits_task/second_appeal_form_spec.rb +++ b/spec/forms/providers/application_merits_task/second_appeal_form_spec.rb @@ -59,14 +59,39 @@ end end - context "when second_appeal previously false and original_judge_level exists" do - let(:appeal) { create(:appeal, second_appeal: false, original_judge_level: "district_judge") } + context "when second_appeal previously false and original_judge_level and appeal court_type exists" do + let(:appeal) do + create(:appeal, + second_appeal: false, + original_judge_level: "recorder_circuit_judge", + court_type: "other_court") + end - context "when second_appeal changed to true" do + context "when second_appeal changed" do let(:second_appeal) { "true" } it "clears original_judge_level" do - expect { save_form }.to change { appeal.reload.original_judge_level }.from("district_judge").to(nil) + expect { save_form }.to change { appeal.reload.original_judge_level }.from("recorder_circuit_judge").to(nil) + end + + it "clears court_type" do + expect { save_form }.to change { appeal.reload.court_type }.from("other_court").to(nil) + end + end + end + + context "when second_appeal previously true and appeal court_type exists" do + let(:appeal) do + create(:appeal, + second_appeal: true, + court_type: "court_of_appeal") + end + + context "when second_appeal changed" do + let(:second_appeal) { "false" } + + it "clears court_type" do + expect { save_form }.to change { appeal.reload.court_type }.from("court_of_appeal").to(nil) end end end diff --git a/spec/forms/providers/application_merits_task/shared_examples_for_appeal_court_type_forms.rb b/spec/forms/providers/application_merits_task/shared_examples_for_appeal_court_type_forms.rb new file mode 100644 index 0000000000..53f6274550 --- /dev/null +++ b/spec/forms/providers/application_merits_task/shared_examples_for_appeal_court_type_forms.rb @@ -0,0 +1,111 @@ +RSpec.shared_examples "appeal court type selector form" do + let(:params) do + { + model: appeal, + court_type:, + } + end + + describe "#validate" do + subject(:form) { described_class.new(params) } + + context "when court_type is supreme_court" do + let(:court_type) { "supreme_court" } + + it "is valid" do + expect(form).to be_valid + end + end + + context "when court_type is court_of_appeal" do + let(:court_type) { "court_of_appeal" } + + it "is valid" do + expect(form).to be_valid + end + end + + context "when court_type is blank" do + let(:court_type) { nil } + + it "is invalid" do + expect(form).not_to be_valid + expect(form.errors).to be_added(:court_type, :blank) + expect(form.errors.messages[:court_type]).to include("Select which court the appeal will be heard in") + end + end + + context "when court_type is invalid value" do + let(:court_type) { "foobar" } + + it "is invalid" do + expect(form).not_to be_valid + expect(form.errors).to be_added(:court_type, :inclusion, value: "foobar") + expect(form.errors.messages[:court_type]).to include("Select which court the appeal will be heard in from the available list") + end + end + end + + describe "#save" do + subject(:save_form) { described_class.new(params).save } + + context "when the form is blank" do + let(:court_type) { nil } + + it "does not update the record" do + expect { save_form }.not_to change { appeal.reload.court_type }.from(nil) + end + end + + context "when the form is invalid" do + let(:court_type) { "foobar" } + + it "does not update the record" do + expect { save_form }.not_to change { appeal.reload.court_type }.from(nil) + end + end + + context "when court_type is valid" do + let(:court_type) { "court_of_appeal" } + + it "updates the record" do + expect { save_form }.to change { appeal.reload.court_type }.from(nil).to("court_of_appeal") + end + end + + context "when value changed" do + let(:appeal) { create(:appeal, court_type: "court_of_appeal") } + let(:court_type) { "supreme_court" } + + it "updates the record" do + expect { save_form }.to change { appeal.reload.court_type } + .from("court_of_appeal") + .to("supreme_court") + end + end + end + + describe "#save_as_draft" do + subject(:form) { described_class.new(params) } + + let(:save_as_draft) { form.save_as_draft } + + context "when the form is blank/invalid" do + let(:court_type) { nil } + + it "does not validate the form and saves" do + save_as_draft + expect(form.errors).to be_empty + expect { save_as_draft }.not_to change { appeal.reload.court_type }.from(nil) + end + end + + context "when the form is not blank" do + let(:court_type) { "supreme_court" } + + it "updates the record" do + expect { save_as_draft }.to change { appeal.reload.court_type }.from(nil).to("supreme_court") + end + end + end +end diff --git a/spec/requests/providers/application_merits_task/first_appeal_court_types_controller_spec.rb b/spec/requests/providers/application_merits_task/first_appeal_court_types_controller_spec.rb new file mode 100644 index 0000000000..a02515036a --- /dev/null +++ b/spec/requests/providers/application_merits_task/first_appeal_court_types_controller_spec.rb @@ -0,0 +1,159 @@ +require "rails_helper" + +RSpec.describe Providers::ApplicationMeritsTask::FirstAppealCourtTypesController do + let(:legal_aid_application) do + create(:legal_aid_application, + :with_public_law_family_appeal, + appeal: create(:appeal, + second_appeal: true, + court_type: nil)) + end + + let(:provider) { legal_aid_application.provider } + let(:next_flow_step) { flow_forward_path } + let(:smtl) { create(:legal_framework_merits_task_list, :pbm01a_as_applicant, legal_aid_application:) } + + before { login_as provider } + + context "when not authenticated" do + before { logout } + + context "when GET /providers/:application_id/appeal_court_type" do + before do + get providers_legal_aid_application_first_appeal_court_type_path(legal_aid_application) + end + + it_behaves_like "a provider not authenticated" + end + + context "when PATCH /providers/:application_id/appeal_court_type" do + before do + patch providers_legal_aid_application_first_appeal_court_type_path(legal_aid_application) + end + + it_behaves_like "a provider not authenticated" + end + end + + describe "GET /providers/:application_id/appeal_court_type" do + subject(:get_first_appeal_court_type) { get providers_legal_aid_application_first_appeal_court_type_path(legal_aid_application) } + + before { get_first_appeal_court_type } + + it "returns http success" do + expect(response).to have_http_status(:ok) + end + + it "has expected path" do + expect(page).to have_current_path(/.*\/appeal_court_type/, ignore_query: true) + end + + it "displays the page" do + expect(page) + .to have_title("Which court will the appeal be heard in?") + .and have_css("h1", text: "Which court will the appeal be heard in?") + end + end + + describe "PATCH /providers/:application_id/appeal_court_type" do + subject(:post_first_appeal_court_type) { patch providers_legal_aid_application_first_appeal_court_type_path(legal_aid_application), params: } + + before do + allow(LegalFramework::MeritsTasksService) + .to receive(:call).with(legal_aid_application).and_return(smtl) + end + + context "when form is saved using save and continue button" do + let(:params) do + { + application_merits_task_appeal: { court_type: }, + } + end + + context "when the user chooses a valid court type" do + let(:court_type) { "other_court" } + + it "updates the appeal record with court_type" do + expect { post_first_appeal_court_type } + .to change { legal_aid_application.reload.appeal.court_type } + .from(nil) + .to("other_court") + end + + it "redirects to the next page" do + post_first_appeal_court_type + expect(response).to redirect_to(next_flow_step) + end + end + + context "when the user chooses nothing" do + let(:court_type) { nil } + + it "stays on the page if there is a validation error" do + post_first_appeal_court_type + + expect(response).to have_http_status(:ok) + + within(".govuk-error-summary") do + expect(page).to have_content("Select which court the appeal will be heard in") + end + end + end + + context "when user changes answer" do + before do + legal_aid_application.appeal = create(:appeal, court_type: "court_of_appeal") + end + + let(:court_type) { "supreme_court" } + + it "updates the appeal record" do + expect { post_first_appeal_court_type } + .to change { legal_aid_application.reload.appeal.court_type } + .from("court_of_appeal") + .to("supreme_court") + end + end + end + + context "when the form is submitted with Save as draft button" do + let(:params) do + { + application_merits_task_appeal: { court_type: }, + draft_button: "irrelevant", + } + end + + context "with a court_type chosen" do + let(:court_type) { "court_of_appeal" } + + it "updates the appeal record with court_type value set" do + expect { post_first_appeal_court_type } + .to change { legal_aid_application.reload.appeal.court_type } + .from(nil) + .to("court_of_appeal") + end + + it "redirects to the list of applications" do + post_first_appeal_court_type + expect(response).to redirect_to(submitted_providers_legal_aid_applications_path) + end + end + + context "with no answer chosen" do + let(:court_type) { nil } + + it "creates the appeal record with no court_type set" do + expect { post_first_appeal_court_type } + .not_to change { legal_aid_application.reload.appeal.court_type } + .from(nil) + end + + it "redirects to the list of applications" do + post_first_appeal_court_type + expect(response).to redirect_to(submitted_providers_legal_aid_applications_path) + end + end + end + end +end diff --git a/spec/requests/providers/application_merits_task/second_appeal_court_types_controller_spec.rb b/spec/requests/providers/application_merits_task/second_appeal_court_types_controller_spec.rb new file mode 100644 index 0000000000..d9acea4e9d --- /dev/null +++ b/spec/requests/providers/application_merits_task/second_appeal_court_types_controller_spec.rb @@ -0,0 +1,159 @@ +require "rails_helper" + +RSpec.describe Providers::ApplicationMeritsTask::SecondAppealCourtTypesController do + let(:legal_aid_application) do + create(:legal_aid_application, + :with_public_law_family_appeal, + appeal: create(:appeal, + second_appeal: false, + court_type: nil)) + end + + let(:provider) { legal_aid_application.provider } + let(:next_flow_step) { flow_forward_path } + let(:smtl) { create(:legal_framework_merits_task_list, :pbm01a_as_applicant, legal_aid_application:) } + + before { login_as provider } + + context "when not authenticated" do + before { logout } + + context "when GET /providers/:application_id/second_appeal_court_type" do + before do + get providers_legal_aid_application_second_appeal_court_type_path(legal_aid_application) + end + + it_behaves_like "a provider not authenticated" + end + + context "when PATCH /providers/:application_id/second_appeal_court_type" do + before do + patch providers_legal_aid_application_second_appeal_court_type_path(legal_aid_application) + end + + it_behaves_like "a provider not authenticated" + end + end + + describe "GET /providers/:application_id/second_appeal_court_type" do + subject(:get_second_appeal_court_type) { get providers_legal_aid_application_second_appeal_court_type_path(legal_aid_application) } + + before { get_second_appeal_court_type } + + it "returns http success" do + expect(response).to have_http_status(:ok) + end + + it "has expected path" do + expect(page).to have_current_path(/.*\/second_appeal_court_type/, ignore_query: true) + end + + it "displays the page" do + expect(page) + .to have_title("Which court will the second appeal be heard in?") + .and have_css("h1", text: "Which court will the second appeal be heard in?") + end + end + + describe "PATCH /providers/:application_id/second_appeal_court_type" do + subject(:post_second_appeal_court_type) { patch providers_legal_aid_application_second_appeal_court_type_path(legal_aid_application), params: } + + before do + allow(LegalFramework::MeritsTasksService) + .to receive(:call).with(legal_aid_application).and_return(smtl) + end + + context "when form is saved using save and continue button" do + let(:params) do + { + application_merits_task_appeal: { court_type: }, + } + end + + context "when the user chooses a valid court type" do + let(:court_type) { "court_of_appeal" } + + it "updates the appeal record with court_type" do + expect { post_second_appeal_court_type } + .to change { legal_aid_application.reload.appeal.court_type } + .from(nil) + .to("court_of_appeal") + end + + it "redirects to the next page" do + post_second_appeal_court_type + expect(response).to redirect_to(next_flow_step) + end + end + + context "when the user chooses nothing" do + let(:court_type) { nil } + + it "stays on the page if there is a validation error" do + post_second_appeal_court_type + + expect(response).to have_http_status(:ok) + + within(".govuk-error-summary") do + expect(page).to have_content("Select which court the appeal will be heard in") + end + end + end + + context "when user changes answer" do + before do + legal_aid_application.appeal = create(:appeal, court_type: "court_of_appeal") + end + + let(:court_type) { "supreme_court" } + + it "updates the appeal record" do + expect { post_second_appeal_court_type } + .to change { legal_aid_application.reload.appeal.court_type } + .from("court_of_appeal") + .to("supreme_court") + end + end + end + + context "when the form is submitted with Save as draft button" do + let(:params) do + { + application_merits_task_appeal: { court_type: }, + draft_button: "irrelevant", + } + end + + context "with a court_type chosen" do + let(:court_type) { "court_of_appeal" } + + it "updates the appeal record with court_type value set" do + expect { post_second_appeal_court_type } + .to change { legal_aid_application.reload.appeal.court_type } + .from(nil) + .to("court_of_appeal") + end + + it "redirects to the list of applications" do + post_second_appeal_court_type + expect(response).to redirect_to(submitted_providers_legal_aid_applications_path) + end + end + + context "with no answer chosen" do + let(:court_type) { nil } + + it "creates the appeal record with no court_type set" do + expect { post_second_appeal_court_type } + .not_to change { legal_aid_application.reload.appeal.court_type } + .from(nil) + end + + it "redirects to the list of applications" do + post_second_appeal_court_type + expect(response).to redirect_to(submitted_providers_legal_aid_applications_path) + end + end + end + end +end diff --git a/spec/services/flow/steps/provider_merits/first_appeal_court_types_step_spec.rb b/spec/services/flow/steps/provider_merits/first_appeal_court_types_step_spec.rb new file mode 100644 index 0000000000..bbfbe7182c --- /dev/null +++ b/spec/services/flow/steps/provider_merits/first_appeal_court_types_step_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +RSpec.describe Flow::Steps::ProviderMerits::FirstAppealCourtTypesStep, type: :request do + let(:legal_aid_application) { create(:legal_aid_application) } + + before do + allow(Flow::MeritsLoop).to receive(:forward_flow).and_return(:merits_task_lists) + end + + describe "#path" do + subject { described_class.path.call(legal_aid_application) } + + it { is_expected.to eq providers_legal_aid_application_first_appeal_court_type_path(legal_aid_application) } + end + + describe "#forward" do + subject(:call) { described_class.forward.call(legal_aid_application) } + + it "goes to next step/question in loop" do + expect(call).to eq :merits_task_lists + end + end + + describe "#check_answers" do + subject { described_class.check_answers } + + it { is_expected.to eq :check_merits_answers } + end +end diff --git a/spec/services/flow/steps/provider_merits/original_judge_levels_step_spec.rb b/spec/services/flow/steps/provider_merits/original_judge_levels_step_spec.rb index d886360204..b1bc7ac126 100644 --- a/spec/services/flow/steps/provider_merits/original_judge_levels_step_spec.rb +++ b/spec/services/flow/steps/provider_merits/original_judge_levels_step_spec.rb @@ -1,7 +1,8 @@ require "rails_helper" RSpec.describe Flow::Steps::ProviderMerits::OriginalJudgeLevelsStep, type: :request do - let(:legal_aid_application) { create(:legal_aid_application) } + let(:legal_aid_application) { create(:legal_aid_application, appeal:) } + let(:appeal) { create(:appeal, original_judge_level:) } before do allow(Flow::MeritsLoop).to receive(:forward_flow).and_return(:merits_task_lists) @@ -10,19 +11,68 @@ describe "#path" do subject { described_class.path.call(legal_aid_application) } + let(:original_judge_level) { nil } + it { is_expected.to eq providers_legal_aid_application_original_judge_level_path(legal_aid_application) } end describe "#forward" do - subject { described_class.forward.call(legal_aid_application) } + subject(:call) { described_class.forward.call(legal_aid_application) } + + context "when original_judge_level in recorder_circuit_judge high_court_judge" do + let(:original_judge_level) { "recorder_circuit_judge" } + + it { is_expected.to eq :first_appeal_court_types } + end + + context "when original_judge_level in high_court_judge" do + let(:original_judge_level) { "high_court_judge" } + + it { is_expected.to eq :first_appeal_court_types } + end + + context "when original_judge_level is other string value" do + let(:original_judge_level) { "foobar" } + + it "goes to next question" do + expect(call).to eq :merits_task_lists + end + end + + context "when original_judge_level is nil" do + let(:original_judge_level) { nil } - # TODO: AP-5531/5532 - should go to question 4 "Which court will the appeal be heard in?" or Next question - it { is_expected.to eq :merits_task_lists } + it "goes to next question" do + expect(call).to eq :merits_task_lists + end + end end describe "#check_answers" do - subject { described_class.check_answers } + subject { described_class.check_answers.call(legal_aid_application) } + + context "when original_judge_level in recorder_circuit_judge high_court_judge" do + let(:original_judge_level) { "recorder_circuit_judge" } + + it { is_expected.to eq :first_appeal_court_types } + end + + context "when original_judge_level in high_court_judge" do + let(:original_judge_level) { "high_court_judge" } + + it { is_expected.to eq :first_appeal_court_types } + end + + context "when original_judge_level is other string value" do + let(:original_judge_level) { "foobar" } + + it { is_expected.to eq :check_merits_answers } + end + + context "when original_judge_level is nil" do + let(:original_judge_level) { nil } - it { is_expected.to eq :check_merits_answers } + it { is_expected.to eq :check_merits_answers } + end end end diff --git a/spec/services/flow/steps/provider_merits/second_appeal_court_types_step_spec.rb b/spec/services/flow/steps/provider_merits/second_appeal_court_types_step_spec.rb new file mode 100644 index 0000000000..93d0ace6ca --- /dev/null +++ b/spec/services/flow/steps/provider_merits/second_appeal_court_types_step_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +RSpec.describe Flow::Steps::ProviderMerits::SecondAppealCourtTypesStep, type: :request do + let(:legal_aid_application) { create(:legal_aid_application) } + + before do + allow(Flow::MeritsLoop).to receive(:forward_flow).and_return(:merits_task_lists) + end + + describe "#path" do + subject { described_class.path.call(legal_aid_application) } + + it { is_expected.to eq providers_legal_aid_application_second_appeal_court_type_path(legal_aid_application) } + end + + describe "#forward" do + subject(:call) { described_class.forward.call(legal_aid_application) } + + it "goes to next step/question in loop" do + expect(call).to eq :merits_task_lists + end + end + + describe "#check_answers" do + subject { described_class.check_answers } + + it { is_expected.to eq :check_merits_answers } + end +end diff --git a/spec/services/flow/steps/provider_merits/second_appeals_step_spec.rb b/spec/services/flow/steps/provider_merits/second_appeals_step_spec.rb index 551e06b272..9d3fb858b4 100644 --- a/spec/services/flow/steps/provider_merits/second_appeals_step_spec.rb +++ b/spec/services/flow/steps/provider_merits/second_appeals_step_spec.rb @@ -24,8 +24,7 @@ context "when second_appeal is true" do let(:second_appeal) { true } - # TODO: AP-5531/5532 - should go to question 3 "Which court will the second appeal be heard in?" - it { is_expected.to eq :merits_task_lists } + it { is_expected.to eq :second_appeal_court_types } end context "when second_appeal is false" do @@ -41,8 +40,7 @@ context "when second_appeal is true" do let(:second_appeal) { true } - # TODO: AP-5531/5532 - should go to question 3 "Which court will the second appeal be heard in?" - it { is_expected.to eq :check_merits_answers } + it { is_expected.to eq :second_appeal_court_types } end context "when second_appeal is false" do