From e497e7fb71bdd96519738004e623dfa99a4f7356 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 9 Nov 2023 09:41:29 +0000 Subject: [PATCH] feat: add and update tests --- .../requests/lettings_logs_controller_spec.rb | 35 ++++++++- spec/requests/sales_logs_controller_spec.rb | 75 +++++++++++++++++++ 2 files changed, 106 insertions(+), 4 deletions(-) diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index ea9debdc1..6844ad6b4 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -889,14 +889,12 @@ RSpec.describe LettingsLogsController, type: :request do end context "and there are duplicate logs for this user" do - before do - FactoryBot.create_list(:lettings_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) - end + let!(:duplicate_logs) { FactoryBot.create_list(:lettings_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) } it "displays a notification banner with a link to review logs" do get lettings_logs_path expect(page).to have_content "duplicate logs" - expect(page).to have_link "Review logs" # add an href when routing done + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" end context "when there is one set of duplicates" do @@ -904,6 +902,20 @@ RSpec.describe LettingsLogsController, type: :request do get lettings_logs_path expect(page).to have_content "There is 1 set of duplicate logs" end + + context "when the set is not editable" do + before do + duplicate_logs.each do |log| + log.startdate = Time.zone.now - 3.years + log.save!(validate: false) + end + end + + it "does not display the banner" do + get lettings_logs_path + expect(page).not_to have_content "duplicate logs" + end + end end context "when there are multiple sets of duplicates" do @@ -914,6 +926,21 @@ RSpec.describe LettingsLogsController, type: :request do it "displays the correct copy in the banner" do get lettings_logs_path expect(page).to have_content "There are 2 sets of duplicate logs" + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" + end + + context "when one set is not editable" do + before do + log = duplicate_logs.first + log.startdate = Time.zone.now - 3.years + log.save!(validate: false) + end + + it "displays the correct copy in the banner" do + get lettings_logs_path + expect(page).to have_content "There is 1 set of duplicate logs" + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" + end end end end diff --git a/spec/requests/sales_logs_controller_spec.rb b/spec/requests/sales_logs_controller_spec.rb index 97c5851fd..2b7f6e172 100644 --- a/spec/requests/sales_logs_controller_spec.rb +++ b/spec/requests/sales_logs_controller_spec.rb @@ -235,6 +235,18 @@ RSpec.describe SalesLogsController, type: :request do expect(page).to have_link("Download (CSV, codes only)", href: "/sales-logs/csv-download?codes_only=true") end + context "when there are duplicate logs for this user" do + before do + FactoryBot.create_list(:sales_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) + end + + it "does not show a notification banner even if there are duplicate logs for this user" do + get sales_logs_path + expect(page).not_to have_content "duplicate logs" + expect(page).not_to have_link "Review logs" + end + end + context "when there are no logs in the database" do before do SalesLog.destroy_all @@ -566,6 +578,12 @@ RSpec.describe SalesLogsController, type: :request do expect(page).not_to have_link("Download (CSV, codes only)") end + it "does not show a notification banner even if there are duplicate logs for this user" do + get sales_logs_path + expect(page).not_to have_content "duplicate logs" + expect(page).not_to have_link "Review logs" + end + context "when using a search query" do let(:logs) { FactoryBot.create_list(:sales_log, 3, :completed, owning_organisation: user.organisation, created_by: user) } let(:log_to_search) { FactoryBot.create(:sales_log, :completed, owning_organisation: user.organisation, created_by: user) } @@ -727,6 +745,63 @@ RSpec.describe SalesLogsController, type: :request do end end end + + context "and there are duplicate logs for this user" do + let!(:duplicate_logs) { FactoryBot.create_list(:lettings_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) } + + it "displays a notification banner with a link to review logs" do + get sales_logs_path + expect(page).to have_content "duplicate logs" + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" + end + + context "when there is one set of duplicates" do + it "displays the correct copy in the banner" do + get sales_logs_path + expect(page).to have_content "There is 1 set of duplicate logs" + end + + context "when the set is not editable" do + before do + duplicate_logs.each do |log| + log.startdate = Time.zone.now - 3.years + log.save!(validate: false) + end + end + + it "does not display the banner" do + get sales_logs_path + expect(page).not_to have_content "duplicate logs" + end + end + end + + context "when there are multiple sets of duplicates" do + before do + FactoryBot.create_list(:sales_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) + end + + it "displays the correct copy in the banner" do + get sales_logs_path + expect(page).to have_content "There are 2 sets of duplicate logs" + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" + end + + context "when one set is not editable" do + before do + log = duplicate_logs.first + log.startdate = Time.zone.now - 3.years + log.save!(validate: false) + end + + it "displays the correct copy in the banner" do + get sales_logs_path + expect(page).to have_content "There is 1 set of duplicate logs" + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" + end + end + end + end end end