Browse Source

CLDC-2671 Update duplicate logs routing (#1983)

* feat: add param to banner duplicate logs route

* feat: pass org id param through for support user case

* feat: update tests

* feat: lint

* feat: add one more org id param to change links

* feat: add duplicate logs controller tests

* feat: update duplicate log tests

* feat: tests no duplicates page

* feat: test params passed correctly on delete

* refactor: lint

* refactor: lint
pull/1988/head
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
d4d93ee44c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/controllers/delete_logs_controller.rb
  2. 14
      app/controllers/duplicate_logs_controller.rb
  3. 6
      app/controllers/form_controller.rb
  4. 9
      app/helpers/duplicate_logs_helper.rb
  5. 6
      app/services/csv/sales_log_csv_service.rb
  6. 4
      app/views/duplicate_logs/index.html.erb
  7. 11
      app/views/duplicate_logs/no_more_duplicates.html.erb
  8. 6
      app/views/logs/delete_duplicates.html.erb
  9. 2
      app/views/logs/index.html.erb
  10. 2
      app/views/organisations/logs.html.erb
  11. 8
      spec/features/lettings_log_spec.rb
  12. 8
      spec/features/sales_log_spec.rb
  13. 795
      spec/requests/duplicate_logs_controller_spec.rb

4
app/controllers/delete_logs_controller.rb

@ -27,7 +27,7 @@ class DeleteLogsController < ApplicationController
logs = LettingsLog.find(params.require(:ids))
discard logs
if request.referer&.include?("delete-duplicates")
redirect_to lettings_log_duplicate_logs_path(lettings_log_id: params["remaining_log_id"], original_log_id: params["original_log_id"]), notice: I18n.t("notification.duplicate_logs_deleted", count: logs.count, log_ids: duplicate_log_ids(logs))
redirect_to lettings_log_duplicate_logs_path(lettings_log_id: params["remaining_log_id"], original_log_id: params["original_log_id"], referrer: params[:referrer], organisation_id: params[:organisation_id]), notice: I18n.t("notification.duplicate_logs_deleted", count: logs.count, log_ids: duplicate_log_ids(logs))
else
redirect_to lettings_logs_path, notice: I18n.t("notification.logs_deleted", count: logs.count)
end
@ -56,7 +56,7 @@ class DeleteLogsController < ApplicationController
logs = SalesLog.find(params.require(:ids))
discard logs
if request.referer&.include?("delete-duplicates")
redirect_to sales_log_duplicate_logs_path(sales_log_id: params["remaining_log_id"], original_log_id: params["original_log_id"]), notice: I18n.t("notification.duplicate_logs_deleted", count: logs.count, log_ids: duplicate_log_ids(logs))
redirect_to sales_log_duplicate_logs_path(sales_log_id: params["remaining_log_id"], original_log_id: params["original_log_id"], referrer: params[:referrer], organisation_id: params[:organisation_id]), notice: I18n.t("notification.duplicate_logs_deleted", count: logs.count, log_ids: duplicate_log_ids(logs))
else
redirect_to sales_logs_path, notice: I18n.t("notification.logs_deleted", count: logs.count)
end

14
app/controllers/duplicate_logs_controller.rb

@ -5,6 +5,7 @@ class DuplicateLogsController < ApplicationController
before_action :find_resource_by_named_id
before_action :find_duplicates_for_a_log
before_action :find_original_log
before_action :find_organisation, only: [:index]
before_action :find_all_duplicates, only: [:index]
def show
@ -26,10 +27,8 @@ class DuplicateLogsController < ApplicationController
end
def index
render_not_found if @duplicates.blank?
@duplicate_sets_count = @duplicates[:lettings].count + @duplicates[:sales].count
render_not_found if @duplicate_sets_count.zero?
render "duplicate_logs/no_more_duplicates" if @duplicate_sets_count.zero?
end
private
@ -55,10 +54,9 @@ private
def find_all_duplicates
return @duplicates = duplicates_for_user(current_user) if current_user.data_provider?
organisation = current_user.support? ? Organisation.find(params[:organisation_id]) : current_user.organisation
return unless organisation
return unless @organisation
@duplicates = duplicates_for_organisation(organisation)
@duplicates = duplicates_for_organisation(@organisation)
end
def duplicate_check_question_ids
@ -89,4 +87,8 @@ private
current_user.lettings_logs.find_by(id: original_log_id)
end
end
def find_organisation
@organisation = current_user.support? ? Organisation.find(params[:organisation_id]) : current_user.organisation
end
end

6
app/controllers/form_controller.rb

@ -165,7 +165,7 @@ private
def successful_redirect_path
if FeatureToggle.deduplication_flow_enabled?
if is_referrer_type?("duplicate_logs")
if is_referrer_type?("duplicate_logs") || is_referrer_type?("duplicate_logs_banner")
return correcting_duplicate_logs_redirect_path
end
@ -251,10 +251,10 @@ private
if original_log.present? && current_user.send(class_name.pluralize).duplicate_logs(original_log).count.positive?
flash[:notice] = deduplication_success_banner unless current_user.send(class_name.pluralize).duplicate_logs(@log).count.positive?
send("#{class_name}_duplicate_logs_path", original_log, original_log_id: original_log.id)
send("#{class_name}_duplicate_logs_path", original_log, original_log_id: original_log.id, referrer: params[:referrer], organisation_id: params[:organisation_id])
else
flash[:notice] = deduplication_success_banner
send("#{class_name}_duplicate_logs_path", "#{class_name}_id".to_sym => from_referrer_query("first_remaining_duplicate_id"), original_log_id: from_referrer_query("original_log_id"))
send("#{class_name}_duplicate_logs_path", "#{class_name}_id".to_sym => from_referrer_query("first_remaining_duplicate_id"), original_log_id: from_referrer_query("original_log_id"), referrer: params[:referrer], organisation_id: params[:organisation_id])
end
end

9
app/helpers/duplicate_logs_helper.rb

@ -8,10 +8,13 @@ module DuplicateLogsHelper
action: "delete_duplicates",
"#{duplicate_log.class.name.underscore}_id": duplicate_log.id,
original_log_id: original_log.id,
referrer: params[:referrer],
organisation_id: params[:organisation_id],
)
end
if !original_log.deleted?
if params[:referrer] == "duplicate_logs_banner"
current_user.support? ? govuk_button_link_to("Review other duplicates", organisation_duplicates_path(organisation_id: params[:organisation_id], referrer: params[:referrer])) : govuk_button_link_to("Review other duplicates", duplicate_logs_path(referrer: params[:referrer]))
elsif !original_log.deleted?
govuk_button_link_to "Back to Log #{original_log.id}", send("#{original_log.class.name.underscore}_path", original_log)
else
type = duplicate_log.lettings? ? "lettings" : "sales"
@ -25,7 +28,7 @@ module DuplicateLogsHelper
def change_duplicate_logs_action_href(log, page_id, all_duplicates, original_log_id)
first_remaining_duplicate_id = all_duplicates.map(&:id).reject { |id| id == log.id }.first
send("#{log.model_name.param_key}_#{page_id}_path", log, referrer: "duplicate_logs", first_remaining_duplicate_id:, original_log_id:)
send("#{log.model_name.param_key}_#{page_id}_path", log, referrer: params[:referrer] == "duplicate_logs_banner" ? "duplicate_logs_banner" : "duplicate_logs", first_remaining_duplicate_id:, original_log_id:, organisation_id: params[:organisation_id])
end
def duplicates_for_user(user)

6
app/services/csv/sales_log_csv_service.rb

@ -58,12 +58,6 @@ module Csv
end
}.freeze
AGE_KNOWN_FIELDS = {}.tap { |hash|
(1..6).each do |i|
hash["age#{i}"] = { "age_known_field" => "age#{i}_known" }
end
}.freeze
FIELDS_ALWAYS_EXPORTED_AS_CODES = %w[
la
prevloc

4
app/views/duplicate_logs/index.html.erb

@ -24,7 +24,7 @@
<% row.cell text: "Lettings" %>
<% row.cell text: duplicate_set.map { |id| "Log #{id}" }.join(", ") %>
<% row.cell do %>
<%= govuk_link_to "Review logs", lettings_log_duplicate_logs_path(duplicate_set.first, original_log_id: duplicate_set.first) %>
<%= govuk_link_to "Review logs", lettings_log_duplicate_logs_path(duplicate_set.first, original_log_id: duplicate_set.first, referrer: params[:referrer], organisation_id: params[:organisation_id]) %>
<% end %>
<% end %>
<% end %>
@ -33,7 +33,7 @@
<% row.cell text: "Sales" %>
<% row.cell text: duplicate_set.map { |id| "Log #{id}" }.join(", ") %>
<% row.cell do %>
<%= govuk_link_to "Review logs", sales_log_duplicate_logs_path(duplicate_set.first, original_log_id: duplicate_set.first) %>
<%= govuk_link_to "Review logs", sales_log_duplicate_logs_path(duplicate_set.first, original_log_id: duplicate_set.first, referrer: params[:referrer], organisation_id: params[:organisation_id]) %>
<% end %>
<% end %>
<% end %>

11
app/views/duplicate_logs/no_more_duplicates.html.erb

@ -0,0 +1,11 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">There are no more duplicate logs</h1>
</div>
</div>
<p class="govuk-body">
You have either changed or deleted all the duplicate logs.
</p>
<%= govuk_button_link_to "Back to all logs", lettings_logs_path %>

6
app/views/logs/delete_duplicates.html.erb

@ -1,6 +1,6 @@
<% content_for :before_content do %>
<% content_for :title, "Are you sure you want to delete #{@duplicate_logs.count == 1 ? 'this duplicate log' : 'these duplicate logs'}?" %>
<%= govuk_back_link href: @log.lettings? ? lettings_log_duplicate_logs_path(@original_log, original_log_id: @original_log.id) : sales_log_duplicate_logs_path(@original_log, original_log_id: @original_log.id) %>
<%= govuk_back_link href: @log.lettings? ? lettings_log_duplicate_logs_path(@original_log, original_log_id: @original_log.id, referrer: params[:referrer], organisation_id: params[:organisation_id]) : sales_log_duplicate_logs_path(@original_log, original_log_id: @original_log.id, referrer: params[:referrer], organisation_id: params[:organisation_id]) %>
<% end %>
<div class="govuk-grid-row">
@ -29,10 +29,10 @@
<%= govuk_button_to @duplicate_logs.count == 1 ? "Delete this log" : "Delete these logs",
send("delete_logs_#{@log.class.name.underscore}s_path"),
method: "delete",
params: { ids: @duplicate_logs.map(&:id), original_log_id: @original_log.id, remaining_log_id: @log.id } %>
params: { ids: @duplicate_logs.map(&:id), original_log_id: @original_log.id, remaining_log_id: @log.id, referrer: params[:referrer], organisation_id: params[:organisation_id] } %>
<%= govuk_button_link_to(
"Cancel",
send("#{@log.class.name.underscore}_duplicate_logs_path", @original_log, original_log_id: @original_log.id),
send("#{@log.class.name.underscore}_duplicate_logs_path", @original_log, original_log_id: @original_log.id, referrer: params[:referrer], organisation_id: params[:organisation_id]),
secondary: true,
) %>
</div>

2
app/views/logs/index.html.erb

@ -9,7 +9,7 @@
) %>
<% if @duplicate_sets_count&.positive? %>
<%= govuk_notification_banner(title_text: "Important", text: govuk_link_to("Review logs", duplicate_logs_path)) do |banner| %>
<%= govuk_notification_banner(title_text: "Important", text: govuk_link_to("Review logs", duplicate_logs_path(referrer: "duplicate_logs_banner"))) do |banner| %>
<% banner.with_heading(text: I18n.t("notification.duplicate_sets", count: @duplicate_sets_count)) %>
<% end %>
<% end %>

