Browse Source
* 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 <katrina@kosiak.co.uk>pull/1767/head
Aaron Spencer
1 year ago
committed by
GitHub
19 changed files with 389 additions and 30 deletions
@ -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 |
@ -0,0 +1,26 @@ |
|||||||
|
<div class="govuk-grid-row govuk-!-padding-top-4"> |
||||||
|
<div class="govuk-grid-column-two-thirds"> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-one-third"> |
||||||
|
<header class="app-log-summary__header"> |
||||||
|
<h2 class="app-log-summary__title"> |
||||||
|
<%= govuk_link_to "Log #{log.id}", send("#{log.class.name.underscore}_path", log) %> |
||||||
|
</h2> |
||||||
|
</header> |
||||||
|
</div> |
||||||
|
<div class="govuk-grid-column-two-thirds"> |
||||||
|
<p class="govuk-body"> |
||||||
|
Created <time datetime="<%= log.created_at.iso8601 %>"><%= log.created_at.to_formatted_s(:govuk_date) %></time> |
||||||
|
<% if log.created_by %> |
||||||
|
<span class="app-log-summary__footer--actor">Assigned to <%= log.created_by.name || log.created_by.email %></span> |
||||||
|
<% end %> |
||||||
|
</p> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div class="govuk-grid-column-one-third app-log-summary__footer"> |
||||||
|
<p class="govuk-body govuk-!-margin-bottom-2"> |
||||||
|
<%= status_tag(log.status) %> |
||||||
|
</p> |
||||||
|
</div> |
||||||
|
</div> |
@ -0,0 +1,39 @@ |
|||||||
|
<div class="x-govuk-summary-card govuk-!-margin-bottom-6"> |
||||||
|
<div class="x-govuk-summary-card__body"> |
||||||
|
<%= 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| %> |
||||||
|
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span> |
||||||
|
<% 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 %> |
||||||
|
</div> |
||||||
|
</div> |
@ -0,0 +1,20 @@ |
|||||||
|
<% content_for :title, "Check duplicate logs" %> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds"> |
||||||
|
<%= govuk_panel( |
||||||
|
classes: "app-panel--interruption", |
||||||
|
) do %> |
||||||
|
<p class="govuk-heading-l">These logs are duplicates</p> |
||||||
|
<p class="govuk-body-l">These logs have the same values for the following fields. Choose one to keep or correct the answers.</p> |
||||||
|
<% 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 %> |
||||||
|
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--m"> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
@ -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 |
Loading…
Reference in new issue