Browse Source
* create helper module to find all logs for a given user that have duplicates write associated tests update methods on user model to retrieve logs related to a given user create a scope on logs to retrieve logs created by a given user * check for duplicates and display notification banner on the index page where appropriate tests to cover the desired behaviour * alter duplicate logs helper to return duplicates in a format that can be passed through the params update associated tests * create user journey to view duplicate sets adn navigate to a given set create a new route and add it to the link from the logs index page create controller method and related view file * update path for duplicate logs in routes, update factories, refactor duplicates scope to eliminate raw sql * write tests for the duplicate logs index page * correct linting errors * minor amendments from code review. * temp * Refactor * Create a scope for duplicate groups * fixes * lint * Update controller specs * Put duplicate sets count behind a feature flag * refactor index * Update duplicate_sets_count * Update scopes * tests * pass in original log id * tests * Add duplicate index page content --------- Co-authored-by: Kat <katrina@kosiak.co.uk>pull/1852/head
Arthur Campbell
1 year ago
committed by
GitHub
24 changed files with 828 additions and 68 deletions
@ -0,0 +1,41 @@
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<h1 class="govuk-heading-l"><%= duplicate_list_header(@duplicates[:lettings].count + @duplicates[:sales].count) %></h1> |
||||
<p class="govuk-body"> |
||||
These logs are duplicates because they have the same answers for certain fields. |
||||
</p> |
||||
<p class="govuk-body"> |
||||
Review each set of logs and either delete any duplicates or change any incorrect answers. |
||||
</p> |
||||
</div> |
||||
</div> |
||||
|
||||
<%= govuk_table do |table| %> |
||||
<%= table.head do |head| %> |
||||
<%= head.row do |row| %> |
||||
<% row.cell header: true, text: "Type of logs" %> |
||||
<% row.cell header: true, text: "Log IDs" %> |
||||
<% row.cell header: true %> |
||||
<% end %> |
||||
<% end %> |
||||
<%= table.body do |body| %> |
||||
<% @duplicates[:lettings].each do |duplicate_set| %> |
||||
<% body.row do |row| %> |
||||
<% 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) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% @duplicates[:sales].each do |duplicate_set| %> |
||||
<% body.row do |row| %> |
||||
<% 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) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
@ -0,0 +1,136 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe DuplicateLogsHelper do |
||||
describe "#duplicates_for_user" do |
||||
let(:org) { create(:organisation) } |
||||
let(:other_org) { create(:organisation) } |
||||
let(:current_user) { create(:user, organisation: org) } |
||||
let(:user_same_org) { create(:user, organisation: org) } |
||||
let(:user_other_org) { create(:user, organisation: other_org) } |
||||
|
||||
let!(:lettings_log) { create(:lettings_log, :duplicate, created_by: current_user) } |
||||
let!(:sales_log) { create(:sales_log, :duplicate, created_by: current_user) } |
||||
let(:result) { duplicates_for_user(current_user) } |
||||
|
||||
context "when there are no duplicates" do |
||||
it "returns empty duplicates" do |
||||
expect(result).to eq({ lettings: [], sales: [] }) |
||||
end |
||||
end |
||||
|
||||
context "when there are duplicates in another org" do |
||||
before do |
||||
create(:lettings_log, :duplicate, created_by: user_other_org) |
||||
create(:sales_log, :duplicate, created_by: user_other_org) |
||||
end |
||||
|
||||
it "does not locate duplicates" do |
||||
expect(result).to eq({ lettings: [], sales: [] }) |
||||
end |
||||
end |
||||
|
||||
context "when another user in the same org has created a duplicate lettings log" do |
||||
let!(:duplicate_lettings_log) { create(:lettings_log, :duplicate, created_by: user_same_org) } |
||||
|
||||
it "returns the ids of the duplicates in a hash under the lettings key" do |
||||
expect(result).to be_a Hash |
||||
expect(result[:lettings]).to match_array [[lettings_log.id, duplicate_lettings_log.id]] |
||||
end |
||||
end |
||||
|
||||
context "when another user in the same org has created a duplicate sales log" do |
||||
let!(:duplicate_sales_log) { create(:sales_log, :duplicate, created_by: user_same_org) } |
||||
|
||||
it "returns the ids of the duplicates in a hash under the sales key" do |
||||
expect(result).to be_a Hash |
||||
expect(result[:sales]).to match_array [[sales_log.id, duplicate_sales_log.id]] |
||||
end |
||||
end |
||||
|
||||
context "when there is a set of duplicate lettings logs not associated with the user" do |
||||
before do |
||||
create_list(:lettings_log, 3, :duplicate, tenancycode: "other", owning_organisation: org) |
||||
end |
||||
|
||||
it "returns the ids of the duplicates in a hash under the lettings key" do |
||||
expect(result).to be_a Hash |
||||
expect(result[:lettings]).to be_empty |
||||
end |
||||
end |
||||
|
||||
context "when there is a set of duplicate sales logs not associated with the user" do |
||||
before do |
||||
create_list(:sales_log, 3, :duplicate, purchid: "other", owning_organisation: org) |
||||
end |
||||
|
||||
it "returns the ids of the duplicates in a hash under the sales key" do |
||||
expect(result).to be_a Hash |
||||
expect(result[:sales]).to be_empty |
||||
end |
||||
end |
||||
|
||||
context "when there are multiple sets of duplicates across lettings and sales" do |
||||
let!(:duplicate_lettings_log) { create(:lettings_log, :duplicate, created_by: user_same_org) } |
||||
let!(:duplicate_sales_log) { create(:sales_log, :duplicate, created_by: user_same_org) } |
||||
let!(:further_sales_log) { create(:sales_log, :duplicate, purchid: "further", created_by: current_user) } |
||||
let!(:further_duplicate_sales_logs) { create_list(:sales_log, 2, :duplicate, purchid: "further", created_by: user_same_org) } |
||||
|
||||
it "returns them all with no repeats" do |
||||
expected_sales_duplicates_result = [ |
||||
[sales_log.id, duplicate_sales_log.id], |
||||
[further_sales_log.id, *further_duplicate_sales_logs.map(&:id)], |
||||
] |
||||
|
||||
expect(result[:lettings]).to match_array [[lettings_log.id, duplicate_lettings_log.id]] |
||||
expect(result[:sales]).to match_array expected_sales_duplicates_result |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "#duplicates_for_organisation" do |
||||
let(:organisation) { create(:organisation) } |
||||
let(:sales_logs) { SalesLog.filter_by_organisation(organisation) } |
||||
|
||||
context "when there are no duplicates" do |
||||
it "returns empty duplicates" do |
||||
expect(duplicates_for_organisation(organisation)).to eq({ lettings: [], sales: [] }) |
||||
end |
||||
end |
||||
|
||||
context "when there are multiple sets of sales duplicates" do |
||||
let!(:duplicate_sales_logs) { create_list(:sales_log, 4, :duplicate, purchid: "set 1", owning_organisation: organisation) } |
||||
let!(:duplicate_sales_logs_too) { create_list(:sales_log, 5, :duplicate, postcode_full: "B1 1BB", owning_organisation: organisation) } |
||||
let!(:duplicate_sales_logs_3) { create_list(:sales_log, 3, :duplicate, age1: 38, owning_organisation: organisation) } |
||||
|
||||
let!(:duplicate_lettings_logs) { create_list(:lettings_log, 4, :duplicate, tenancycode: "set 1", owning_organisation: organisation) } |
||||
let!(:duplicate_lettings_logs_too) { create_list(:lettings_log, 5, :duplicate, postcode_full: "B1 1BB", owning_organisation: organisation) } |
||||
let!(:duplicate_lettings_logs_3) { create_list(:lettings_log, 3, :duplicate, age1: 38, owning_organisation: organisation) } |
||||
|
||||
before do |
||||
create_list(:sales_log, 3, :duplicate, discarded_at: Time.zone.now, status: 4, owning_organisation: organisation) |
||||
create_list(:lettings_log, 3, :duplicate, discarded_at: Time.zone.now, status: 4, owning_organisation: organisation) |
||||
end |
||||
|
||||
it "returns them all with no repeats" do |
||||
expected_sales_duplicates_result = [ |
||||
duplicate_sales_logs.map(&:id), |
||||
duplicate_sales_logs_too.map(&:id), |
||||
duplicate_sales_logs_3.map(&:id), |
||||
] |
||||
|
||||
expected_lettings_duplicates_result = [ |
||||
duplicate_lettings_logs.map(&:id), |
||||
duplicate_lettings_logs_too.map(&:id), |
||||
duplicate_lettings_logs_3.map(&:id), |
||||
] |
||||
|
||||
expect(duplicates_for_organisation(organisation)[:lettings]).to match_array( |
||||
expected_lettings_duplicates_result.map { |nested_array| match_array(nested_array) }, |
||||
) |
||||
expect(duplicates_for_organisation(organisation)[:sales]).to match_array( |
||||
expected_sales_duplicates_result.map { |nested_array| match_array(nested_array) }, |
||||
) |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue