Browse Source

Add routing for sales

pull/2484/head
Kat 10 months ago
parent
commit
ba3092c44d
  1. 2
      app/components/check_answers_summary_list_card_component.rb
  2. 4
      app/controllers/check_errors_controller.rb
  3. 12
      app/controllers/form_controller.rb
  4. 2
      app/views/check_errors/confirm_clear_answer.html.erb
  5. 6
      app/views/form/check_errors.html.erb
  6. 3
      config/routes.rb
  7. 166
      spec/requests/check_errors_controller_spec.rb

2
app/components/check_answers_summary_list_card_component.rb

@ -36,7 +36,7 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
def correct_validation_action_href(question, log, _related_question_ids) def correct_validation_action_href(question, log, _related_question_ids)
if question.displayed_as_answered?(log) if question.displayed_as_answered?(log)
lettings_log_confirm_clear_answer_path(log, question_id: question.id) send("#{log.model_name.param_key}_confirm_clear_answer_path", log, question_id: question.id)
else else
send("#{log.model_name.param_key}_#{question.page.id}_path", log, referrer: "check_errors", related_question_ids: request.query_parameters["related_question_ids"], original_page_id: request.query_parameters["original_page_id"]) send("#{log.model_name.param_key}_#{question.page.id}_path", log, referrer: "check_errors", related_question_ids: request.query_parameters["related_question_ids"], original_page_id: request.query_parameters["original_page_id"])
end end

4
app/controllers/check_errors_controller.rb

@ -7,10 +7,10 @@ class CheckErrorsController < ApplicationController
def confirm_clear_answer def confirm_clear_answer
return render_not_found unless @log return render_not_found unless @log
@related_question_ids = params["lettings_log"].keys.reject { |id| id == "page_id" } @related_question_ids = params[@log.model_name.param_key].keys.reject { |id| id == "page_id" }
question_id = @related_question_ids.find { |id| !params[id].nil? } question_id = @related_question_ids.find { |id| !params[id].nil? }
@question = @log.form.get_question(question_id, @log) @question = @log.form.get_question(question_id, @log)
@page = @log.form.get_page(params["lettings_log"]["page_id"]) @page = @log.form.get_page(params[@log.model_name.param_key]["page_id"])
end end
private private

12
app/controllers/form_controller.rb

@ -227,9 +227,9 @@ private
return send("#{@log.class.name.underscore}_#{previous_interruption_screen_page_id}_path", @log, { referrer: previous_interruption_screen_referrer, original_log_id: original_duplicate_log_id_from_query }.compact) return send("#{@log.class.name.underscore}_#{previous_interruption_screen_page_id}_path", @log, { referrer: previous_interruption_screen_referrer, original_log_id: original_duplicate_log_id_from_query }.compact)
end end
if params["lettings_log"]["check_errors"] if params[@log.model_name.param_key]["check_errors"]
@page = form.get_page(params["lettings_log"]["page"]) @page = form.get_page(params[@log.model_name.param_key]["page"])
return send("#{@log.class.name.underscore}_#{params['lettings_log']['original_page_id']}_path", @log, { check_errors: true, related_question_ids: params["lettings_log"]["related_question_ids"].split(" ") }.compact) return send("#{@log.class.name.underscore}_#{params[@log.model_name.param_key]['original_page_id']}_path", @log, { check_errors: true, related_question_ids: params[@log.model_name.param_key]["related_question_ids"].split(" ") }.compact)
end end
is_new_answer_from_check_answers = is_referrer_type?("check_answers_new_answer") is_new_answer_from_check_answers = is_referrer_type?("check_answers_new_answer")
@ -395,11 +395,11 @@ private
end end
def render_check_errors_page def render_check_errors_page
if params["lettings_log"]["clear_question_id"] if params[@log.model_name.param_key]["clear_question_id"]
question_id = params["lettings_log"]["clear_question_id"] question_id = params[@log.model_name.param_key]["clear_question_id"]
@log.form.get_question(question_id, @log).page.questions.map(&:id).each { |id| @log[id] = nil } @log.form.get_question(question_id, @log).page.questions.map(&:id).each { |id| @log[id] = nil }
@log.save! @log.save!
@questions = params["lettings_log"].keys.reject { |id| %w[clear_question_id page].include?(id) }.map { |id| @log.form.get_question(id, @log) } @questions = params[@log.model_name.param_key].keys.reject { |id| %w[clear_question_id page].include?(id) }.map { |id| @log.form.get_question(id, @log) }
else else
responses_for_page = responses_for_page(@page) responses_for_page = responses_for_page(@page)
@log.assign_attributes(responses_for_page) @log.assign_attributes(responses_for_page)