2
app/views/organisations/logs.html.erb

@ -11,7 +11,7 @@
) %>
<% if @duplicate_sets_count&.positive? %>
<%= govuk_notification_banner(title_text: "Important", text: govuk_link_to("Review logs", organisation_duplicates_path(@organisation))) do |banner| %>
<%= govuk_notification_banner(title_text: "Important", text: govuk_link_to("Review logs", organisation_duplicates_path(@organisation, referrer: "duplicate_logs_banner"))) do |banner| %>
<% banner.with_heading(text: I18n.t("notification.duplicate_sets", count: @duplicate_sets_count)) %>
<% end %>
<% end %>

8
spec/features/lettings_log_spec.rb

@ -467,7 +467,7 @@ RSpec.describe "Lettings Log Features" do
expect(duplicate_log.deleted?).to be true
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{duplicate_log.id} has been deleted.")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/duplicate-logs?organisation_id=&original_log_id=#{lettings_log.id}&referrer=")
expect(page).not_to have_content("These logs are duplicates")
expect(page).not_to have_link("Keep this log and delete duplicates")
expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
@ -491,7 +491,7 @@ RSpec.describe "Lettings Log Features" do
expect(lettings_log.status).to eq("deleted")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{lettings_log.id} has been deleted.")
expect(page).to have_current_path("/lettings-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}")
expect(page).to have_current_path("/lettings-logs/#{duplicate_log.id}/duplicate-logs?organisation_id=&original_log_id=#{lettings_log.id}&referrer=")
expect(page).not_to have_content("These logs are duplicates")
expect(page).not_to have_link("Keep this log and delete duplicates")
expect(page).to have_link("Back to lettings logs", href: "/lettings-logs")
@ -511,7 +511,7 @@ RSpec.describe "Lettings Log Features" do
click_link("Change", href: "/lettings-logs/#{duplicate_log.id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
fill_in("lettings-log-tenancycode-field", with: "something else")
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{duplicate_log.id} is no longer a duplicate and has been removed from the list")
@ -522,7 +522,7 @@ RSpec.describe "Lettings Log Features" do
click_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
fill_in("lettings-log-tenancycode-field", with: "something else")
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}")
expect(page).to have_current_path("/lettings-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{lettings_log.id} is no longer a duplicate and has been removed from the list")

