From 3fc5a68a3651c59e09b8e8cf91e59a15cc163330 Mon Sep 17 00:00:00 2001 From: Aaron Spencer <62190777+Airk0n@users.noreply.github.com> Date: Tue, 11 Jul 2023 08:48:25 +0100 Subject: [PATCH] CLDC-2494 Add duplicate logs page (#1763) * CLDC-2494: WIP * CLDC-2494: wip * CLDC-2494: page work in progress * cleanup * Add a path for duplicate logs * Display all duplicate logs * Move a test * Display duplicate check answers for logs * Add buttons to delete duplicates * Add a route for sales logs duplicates * Update duplicated page to work for sales logs * Update styling * lint * Add auth * Rebase updates * Remove propcode from dedulication checks * Update fields to work with supported housing * Trigger duplicate log check on buyer 1 age not known * compare correct charges * Update displayed questions * BU test * Put redirect to duplicate logs path behind a feature flag * More BU tests --------- Co-authored-by: Kat --- app/controllers/duplicate_logs_controller.rb | 50 ++++++++ app/controllers/form_controller.rb | 10 ++ app/helpers/tag_helper.rb | 2 + app/models/lettings_log.rb | 18 ++- app/models/sales_log.rb | 8 +- .../lettings/year2022/row_parser.rb | 3 - .../lettings/year2023/row_parser.rb | 3 - app/services/feature_toggle.rb | 4 + .../duplicate_logs/_duplicate_log.html.erb | 26 ++++ .../_duplicate_log_check_answers.erb | 39 ++++++ app/views/duplicate_logs/show.erb | 20 ++++ config/routes.rb | 2 + spec/models/lettings_log_spec.rb | 39 ++++-- spec/models/sales_log_spec.rb | 27 +++++ .../duplicate_logs_controller_spec.rb | 112 ++++++++++++++++++ spec/requests/form_controller_spec.rb | 48 ++++++++ .../bulk_upload/lettings/validator_spec.rb | 2 +- .../lettings/year2022/row_parser_spec.rb | 3 - .../lettings/year2023/row_parser_spec.rb | 3 - 19 files changed, 389 insertions(+), 30 deletions(-) create mode 100644 app/controllers/duplicate_logs_controller.rb create mode 100644 app/views/duplicate_logs/_duplicate_log.html.erb create mode 100644 app/views/duplicate_logs/_duplicate_log_check_answers.erb create mode 100644 app/views/duplicate_logs/show.erb create mode 100644 spec/requests/duplicate_logs_controller_spec.rb diff --git a/app/controllers/duplicate_logs_controller.rb b/app/controllers/duplicate_logs_controller.rb new file mode 100644 index 000000000..21e853bf9 --- /dev/null +++ b/app/controllers/duplicate_logs_controller.rb @@ -0,0 +1,50 @@ +class DuplicateLogsController < ApplicationController + before_action :authenticate_user! + before_action :find_resource_by_named_id + + def show + if @log + @duplicate_logs = if @log.lettings? + current_user.lettings_logs.duplicate_logs(@log) + else + current_user.sales_logs.duplicate_logs(@log) + end + @all_duplicates = [@log, *@duplicate_logs] + @duplicate_check_questions = duplicate_check_question_ids.map { |question_id| + question = @log.form.get_question(question_id, @log) + question if question.page.routed_to?(@log, current_user) + }.compact + else + render_not_found + end + end + +private + + def find_resource_by_named_id + @log = if params[:sales_log_id].present? + current_user.sales_logs.visible.find_by(id: params[:sales_log_id]) + else + current_user.lettings_logs.visible.find_by(id: params[:lettings_log_id]) + end + end + + def duplicate_check_question_ids + if @log.lettings? + ["owning_organisation_id", + "startdate", + "tenancycode", + "postcode_full", + "scheme_id", + "location_id", + "age1", + "sex1", + "ecstat1", + @log.household_charge == 1 ? "household_charge" : nil, + "tcharge", + @log.is_carehome? ? "chcharge" : nil].compact + else + %w[owning_organisation_id saledate purchid age1 sex1 ecstat1 postcode_full] + end + end +end diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index eb58b656d..93cfda2f0 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -155,6 +155,16 @@ private end def successful_redirect_path + if FeatureToggle.deduplication_flow_enabled? + if @log.lettings? + if current_user.lettings_logs.duplicate_logs(@log).count.positive? + return send("lettings_log_duplicate_logs_path", @log) + end + elsif current_user.sales_logs.duplicate_logs(@log).count.positive? + return send("sales_log_duplicate_logs_path", @log) + end + end + if is_referrer_type?("check_answers") next_page_id = form.next_page_id(@page, @log, current_user) next_page = form.get_page(next_page_id) diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb index 074ef21ed..5a7498b78 100644 --- a/app/helpers/tag_helper.rb +++ b/app/helpers/tag_helper.rb @@ -12,6 +12,7 @@ module TagHelper activating_soon: "Activating soon", reactivating_soon: "Reactivating soon", deactivated: "Deactivated", + deleted: "Deleted", }.freeze COLOUR = { @@ -25,6 +26,7 @@ module TagHelper activating_soon: "blue", reactivating_soon: "blue", deactivated: "grey", + deleted: "red", }.freeze def status_tag(status, classes = []) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 48baa7b8e..a1094ee37 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -54,10 +54,18 @@ class LettingsLog < Log scope :unresolved, -> { where(unresolved: true) } scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } scope :duplicate_logs, lambda { |log| - visible.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES)) - .where.not(id: log.id) - .where.not("startdate IS NULL OR age1 IS NULL OR sex1 IS NULL OR ecstat1 IS NULL OR tcharge IS NULL OR postcode_full IS NULL OR propcode IS NULL OR needstype IS NULL") - .where("location_id = ? OR needstype = 1", log.location_id) + visible + .where(log.slice(*DUPLICATE_LOG_ATTRIBUTES)) + .where.not(id: log.id) + .where.not(startdate: nil) + .where.not(sex1: nil) + .where.not(ecstat1: nil) + .where.not(needstype: nil) + .where("age1 IS NOT NULL OR age1_known = 1") + .where("tcharge IS NOT NULL OR household_charge = 1 OR is_carehome = 1") + .where("chcharge IS NOT NULL OR is_carehome IS NULL OR is_carehome = 0") + .where("location_id = ? OR needstype = 1", log.location_id) + .where("postcode_full = ? OR needstype = 2", log.postcode_full) } AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze @@ -67,7 +75,7 @@ class LettingsLog < Log NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52, 10 => 53 }.freeze SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze - DUPLICATE_LOG_ATTRIBUTES = %w[tenancycode propcode startdate age1 sex1 ecstat1 tcharge postcode_full].freeze + DUPLICATE_LOG_ATTRIBUTES = %w[tenancycode startdate age1_known age1 sex1 ecstat1 tcharge household_charge chcharge].freeze def form FormHandler.instance.get_form(form_name) || FormHandler.instance.current_lettings_form diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 311ecc565..ae76e32c3 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -44,12 +44,16 @@ class SalesLog < Log scope :duplicate_logs, lambda { |log| visible.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES)) .where.not(id: log.id) - .where.not("saledate is NULL OR age1 IS NULL OR sex1 IS NULL OR ecstat1 IS NULL OR postcode_full IS NULL") + .where.not(saledate: nil) + .where.not(sex1: nil) + .where.not(ecstat1: nil) + .where.not(postcode_full: nil) + .where("age1 IS NOT NULL OR age1_known = 1 OR age1_known = 2") } OPTIONAL_FIELDS = %w[purchid othtype].freeze RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze - DUPLICATE_LOG_ATTRIBUTES = %w[purchid saledate age1 sex1 ecstat1 postcode_full].freeze + DUPLICATE_LOG_ATTRIBUTES = %w[purchid saledate age1_known age1 sex1 ecstat1 postcode_full].freeze def lettings? false diff --git a/app/services/bulk_upload/lettings/year2022/row_parser.rb b/app/services/bulk_upload/lettings/year2022/row_parser.rb index a1e7dbb06..642c8efe8 100644 --- a/app/services/bulk_upload/lettings/year2022/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2022/row_parser.rb @@ -450,7 +450,6 @@ class BulkUpload::Lettings::Year2022::RowParser "field_96", # startdate "field_97", # startdate "field_98", # startdate - "field_100", # propcode bulk_upload.needstype != 2 ? "field_108" : nil, # postcode bulk_upload.needstype != 2 ? "field_109" : nil, # postcode "field_111", # owning org @@ -525,7 +524,6 @@ private "ecstat1", "owning_organisation", "tcharge", - "propcode", bulk_upload.needstype != 2 ? "postcode_full" : nil, bulk_upload.needstype != 1 ? "location" : nil, ].compact @@ -862,7 +860,6 @@ private errors.add(:field_96, error_message) # startdate errors.add(:field_97, error_message) # startdate errors.add(:field_98, error_message) # startdate - errors.add(:field_100, error_message) # propcode errors.add(:field_108, error_message) if bulk_upload.needstype != 2 # postcode_full errors.add(:field_109, error_message) if bulk_upload.needstype != 2 # postcode_full errors.add(:field_111, error_message) # owning_organisation diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 11e9a1e5b..4a12e9083 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -464,7 +464,6 @@ class BulkUpload::Lettings::Year2023::RowParser "field_8", # startdate "field_9", # startdate "field_13", # tenancycode - "field_14", # propcode field_4 != 1 ? "field_17" : nil, # location field_4 != 2 ? "field_23" : nil, # postcode field_4 != 2 ? "field_24" : nil, # postcode @@ -561,7 +560,6 @@ private "ecstat1", "owning_organisation", "tcharge", - "propcode", field_4 != 2 ? "postcode_full" : nil, field_4 != 1 ? "location" : nil, "tenancycode", @@ -856,7 +854,6 @@ private errors.add(:field_8, error_message) # startdate errors.add(:field_9, error_message) # startdate errors.add(:field_13, error_message) # tenancycode - errors.add(:field_14, error_message) # propcode errors.add(:field_17, error_message) if field_4 != 1 # location errors.add(:field_23, error_message) if field_4 != 2 # postcode_full errors.add(:field_24, error_message) if field_4 != 2 # postcode_full diff --git a/app/services/feature_toggle.rb b/app/services/feature_toggle.rb index 2bc081b56..153b7352a 100644 --- a/app/services/feature_toggle.rb +++ b/app/services/feature_toggle.rb @@ -33,4 +33,8 @@ class FeatureToggle def self.new_data_protection_confirmation? true end + + def self.deduplication_flow_enabled? + !Rails.env.production? + end end diff --git a/app/views/duplicate_logs/_duplicate_log.html.erb b/app/views/duplicate_logs/_duplicate_log.html.erb new file mode 100644 index 000000000..a93e63570 --- /dev/null +++ b/app/views/duplicate_logs/_duplicate_log.html.erb @@ -0,0 +1,26 @@ +
+
+
+
+
+

+ <%= govuk_link_to "Log #{log.id}", send("#{log.class.name.underscore}_path", log) %> +

+
+
+
+

+ Created + <% if log.created_by %> + Assigned to <%= log.created_by.name || log.created_by.email %> + <% end %> +

+
+
+
+ +
diff --git a/app/views/duplicate_logs/_duplicate_log_check_answers.erb b/app/views/duplicate_logs/_duplicate_log_check_answers.erb new file mode 100644 index 000000000..15d4caf73 --- /dev/null +++ b/app/views/duplicate_logs/_duplicate_log_check_answers.erb @@ -0,0 +1,39 @@ +
+
+ <%= govuk_summary_list do |summary_list| %> + <% @duplicate_check_questions.each do |question| %> + <% summary_list.row do |row| %> + <% row.key { get_question_label(question) } %> + + <% row.value do %> + <%= simple_format( + get_answer_label(question, @log), + wrapper_tag: "span", + class: "govuk-!-margin-right-4", + ) %> + + <% extra_value = question.get_extra_check_answer_value(@log) %> + + <% if extra_value && question.answer_label(@log, current_user).present? %> + <%= simple_format( + extra_value, + wrapper_tag: "span", + class: "govuk-!-font-weight-regular app-!-colour-muted", + ) %> + <% end %> + + <% question.get_inferred_answers(@log).each do |inferred_answer| %> + <%= inferred_answer %> + <% end %> + <% end %> + + <% row.action( + text: question.action_text(@log), + href: action_href(@log, question.page.id), + visually_hidden_text: question.check_answer_label.to_s.downcase, + ) %> + <% end %> + <% end %> + <% end %> +
+
diff --git a/app/views/duplicate_logs/show.erb b/app/views/duplicate_logs/show.erb new file mode 100644 index 000000000..04da14593 --- /dev/null +++ b/app/views/duplicate_logs/show.erb @@ -0,0 +1,20 @@ +<% content_for :title, "Check duplicate logs" %> +
+
+ <%= govuk_panel( + classes: "app-panel--interruption", + ) do %> +

These logs are duplicates

+

These logs have the same values for the following fields. Choose one to keep or correct the answers.

+ <% end %> + + <% @all_duplicates.each_with_index do |log, index| %> + <%= render partial: "duplicate_log", locals: { log: log } %> + <%= render partial: "duplicate_log_check_answers", locals: { log: log } %> + <%= govuk_button_link_to "Keep this log and delete duplicates", "#" %> + <% if index < @all_duplicates.count - 1 %> +
+ <% end %> + <% end %> +
+
diff --git a/config/routes.rb b/config/routes.rb index 8b61f1ece..707e8e942 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -170,6 +170,7 @@ Rails.application.routes.draw do resources :lettings_logs, path: "/lettings-logs" do get "delete-confirmation", to: "lettings_logs#delete_confirmation" + get "duplicate-logs", to: "duplicate_logs#show" collection do post "bulk-upload", to: "bulk_upload#bulk_upload" @@ -235,6 +236,7 @@ Rails.application.routes.draw do resources :sales_logs, path: "/sales-logs" do get "delete-confirmation", to: "sales_logs#delete_confirmation" + get "duplicate-logs", to: "duplicate_logs#show" collection do get "csv-download", to: "sales_logs#download_csv" diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index b5b5e99cb..e2a15874a 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -2862,14 +2862,6 @@ RSpec.describe LettingsLog do end end - context "when there is a log with a different propcode" do - let!(:different_propcode) { create(:lettings_log, :duplicate, propcode: "different") } - - it "does not return a log with a different propcode as a duplicate" do - expect(described_class.duplicate_logs(log)).not_to include(different_propcode) - end - end - context "when there is a log with a different tenancycode" do let!(:different_tenancycode) { create(:lettings_log, :duplicate, tenancycode: "different") } @@ -2887,10 +2879,10 @@ RSpec.describe LettingsLog do end context "when there is a log with nil values for duplicate check fields" do - let!(:duplicate_check_fields_not_given) { create(:lettings_log, :duplicate, age1: nil, sex1: nil, ecstat1: nil, propcode: nil, postcode_known: 2, postcode_full: nil) } + let!(:duplicate_check_fields_not_given) { create(:lettings_log, :duplicate, age1: nil, sex1: nil, ecstat1: nil, postcode_known: 2, postcode_full: nil) } it "does not return a log with nil values as a duplicate" do - log.update!(age1: nil, sex1: nil, ecstat1: nil, propcode: nil, postcode_known: 2, postcode_full: nil) + log.update!(age1: nil, sex1: nil, ecstat1: nil, postcode_known: 2, postcode_full: nil) expect(described_class.duplicate_logs(log)).not_to include(duplicate_check_fields_not_given) end end @@ -2904,6 +2896,15 @@ RSpec.describe LettingsLog do end end + context "when there is a log with age1 not known" do + let!(:age1_not_known) { create(:lettings_log, :duplicate, age1_known: 1, age1: nil) } + + it "returns the log as a duplicate if age1 is not known" do + log.update!(age1_known: 1, age1: nil) + expect(described_class.duplicate_logs(log)).to include(age1_not_known) + end + end + context "when there is a duplicate supported housing log" do let(:scheme) { create(:scheme) } let(:location) { create(:location, scheme:) } @@ -2919,6 +2920,24 @@ RSpec.describe LettingsLog do duplicate_supported_housing_log.update!(location: location_2) expect(described_class.duplicate_logs(supported_housing_log)).not_to include(duplicate_supported_housing_log) end + + it "does not compare tcharge if there are no household charges" do + supported_housing_log.update!(household_charge: 1, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) + duplicate_supported_housing_log.update!(household_charge: 1, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) + expect(described_class.duplicate_logs(supported_housing_log)).to include(duplicate_supported_housing_log) + end + + it "compares chcharge if it's a carehome" do + supported_housing_log.update!(is_carehome: 1, chcharge: 100, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) + duplicate_supported_housing_log.update!(is_carehome: 1, chcharge: 100, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) + expect(described_class.duplicate_logs(supported_housing_log)).to include(duplicate_supported_housing_log) + end + + it "does not return a duplicate if carehome charge is not given" do + supported_housing_log.update!(is_carehome: 1, chcharge: nil, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) + duplicate_supported_housing_log.update!(is_carehome: 1, chcharge: nil, supcharg: nil, brent: nil, scharge: nil, pscharge: nil, tcharge: nil) + expect(described_class.duplicate_logs(supported_housing_log)).not_to include(duplicate_supported_housing_log) + end end end end diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index c382c364b..d032293c8 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -249,6 +249,33 @@ RSpec.describe SalesLog, type: :model do expect(described_class.duplicate_logs(log)).to include(purchid_not_given) end end + + context "when there is a log age not known" do + let!(:age1_not_known) { create(:sales_log, :duplicate, age1_known: 1, age1: nil) } + + it "returns the log as a duplicate if age is not known" do + log.update!(age1_known: 1, age1: nil) + expect(described_class.duplicate_logs(log)).to include(age1_not_known) + end + end + + context "when there is a log age pefers not to say" do + let!(:age1_prefers_not_to_say) { create(:sales_log, :duplicate, age1_known: 2, age1: nil) } + + it "returns the log as a duplicate if age is prefers not to say" do + log.update!(age1_known: 2, age1: nil) + expect(described_class.duplicate_logs(log)).to include(age1_prefers_not_to_say) + end + end + + context "when there is a log age pefers not to say and not known" do + let!(:age1_prefers_not_to_say) { create(:sales_log, :duplicate, age1_known: 2, age1: nil) } + + it "does not return the log as a duplicate if age is prefers not to say" do + log.update!(age1_known: 1, age1: nil) + expect(described_class.duplicate_logs(log)).not_to include(age1_prefers_not_to_say) + end + end end describe "derived variables" do diff --git a/spec/requests/duplicate_logs_controller_spec.rb b/spec/requests/duplicate_logs_controller_spec.rb new file mode 100644 index 000000000..3ba94c218 --- /dev/null +++ b/spec/requests/duplicate_logs_controller_spec.rb @@ -0,0 +1,112 @@ +require "rails_helper" + +RSpec.describe DuplicateLogsController, type: :request do + let(:page) { Capybara::Node::Simple.new(response.body) } + let(:user) { create(:user) } + + context "when a user is signed in" do + let(:lettings_log) do + create( + :lettings_log, + :completed, + created_by: user, + ) + end + let(:sales_log) do + create( + :sales_log, + :completed, + created_by: user, + ) + end + + describe "GET" do + context "when user is not signed in" do + it "redirects to sign in page" do + get "/lettings-logs/#{lettings_log.id}/duplicate-logs" + expect(response).to redirect_to("/account/sign-in") + end + end + + context "when the user is from different organisation" do + let(:other_user) { create(:user) } + + before do + allow(other_user).to receive(:need_two_factor_authentication?).and_return(false) + sign_in other_user + end + + it "renders page not found" do + get "/lettings-logs/#{lettings_log.id}/duplicate-logs" + expect(response).to have_http_status(:not_found) + end + end + + context "when user is signed in" do + before do + allow(user).to receive(:need_two_factor_authentication?).and_return(false) + sign_in user + end + + context "with multiple duplicate lettings logs" do + let(:duplicate_logs) { create_list(:lettings_log, 2, :completed) } + + before do + allow(LettingsLog).to receive(:duplicate_logs).and_return(duplicate_logs) + get "/lettings-logs/#{lettings_log.id}/duplicate-logs" + end + + it "displays links to all the duplicate logs" do + expect(page).to have_link("Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}") + expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/lettings-logs/#{duplicate_logs.first.id}") + expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/lettings-logs/#{duplicate_logs.second.id}") + end + + it "displays check your answers for each log with correct questions" do + expect(page).to have_content("Q5 - Tenancy start date", count: 3) + expect(page).to have_content("Q7 - Tenant code", count: 3) + expect(page).to have_content("Q12 - Postcode", count: 3) + expect(page).to have_content("Q32 - Lead tenant’s age", count: 3) + expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3) + expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3) + expect(page).to have_content("Household rent and charges", count: 3) + expect(page).to have_link("Change", count: 21) + end + + it "displays buttons to delete" do + expect(page).to have_link("Keep this log and delete duplicates", count: 3) + end + end + + context "with multiple duplicate sales logs" do + let(:duplicate_logs) { create_list(:sales_log, 2, :completed) } + + before do + allow(SalesLog).to receive(:duplicate_logs).and_return(duplicate_logs) + get "/sales-logs/#{sales_log.id}/duplicate-logs" + end + + it "displays links to all the duplicate logs" do + expect(page).to have_link("Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}") + expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/sales-logs/#{duplicate_logs.first.id}") + expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/sales-logs/#{duplicate_logs.second.id}") + end + + it "displays check your answers for each log with correct questions" do + expect(page).to have_content("Q1 - Sale completion date", count: 3) + expect(page).to have_content("Q2 - Purchaser code", count: 3) + expect(page).to have_content("Q20 - Lead buyer’s age", count: 3) + expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3) + expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3) + expect(page).to have_content("Q15 - Postcode", count: 3) + expect(page).to have_link("Change", count: 18) + end + + it "displays buttons to delete" do + expect(page).to have_link("Keep this log and delete duplicates", count: 3) + end + end + end + end + end +end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 0f086d27a..a6143f91a 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -532,6 +532,54 @@ RSpec.describe FormController, type: :request do expect(whodunnit_actor).to be_a(User) expect(whodunnit_actor.id).to eq(user.id) end + + context "and duplicate logs" do + let(:duplicate_logs) { create_list(:lettings_log, 2) } + + before do + allow(LettingsLog).to receive(:duplicate_logs).and_return(duplicate_logs) + post "/lettings-logs/#{lettings_log.id}/#{page_id.dasherize}", params: + end + + it "redirects to the duplicate logs page" do + expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}/duplicate-logs") + follow_redirect! + expect(page).to have_content("These logs are duplicates") + end + end + end + + context "with valid sales answers" do + let(:sales_log) do + create( + :sales_log, + created_by: user, + ) + end + let(:params) do + { + id: sales_log.id, + sales_log: { + page: "buyer-1-age", + age1: 20, + }, + } + end + + context "and duplicate logs" do + let(:duplicate_logs) { create_list(:sales_log, 2) } + + before do + allow(SalesLog).to receive(:duplicate_logs).and_return(duplicate_logs) + post "/sales-logs/#{sales_log.id}/buyer-1-age", params: + end + + it "redirects to the duplicate logs page" do + expect(response).to redirect_to("/sales-logs/#{sales_log.id}/duplicate-logs") + follow_redirect! + expect(page).to have_content("These logs are duplicates") + end + end end context "when the question has a conditional question" do diff --git a/spec/services/bulk_upload/lettings/validator_spec.rb b/spec/services/bulk_upload/lettings/validator_spec.rb index 26134735e..fa913e091 100644 --- a/spec/services/bulk_upload/lettings/validator_spec.rb +++ b/spec/services/bulk_upload/lettings/validator_spec.rb @@ -305,7 +305,7 @@ RSpec.describe BulkUpload::Lettings::Validator do end it "creates errors" do - expect { validator.call }.to change(BulkUploadError.where(category: :setup, error: "This is a duplicate of a log in your file"), :count).by(22) + expect { validator.call }.to change(BulkUploadError.where(category: :setup, error: "This is a duplicate of a log in your file"), :count).by(20) end end diff --git a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb index 4d2c28ee8..b91caa969 100644 --- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb @@ -258,7 +258,6 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do field_96: [error_message], # startdate field_97: [error_message], # startdate field_98: [error_message], # startdate - field_100: [error_message], # propcode field_108: [error_message], # postcode_full field_109: [error_message], # postcode_full field_111: [error_message], # owning_organisation @@ -295,7 +294,6 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do :field_96, # startdate :field_97, # startdate :field_98, # startdate - :field_100, # propcode :field_111, # owning_organisation ].each do |field| expect(parser.errors[field]).to include("This is a duplicate log") @@ -329,7 +327,6 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do :field_96, # startdate :field_97, # startdate :field_98, # startdate - :field_100, # propcode :field_108, # postcode_full :field_109, # postcode_full :field_111, # owning_organisation diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index e177eb859..e12785738 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -289,7 +289,6 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do :field_8, # startdate :field_9, # startdate :field_13, # tenancycode - :field_14, # propcode :field_23, # postcode_full :field_24, # postcode_full :field_25, # postcode_full @@ -328,7 +327,6 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do :field_8, # startdate :field_9, # startdate :field_13, # tenancycode - :field_14, # propcode :field_17, # location :field_46, # age1 :field_47, # sex1 @@ -363,7 +361,6 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do :field_7, # startdate :field_8, # startdate :field_9, # startdate - :field_14, # propcode :field_17, # location :field_23, # postcode_full :field_24, # postcode_full