Browse Source

feat: add duplicate logs controller tests

pull/1983/head
natdeanlewissoftwire 3 years ago
parent
commit
f7d9cd6a5f
  1. 241
      spec/requests/duplicate_logs_controller_spec.rb

241
spec/requests/duplicate_logs_controller_spec.rb

@ -29,6 +29,203 @@ RSpec.describe DuplicateLogsController, type: :request do
end
context "when user is signed in" do
context "when user is support" do
let(:support_user_org) { create(:organisation) }
let(:user) { create(:user, :support, organisation: support_user_org) }
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}&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
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 return 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 buttons 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
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
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 return 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 user is a data provider" do
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
@ -163,6 +360,7 @@ RSpec.describe DuplicateLogsController, type: :request do
end
end
end
end
describe "GET sales delete-duplicates" do
let(:headers) { { "Accept" => "text/html" } }
@ -323,9 +521,44 @@ RSpec.describe DuplicateLogsController, type: :request do
context "when the user is support" do
let(:user) { create(:user, :support) }
it "returns 200 status" do
get duplicate_logs_path(organisation_id: user.organisation.id)
expect(response).to have_http_status(:ok)
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
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
end
@ -379,7 +612,7 @@ RSpec.describe DuplicateLogsController, type: :request do
expect(page).to have_content("Log 11, Log 12")
end
it "shows links for each set of duplciates" do
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))

Loading…
Cancel
Save