8
spec/features/sales_log_spec.rb

@ -206,7 +206,7 @@ RSpec.describe "Sales Log Features" do
expect(duplicate_log.deleted?).to be true
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{duplicate_log.id} has been deleted.")
expect(page).to have_current_path("/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}")
expect(page).to have_current_path("/sales-logs/#{sales_log.id}/duplicate-logs?organisation_id=&original_log_id=#{sales_log.id}&referrer=")
expect(page).not_to have_content("These logs are duplicates")
expect(page).not_to have_link("Keep this log and delete duplicates")
expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
@ -230,7 +230,7 @@ RSpec.describe "Sales Log Features" do
expect(sales_log.status).to eq("deleted")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{sales_log.id} has been deleted.")
expect(page).to have_current_path("/sales-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{sales_log.id}")
expect(page).to have_current_path("/sales-logs/#{duplicate_log.id}/duplicate-logs?organisation_id=&original_log_id=#{sales_log.id}&referrer=")
expect(page).not_to have_content("These logs are duplicates")
expect(page).not_to have_link("Keep this log and delete duplicates")
expect(page).to have_link("Back to sales logs", href: "/sales-logs")
@ -250,7 +250,7 @@ RSpec.describe "Sales Log Features" do
click_link("Change", href: "/sales-logs/#{duplicate_log.id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
fill_in("sales-log-purchid-field", with: "something else")
click_button("Save and continue")
expect(page).to have_current_path("/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}")
expect(page).to have_current_path("/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{duplicate_log.id} is no longer a duplicate and has been removed from the list")
@ -261,7 +261,7 @@ RSpec.describe "Sales Log Features" do
click_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
fill_in("sales-log-purchid-field", with: "something else")
click_button("Save and continue")
expect(page).to have_current_path("/sales-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{sales_log.id}")
expect(page).to have_current_path("/sales-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{sales_log.id} is no longer a duplicate and has been removed from the list")

795
spec/requests/duplicate_logs_controller_spec.rb

@ -29,145 +29,398 @@ RSpec.describe DuplicateLogsController, type: :request do
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 "when viewing lettings logs duplicates" do
context "when there are multiple duplicate 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?original_log_id=#{lettings_log.id}"
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
context "when user is support" do
let(:support_user_org) { create(:organisation) }
let(:user) { create(:user, :support, organisation: support_user_org) }
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)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[0].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[1].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
end
it "displays buttons to delete" do
expect(page).to have_link("Keep this log and delete duplicates", count: 3)
expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{lettings_log.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.first.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.second.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
end
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
end
context "when there are no more duplicate logs" do
before do
allow(LettingsLog).to receive(:duplicate_logs).and_return(LettingsLog.none)
get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}"
context "when viewing lettings logs duplicates" do
context "when there are multiple duplicate 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?original_log_id=#{lettings_log.id}&organisation_id=#{lettings_log.owning_organisation_id}"
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: 24)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[0].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[1].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
end
it "displays buttons to delete" do
expect(page).to have_link("Keep this log and delete duplicates", count: 3)
expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{lettings_log.id}/delete-duplicates?organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.first.id}/delete-duplicates?organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.second.id}/delete-duplicates?organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}")
end
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 1)
expect(page).to have_content("Q7 - Tenant code", count: 1)
expect(page).to have_content("Q12 - Postcode", count: 1)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
expect(page).to have_content("Household rent and charges", count: 1)
expect(page).to have_link("Change", count: 7)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
context "when there are no more duplicate logs" do
context "when accessed from the duplicate logs banner flow" do
before do
allow(LettingsLog).to receive(:duplicate_logs).and_return(LettingsLog.none)
get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&organisation_id=#{lettings_log.owning_organisation_id}&referrer=duplicate_logs_banner"
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 1)
expect(page).to have_content("Q7 - Tenant code", count: 1)
expect(page).to have_content("Q12 - Postcode", count: 1)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
expect(page).to have_content("Household rent and charges", count: 1)
expect(page).to have_link("Change", count: 8)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
end
it "displays button to review other duplicates" do
expect(page).to have_link("Review other duplicates", href: "/organisations/#{lettings_log.owning_organisation_id}/duplicates?referrer=duplicate_logs_banner")
end
it "displays no duplicates banner" do
expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
end
end
context "when accessed from the single log submission flow" do
before do
allow(LettingsLog).to receive(:duplicate_logs).and_return(LettingsLog.none)
get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&organisation_id=#{lettings_log.owning_organisation_id}"
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 1)
expect(page).to have_content("Q7 - Tenant code", count: 1)
expect(page).to have_content("Q12 - Postcode", count: 1)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
expect(page).to have_content("Household rent and charges", count: 1)
expect(page).to have_link("Change", count: 8)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
end
it "displays button to return to log" do
expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
end
it "displays no duplicates banner" do
expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
end
end
end
end
it "displays buttons to return to log" do
expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
context "when viewing sales logs duplicates" do
context "when there are multiple duplicate 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?original_log_id=#{sales_log.id}&organisation_id=#{sales_log.owning_organisation_id}"
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: 21)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[1].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
end
it "displays buttons to delete" do
expect(page).to have_link("Keep this log and delete duplicates", count: 3)
expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{sales_log.id}/delete-duplicates?organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.first.id}/delete-duplicates?organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.second.id}/delete-duplicates?organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}")
end
end
it "displays no duplicates banner" do
expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
context "when there are no more duplicate logs" do
context "when accessed from the duplicate logs banner flow" do
before do
allow(SalesLog).to receive(:duplicate_logs).and_return(SalesLog.none)
get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&referrer=duplicate_logs_banner&organisation_id=#{sales_log.owning_organisation_id}"
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1)
expect(page).to have_link("Change", count: 7)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
end
it "displays button to review other duplicates" do
expect(page).to have_link("Review other duplicates", href: "/organisations/#{sales_log.owning_organisation_id}/duplicates?referrer=duplicate_logs_banner")
end
it "displays no duplicates banner" do
expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
end
end
context "when accessed from the single log submission flow" do
before do
allow(SalesLog).to receive(:duplicate_logs).and_return(SalesLog.none)
get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&organisation_id=#{sales_log.owning_organisation_id}"
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1)
expect(page).to have_link("Change", count: 7)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
end
it "displays button to return to log" do
expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
end
it "displays no duplicates banner" do
expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
end
end
end
end
end
context "when viewing sales logs duplicates" do
context "when there are multiple duplicate 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?original_log_id=#{sales_log.id}"
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)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[1].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
end
it "displays buttons to delete" do
expect(page).to have_link("Keep this log and delete duplicates", count: 3)
expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{sales_log.id}/delete-duplicates?original_log_id=#{sales_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.first.id}/delete-duplicates?original_log_id=#{sales_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.second.id}/delete-duplicates?original_log_id=#{sales_log.id}")
end
context "when user is a data provider" do
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
end
context "when there are no more duplicate logs" do
before do
allow(SalesLog).to receive(:duplicate_logs).and_return(SalesLog.none)
get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}"
context "when viewing lettings logs duplicates" do
context "when there are multiple duplicate 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?original_log_id=#{lettings_log.id}"
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)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[0].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[1].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
end
it "displays buttons to delete" do
expect(page).to have_link("Keep this log and delete duplicates", count: 3)
expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{lettings_log.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.first.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.second.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
end
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1)
expect(page).to have_link("Change", count: 6)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
context "when there are no more duplicate logs" do
context "when accessed from the duplicate logs banner flow" do
before do
allow(LettingsLog).to receive(:duplicate_logs).and_return(LettingsLog.none)
get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&referrer=duplicate_logs_banner"
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 1)
expect(page).to have_content("Q7 - Tenant code", count: 1)
expect(page).to have_content("Q12 - Postcode", count: 1)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
expect(page).to have_content("Household rent and charges", count: 1)
expect(page).to have_link("Change", count: 7)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
end
it "displays button to review other duplicates" do
expect(page).to have_link("Review other duplicates", href: "/duplicate-logs?referrer=duplicate_logs_banner")
end
it "displays no duplicates banner" do
expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
end
end
context "when accessed from the single log submission flow" do
before do
allow(LettingsLog).to receive(:duplicate_logs).and_return(LettingsLog.none)
get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}"
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 1)
expect(page).to have_content("Q7 - Tenant code", count: 1)
expect(page).to have_content("Q12 - Postcode", count: 1)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
expect(page).to have_content("Household rent and charges", count: 1)
expect(page).to have_link("Change", count: 7)
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
end
it "displays button to return to log" do
expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
end
it "displays no duplicates banner" do
expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
end
end
end
end
it "displays buttons to return to log" do
expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
context "when viewing sales logs duplicates" do
context "when there are multiple duplicate 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?original_log_id=#{sales_log.id}"
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)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[1].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
end
it "displays buttons to delete" do
expect(page).to have_link("Keep this log and delete duplicates", count: 3)
expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{sales_log.id}/delete-duplicates?original_log_id=#{sales_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.first.id}/delete-duplicates?original_log_id=#{sales_log.id}")
expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.second.id}/delete-duplicates?original_log_id=#{sales_log.id}")
end
end
it "displays no duplicates banner" do
expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
context "when there are no more duplicate logs" do
context "when accessed from the duplicate logs banner flow" do
before do
allow(SalesLog).to receive(:duplicate_logs).and_return(SalesLog.none)
get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&referrer=duplicate_logs_banner"
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1)
expect(page).to have_link("Change", count: 6)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
end
it "displays button to review other duplicates" do
expect(page).to have_link("Review other duplicates", href: "/duplicate-logs?referrer=duplicate_logs_banner")
end
it "displays no duplicates banner" do
expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
end
end
context "when accessed from the single log submission flow" do
before do
allow(SalesLog).to receive(:duplicate_logs).and_return(SalesLog.none)
get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}"
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1)
expect(page).to have_link("Change", count: 6)
expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
end
it "displays button to return to log" do
expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
end
it "displays no duplicates banner" do
expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
end
end
end
end
end
end
end
describe "GET sales delete-duplicates" do
let(:headers) { { "Accept" => "text/html" } }
let(:id) { sales_log.id }
let(:request) { get "/sales-logs/#{id}/delete-duplicates?original_log_id=#{id}" }
describe "GET lettings delete-duplicates" do
let(:id) { lettings_log.id }
let(:request) { get "/lettings-logs/#{id}/delete-duplicates?original_log_id=#{id}" }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -175,43 +428,85 @@ RSpec.describe DuplicateLogsController, type: :request do
end
context "when there are no duplicate logs" do
it "renders not found" do
it "renders page not found" do
request
expect(response).to have_http_status(:not_found)
end
end
context "when there is 1 duplicate log being deleted" do
let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
context "when accessed from the duplicate logs banner flow" do
let(:request) { get "/lettings-logs/#{id}/delete-duplicates?original_log_id=#{id}&referrer=duplicate_logs_banner" }
it "renders page" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete this duplicate log?")
expect(page).to have_button(text: "Delete this log")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
expect(page).not_to have_link(text: "Log #{id}", href: sales_log_path(id))
expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id))
expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id))
context "when there is 1 duplicate log being deleted" do
let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
it "renders page with correct link params" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete this duplicate log?")
expect(page).to have_content("This log will be deleted:")
expect(page).to have_button(text: "Delete this log")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
expect(page).not_to have_link(text: "Log #{id}", href: lettings_log_path(id))
expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
end
end
context "when there are multiple duplicate logs being deleted" do
let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
let!(:duplicate_log_2) { create(:lettings_log, :duplicate, created_by: user) }
it "renders page with correct link params" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
expect(page).to have_content("These logs will be deleted:")
expect(page).to have_button(text: "Delete these logs")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: lettings_log_path(duplicate_log_2.id))
expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
end
end
end
context "when there are multiple duplicate logs being deleted" do
let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
let!(:duplicate_log_2) { create(:sales_log, :duplicate, created_by: user) }
context "when accessed from the single log submission flow" do
context "when there is 1 duplicate log being deleted" do
let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
it "renders page" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete this duplicate log?")
expect(page).to have_content("This log will be deleted:")
expect(page).to have_button(text: "Delete this log")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
expect(page).not_to have_link(text: "Log #{id}", href: lettings_log_path(id))
expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
end
end
it "renders page" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
expect(page).to have_content("These logs will be deleted:")
expect(page).to have_button(text: "Delete these logs")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: sales_log_path(duplicate_log_2.id))
expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id))
expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id))
context "when there are multiple duplicate logs being deleted" do
let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
let!(:duplicate_log_2) { create(:lettings_log, :duplicate, created_by: user) }
it "renders page" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
expect(page).to have_content("These logs will be deleted:")
expect(page).to have_button(text: "Delete these logs")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: lettings_log_path(duplicate_log_2.id))
expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
end
end
end
@ -239,9 +534,10 @@ RSpec.describe DuplicateLogsController, type: :request do
end
end
describe "GET lettings delete-duplicates" do
let(:id) { lettings_log.id }
let(:request) { get "/lettings-logs/#{id}/delete-duplicates?original_log_id=#{id}" }
describe "GET sales delete-duplicates" do
let(:headers) { { "Accept" => "text/html" } }
let(:id) { sales_log.id }
let(:request) { get "/sales-logs/#{id}/delete-duplicates?original_log_id=#{id}" }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -249,44 +545,85 @@ RSpec.describe DuplicateLogsController, type: :request do
end
context "when there are no duplicate logs" do
it "renders page not found" do
it "renders not found" do
request
expect(response).to have_http_status(:not_found)
end
end
context "when there is 1 duplicate log being deleted" do
let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
context "when accessed from the duplicate logs banner flow" do
let(:request) { get "/sales-logs/#{id}/delete-duplicates?original_log_id=#{id}&referrer=duplicate_logs_banner" }
it "renders page" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete this duplicate log?")
expect(page).to have_content("This log will be deleted:")
expect(page).to have_button(text: "Delete this log")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
expect(page).not_to have_link(text: "Log #{id}", href: lettings_log_path(id))
expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
context "when there is 1 duplicate log being deleted" do
let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
it "renders page with correct link params" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete this duplicate log?")
expect(page).to have_content("This log will be deleted:")
expect(page).to have_button(text: "Delete this log")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
expect(page).not_to have_link(text: "Log #{id}", href: sales_log_path(id))
expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
end
end
context "when there are multiple duplicate logs being deleted" do
let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
let!(:duplicate_log_2) { create(:sales_log, :duplicate, created_by: user) }
it "renders page with correct link params" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
expect(page).to have_content("These logs will be deleted:")
expect(page).to have_button(text: "Delete these logs")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: sales_log_path(duplicate_log_2.id))
expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
end
end
end
context "when there are multiple duplicate logs being deleted" do
let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
let!(:duplicate_log_2) { create(:lettings_log, :duplicate, created_by: user) }
context "when accessed from the single log submission flow" do
context "when there is 1 duplicate log being deleted" do
let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
it "renders page" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete this duplicate log?")
expect(page).to have_content("This log will be deleted:")
expect(page).to have_button(text: "Delete this log")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
expect(page).not_to have_link(text: "Log #{id}", href: sales_log_path(id))
expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id))
expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id))
end
end
it "renders page" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
expect(page).to have_content("These logs will be deleted:")
expect(page).to have_button(text: "Delete these logs")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: lettings_log_path(duplicate_log_2.id))
expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
context "when there are multiple duplicate logs being deleted" do
let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
let!(:duplicate_log_2) { create(:sales_log, :duplicate, created_by: user) }
it "renders page" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
expect(page).to have_content("These logs will be deleted:")
expect(page).to have_button(text: "Delete these logs")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: sales_log_path(duplicate_log_2.id))
expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id))
expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id))
end
end
end
@ -323,9 +660,64 @@ RSpec.describe DuplicateLogsController, type: :request do
context "when the user is support" do
let(:user) { create(:user, :support) }
it "renders not found" do
get duplicate_logs_path(organisation_id: user.organisation.id)
expect(response).to have_http_status(:not_found)
before do
allow(Organisation).to receive(:find).with(user.organisation_id.to_s).and_return(user.organisation)
allow(user.organisation).to receive(:duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]])
allow(user.organisation).to receive(:duplicate_sales_logs_sets).and_return([[11, 12]])
end
it "gets organisation duplicates" do
expect(user.organisation).to receive(:duplicate_lettings_logs_sets)
expect(user.organisation).to receive(:duplicate_sales_logs_sets)
get organisation_duplicates_path(organisation_id: user.organisation_id)
end
describe "viewing the page" do
context "when there are duplicate logs" do
before do
get organisation_duplicates_path(organisation_id: user.organisation_id)
end
it "has the correct headers" do
expect(page).to have_content("Type of logs")
expect(page).to have_content("Log IDs")
end
it "has the correct number of rows for each log type" do
expect(page).to have_selector("tbody tr td", text: "Lettings", count: 2)
expect(page).to have_selector("tbody tr td", text: "Sales", count: 1)
end
it "shows the log ids for each set of duplicates" do
expect(page).to have_content("Log 1, Log 2")
expect(page).to have_content("Log 3, Log 4, Log 5")
expect(page).to have_content("Log 11, Log 12")
end
it "shows links for each set of duplicates" do
expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(1, original_log_id: 1, organisation_id: user.organisation_id))
expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(3, original_log_id: 3, organisation_id: user.organisation_id))
expect(page).to have_link("Review logs", href: sales_log_duplicate_logs_path(11, original_log_id: 11, organisation_id: user.organisation_id))
end
end
context "when there are no duplicate logs" do
before do
allow(Organisation).to receive(:find).with(user.organisation_id.to_s).and_return(user.organisation)
allow(user.organisation).to receive(:duplicate_lettings_logs_sets).and_return([])
allow(user.organisation).to receive(:duplicate_sales_logs_sets).and_return([])
get organisation_duplicates_path(organisation_id: user.organisation_id)
end
it "has the correct headers" do
expect(page).to have_content("There are no more duplicate logs")
expect(page).to have_content("You have either changed or deleted all the duplicate logs.")
end
it "shows back to all logs button" do
expect(page).to have_link("Back to all logs", href: lettings_logs_path)
end
end
end
end
@ -359,30 +751,49 @@ RSpec.describe DuplicateLogsController, type: :request do
end
describe "viewing the page" do
before do
get duplicate_logs_path
end
context "when there are duplicate logs" do
before do
get duplicate_logs_path
end
it "has the correct headers" do
expect(page).to have_content("Type of logs")
expect(page).to have_content("Log IDs")
end
it "has the correct headers" do
expect(page).to have_content("Type of logs")
expect(page).to have_content("Log IDs")
end
it "has the correct number of rows for each log type" do
expect(page).to have_selector("tbody tr td", text: "Lettings", count: 2)
expect(page).to have_selector("tbody tr td", text: "Sales", count: 1)
end
it "has the correct number of rows for each log type" do
expect(page).to have_selector("tbody tr td", text: "Lettings", count: 2)
expect(page).to have_selector("tbody tr td", text: "Sales", count: 1)
end
it "shows the log ids for each set of duplicates" do
expect(page).to have_content("Log 1, Log 2")
expect(page).to have_content("Log 3, Log 4, Log 5")
expect(page).to have_content("Log 11, Log 12")
end
it "shows the log ids for each set of duplicates" do
expect(page).to have_content("Log 1, Log 2")
expect(page).to have_content("Log 3, Log 4, Log 5")
expect(page).to have_content("Log 11, Log 12")
it "shows links for each set of duplicates" do
expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(1, original_log_id: 1))
expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(3, original_log_id: 3))
expect(page).to have_link("Review logs", href: sales_log_duplicate_logs_path(11, original_log_id: 11))
end
end
it "shows links for each set of duplciates" do
expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(1, original_log_id: 1))
expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(3, original_log_id: 3))
expect(page).to have_link("Review logs", href: sales_log_duplicate_logs_path(11, original_log_id: 11))
context "when there are no duplicate logs" do
before do
allow(user).to receive(:duplicate_lettings_logs_sets).and_return([])
allow(user).to receive(:duplicate_sales_logs_sets).and_return([])
get duplicate_logs_path
end
it "has the correct headers" do
expect(page).to have_content("There are no more duplicate logs")
expect(page).to have_content("You have either changed or deleted all the duplicate logs.")
end
it "shows back to all logs button" do
expect(page).to have_link("Back to all logs", href: lettings_logs_path)
end
end
end
end

Loading…
Cancel
Save