2
app/views/check_errors/confirm_clear_answer.html.erb

@ -9,7 +9,7 @@
</h1> </h1>
<%= govuk_warning_text(text: "This action is permanent") %> <%= govuk_warning_text(text: "This action is permanent") %>
<%= form_with model: @log, url: send("lettings_log_#{@page.id}_path", @log), method: "post", local: true do |f| %> <%= form_with model: @log, url: send("#{@log.model_name.param_key}_#{@page.id}_path", @log), method: "post", local: true do |f| %>
<% @related_question_ids.each do |id| %> <% @related_question_ids.each do |id| %>
<%= f.hidden_field id, value: @log[id] %> <%= f.hidden_field id, value: @log[id] %>

6
app/views/form/check_errors.html.erb

@ -1,7 +1,7 @@
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters-from-desktop"> <div class="govuk-grid-column-three-quarters-from-desktop">
<%= form_with model: @log, url: lettings_log_confirm_clear_answer_path(@log), method: "post", local: true do |f| %> <%= form_with model: @log, url: send("#{@log.model_name.param_key}_confirm_clear_answer_path", @log), method: "post", local: true do |f| %>
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
<%= f.hidden_field :page_id, value: @page.id %> <%= f.hidden_field :page_id, value: @page.id %>
@ -11,7 +11,7 @@
Make sure these answers are correct: Make sure these answers are correct:
</span> </span>
<span class="govuk-body govuk-!-text-align-right govuk-grid-column-one-third"> <span class="govuk-body govuk-!-text-align-right govuk-grid-column-one-third">
<%= govuk_link_to "Clear all", lettings_log_confirm_clear_all_answers_path(@log) %> <%= govuk_link_to "Clear all", send("#{@log.model_name.param_key}_confirm_clear_all_answers_path", @log) %>
</span> </span>
</div> </div>
</h1> </h1>
@ -49,7 +49,7 @@
</dd> </dd>
<dd class="govuk-summary-list__actions"> <dd class="govuk-summary-list__actions">
<% if question.displayed_as_answered?(@log) %> <% if question.displayed_as_answered?(@log) %>
<input type="submit" value="Clear" name=<%= question.id %> class="govuk-body govuk-link submit-button-link" > <input type="submit" value="Clear" class="govuk-body govuk-link submit-button-link" name="<%= question.id %>">
<% else %> <% else %>
<%= govuk_link_to "Answer", send("#{@log.model_name.param_key}_#{question.page.id}_path", @log, referrer: "check_errors", original_page_id: @page.id, related_question_ids: applicable_questions.map(&:id)) %> <%= govuk_link_to "Answer", send("#{@log.model_name.param_key}_#{question.page.id}_path", @log, referrer: "check_errors", original_page_id: @page.id, related_question_ids: applicable_questions.map(&:id)) %>
<% end %> <% end %>

3
config/routes.rb

@ -214,7 +214,6 @@ Rails.application.routes.draw do
get "delete-duplicates", to: "duplicate_logs#delete_duplicates" get "delete-duplicates", to: "duplicate_logs#delete_duplicates"
post "confirm-clear-answer", to: "check_errors#confirm_clear_answer" post "confirm-clear-answer", to: "check_errors#confirm_clear_answer"
post "confirm-clear-all-answers", to: "check_errors#confirm_clear_all_answers" post "confirm-clear-all-answers", to: "check_errors#confirm_clear_all_answers"
post "clear-answer", to: "check_errors#clear_answer"
collection do collection do
get "csv-download", to: "lettings_logs#download_csv" get "csv-download", to: "lettings_logs#download_csv"
@ -285,6 +284,8 @@ Rails.application.routes.draw do
get "delete-confirmation", to: "sales_logs#delete_confirmation" get "delete-confirmation", to: "sales_logs#delete_confirmation"
get "duplicate-logs", to: "duplicate_logs#show" get "duplicate-logs", to: "duplicate_logs#show"
get "delete-duplicates", to: "duplicate_logs#delete_duplicates" get "delete-duplicates", to: "duplicate_logs#delete_duplicates"
post "confirm-clear-answer", to: "check_errors#confirm_clear_answer"
post "confirm-clear-all-answers", to: "check_errors#confirm_clear_all_answers"
collection do collection do
get "csv-download", to: "sales_logs#download_csv" get "csv-download", to: "sales_logs#download_csv"

166
spec/requests/check_errors_controller_spec.rb

@ -3,14 +3,20 @@ require "rails_helper"
RSpec.describe CheckErrorsController, type: :request do RSpec.describe CheckErrorsController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
let(:user) { create(:user, :data_coordinator) } let(:user) { create(:user, :data_coordinator) }
let(:lettings_log) { create(:lettings_log, :duplicate, assigned_to: user) } let(:lettings_log) { create(:lettings_log, :setup_completed, assigned_to: user) }
let(:sales_log) { create(:sales_log, :shared_ownership_setup_complete, assigned_to: user) }
describe "check errors page" do describe "check errors page" do
context "when user is not signed in" do context "when user is not signed in" do
it "redirects to sign in page" do it "redirects to sign in page for lettings" do
post "/lettings-logs/#{lettings_log.id}/net-income", params: {} post "/lettings-logs/#{lettings_log.id}/net-income", params: {}
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end end
it "redirects to sign in page for sales" do
post "/sales-logs/#{sales_log.id}/buyer-1-income", params: {}
expect(response).to redirect_to("/account/sign-in")
end
end end
context "when the user is from different organisation" do context "when the user is from different organisation" do
@ -20,38 +26,66 @@ RSpec.describe CheckErrorsController, type: :request do
sign_in other_user sign_in other_user
end end
it "renders page not found" do it "renders page not found for lettings" do
post "/lettings-logs/#{lettings_log.id}/net-income", params: {} post "/lettings-logs/#{lettings_log.id}/net-income", params: {}
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end end
it "renders page not found for sales" do
post "/sales-logs/#{sales_log.id}/buyer-1-income", params: {}
expect(response).to have_http_status(:not_found)
end
end end
context "when user is signed in" do context "when user is signed in" do
let(:params) do context "with multiple error fields and answered questions for lettings" do
{ let(:params) do
id: lettings_log.id, {
lettings_log: { id: lettings_log.id,
page: "income_amount", lettings_log: {
earnings: "100000", page: "income_amount",
incfreq: "1", earnings: "100000",
}, incfreq: "1",
check_errors: "", },
} check_errors: "",
end }
end
before do before do
lettings_log.update(needstype: 1, declaration: 1, ecstat1: 10, hhmemb: 2, net_income_known: 0, incfreq: 1, earnings: 1000) lettings_log.update!(needstype: 1, declaration: 1, ecstat1: 10, hhmemb: 2, net_income_known: 0, incfreq: 1, earnings: 1000)
sign_in user
post "/lettings-logs/#{lettings_log.id}/income-amount", params: params
end
it "displays correct clear links" do
expect(page).to have_selector("input[type=submit][value='Clear']", count: 3)
expect(page).to have_link("Clear all", href: "/lettings-logs/#{lettings_log.id}/confirm-clear-all-answers")
end
end end
context "with multiple error fields and answered questions" do context "with multiple error fields and answered questions for sales" do
let(:params) do
{
id: sales_log.id,
sales_log: {
page: "buyer_1_income",
income1: "100000",
la: "E09000001",
ownershipsch: "1",
},
check_errors: "",
}
end
before do before do
sales_log.update!(income1: 1000, la: "E09000001")
sign_in user sign_in user
post "/lettings-logs/#{lettings_log.id}/income-amount", params: params post "/sales-logs/#{sales_log.id}/buyer-1-income", params: params
end end
it "displays correct clear links" do it "displays correct clear links" do
expect(page).to have_button("Clear", count: 3) expect(page).to have_button("Clear", count: 3)
expect(page).to have_link("Clear all", href: "/lettings-logs/#{lettings_log.id}/confirm-clear-all-answers") expect(page).to have_link("Clear all", href: "/sales-logs/#{sales_log.id}/confirm-clear-all-answers")
end end
end end
end end
@ -59,10 +93,15 @@ RSpec.describe CheckErrorsController, type: :request do
describe "confirm clear answer page" do describe "confirm clear answer page" do
context "when user is not signed in" do context "when user is not signed in" do
it "redirects to sign in page" do it "redirects to sign in page for lettings" do
post "/lettings-logs/#{lettings_log.id}/confirm-clear-answer", params: {} post "/lettings-logs/#{lettings_log.id}/confirm-clear-answer", params: {}
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end end
it "redirects to sign in page for sales" do
post "/sales-logs/#{sales_log.id}/confirm-clear-answer", params: {}
expect(response).to redirect_to("/account/sign-in")
end
end end
context "when the user is from different organisation" do context "when the user is from different organisation" do
@ -72,14 +111,19 @@ RSpec.describe CheckErrorsController, type: :request do
sign_in other_user sign_in other_user
end end
it "renders page not found" do it "renders page not found for lettings" do
post "/lettings-logs/#{lettings_log.id}/confirm-clear-answer", params: {} post "/lettings-logs/#{lettings_log.id}/confirm-clear-answer", params: {}
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end end
it "renders page not found for sales" do
post "/sales-logs/#{sales_log.id}/confirm-clear-answer", params: {}
expect(response).to have_http_status(:not_found)
end
end end
context "when user is signed in" do context "when user is signed in" do
context "and clearing specific question" do context "and clearing specific lettings question" do
let(:params) do let(:params) do
{ {
id: lettings_log.id, id: lettings_log.id,
@ -105,18 +149,47 @@ RSpec.describe CheckErrorsController, type: :request do
expect(page).to have_button("Confirm and continue") expect(page).to have_button("Confirm and continue")
end end
end end
end
end
describe "confirm clear all answers page" do context "and clearing specific sales question" do
let(:params) do
{
id: sales_log.id,
sales_log: {
income1: "100000",
la: "E09000001",
ownershipsch: "1",
page_id: "buyer_1_income",
},
income1: "",
}
end
before do
sign_in user
post "/sales-logs/#{sales_log.id}/confirm-clear-answer", params:
end
it "displays correct clear links" do
expect(page).to have_content("Are you sure you want to clear Buyer 1’s gross annual income?")
expect(page).to have_content("This action is permanent")
expect(page).to have_link("Cancel")
expect(page).to have_button("Confirm and continue")
end
end
end
end end
describe "clear answer" do describe "clear answer" do
context "when user is not signed in" do context "when user is not signed in" do
it "redirects to sign in page" do it "redirects to sign in page for lettings" do
post "/lettings-logs/#{lettings_log.id}/income-amount", params: {} post "/lettings-logs/#{lettings_log.id}/income-amount", params: {}
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end end
it "redirects to sign in page for sales" do
post "/sales-logs/#{sales_log.id}/buyer-1-income", params: {}
expect(response).to redirect_to("/account/sign-in")
end
end end
context "when the user is from different organisation" do context "when the user is from different organisation" do
@ -126,14 +199,19 @@ RSpec.describe CheckErrorsController, type: :request do
sign_in other_user sign_in other_user
end end
it "renders page not found" do it "renders page not found for lettings" do
post "/lettings-logs/#{lettings_log.id}/income-amount", params: {} post "/lettings-logs/#{lettings_log.id}/income-amount", params: {}
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end end
it "renders page not found for sales" do
post "/sales-logs/#{lettings_log.id}/buyer-1-income", params: {}
expect(response).to have_http_status(:not_found)
end
end end
context "when user is signed in" do context "when user is signed in" do
context "and clearing specific question" do context "and clearing specific lettings question" do
let(:params) do let(:params) do
{ {
id: lettings_log.id, id: lettings_log.id,
@ -157,11 +235,37 @@ RSpec.describe CheckErrorsController, type: :request do
expect(page).to have_content("Make sure these answers are correct") expect(page).to have_content("Make sure these answers are correct")
expect(page).to have_content("You didn’t answer this question") expect(page).to have_content("You didn’t answer this question")
expect(page).to have_link("Answer") expect(page).to have_link("Answer")
expect(lettings_log.reload.earnings).to eq(nil)
end end
end end
end
end
describe "clear all answers" do context "and clearing specific sales question" do
let(:params) do
{
id: sales_log.id,
sales_log: {
income1: "100000",
la: "E09000001",
ownershipsch: "1",
clear_question_id: "income1",
page: "buyer_1_income",
},
check_errors: "",
}
end
before do
sign_in user
post "/sales-logs/#{sales_log.id}/buyer-1-income", params:
end
it "displays correct clear links" do
expect(page).to have_content("Make sure these answers are correct")
expect(page).to have_content("You didn’t answer this question")
expect(page).to have_link("Answer")
expect(sales_log.reload.income1).to eq(nil)
end
end
end
end end
end end

Loading…
Cancel
Save