diff --git a/spec/components/lettings_log_summary_component_spec.rb b/spec/components/lettings_log_summary_component_spec.rb index 31533ab29..50885af3c 100644 --- a/spec/components/lettings_log_summary_component_spec.rb +++ b/spec/components/lettings_log_summary_component_spec.rb @@ -6,10 +6,9 @@ RSpec.describe LettingsLogSummaryComponent, type: :component do let(:propcode) { "P3647" } let(:tenancycode) { "T62863" } let(:lettings_log) { FactoryBot.create(:lettings_log, needstype: 1, tenancycode:, propcode:, startdate: Time.zone.today) } - let(:sales_log) { FactoryBot.create(:sales_log) } context "when rendering lettings log for a support user" do - it "show the log summary with organisational relationships" do + it "shows the log summary with organisational relationships" do result = render_inline(described_class.new(current_user: support_user, log: lettings_log)) expect(result).to have_link(lettings_log.id.to_s) @@ -25,29 +24,11 @@ RSpec.describe LettingsLogSummaryComponent, type: :component do end context "when rendering lettings log for a data coordinator user" do - it "show the log summary" do + it "does not show the user who the log is owned and managed by" do result = render_inline(described_class.new(current_user: coordinator_user, log: lettings_log)) expect(result).not_to have_content("Owned by") expect(result).not_to have_content("Managed by") end end - - context "when rendering sales log for a support user" do - it "show the log summary with organisational relationships" do - result = render_inline(described_class.new(current_user: support_user, log: sales_log)) - - expect(result).to have_content("Owned by\n DLUHC") - expect(result).not_to have_content("Managed by") - end - end - - context "when rendering sales log for a data coordinator user" do - it "show the log summary" do - result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log)) - - expect(result).not_to have_content("Owned by") - expect(result).not_to have_content("Managed by") - end - end end diff --git a/spec/components/sales_log_summary_component_spec.rb b/spec/components/sales_log_summary_component_spec.rb new file mode 100644 index 000000000..68f55184b --- /dev/null +++ b/spec/components/sales_log_summary_component_spec.rb @@ -0,0 +1,99 @@ +require "rails_helper" + +RSpec.describe SalesLogSummaryComponent, type: :component do + let(:support_user) { FactoryBot.create(:user, :support) } + let(:coordinator_user) { FactoryBot.create(:user) } + let(:purchid) { "62863" } + let(:ownershipsch) { "0" } + let(:saledate) { Time.zone.today } + let(:sales_log) { FactoryBot.create(:sales_log, ownershipsch:, purchid:, saledate:) } + + context "when rendering sales log for a support user" do + it "shows the log summary with organisational relationships" do + result = render_inline(described_class.new(current_user: support_user, log: sales_log)) + + expect(result).to have_content("Owned by\n DLUHC") + expect(result).not_to have_content("Managed by") + end + end + + context "when rendering sales log for a data coordinator user" do + it "does not show the user who the log is owned and managed by" do + result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log)) + + expect(result).not_to have_content("Owned by") + expect(result).not_to have_content("Managed by") + end + end + + describe "what is shown in regards to sale completion" do + context "when a sale is completed" do + let(:saledate) { Time.zone.today } + + it "shows the sale completion date" do + result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log)) + + expect(result).to have_content("Sale completed") + end + end + + context "when a sale is completed and a purchaser id is provided" do + let(:purchid) { "62863" } + let(:saledate) { Time.zone.today } + + it "shows the purchaser id" do + result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log)) + + expect(result).to have_content(purchid) + end + end + + context "when the sale is not completed" do + let(:saledate) { nil } + + it "does not show a sale completed date" do + result = render_inline(described_class.new(current_user: coordinator_user, log: sales_log)) + + expect(result).not_to have_content("Sale completed") + end + end + end + + describe "what is shown dependant on ownership type" do + context "when the ownership scheme is shared ownership" do + let(:ownershipsch) { "1" } + + it "displayed the correct ownership type" do + result = render_inline(described_class.new(current_user: support_user, log: sales_log)) + + expect(result).to have_content("Shared ownership") + expect(result).not_to have_content("Discounted ownership") + expect(result).not_to have_content("Outright or other sale") + end + end + + context "when the ownership scheme is discounted ownership" do + let(:ownershipsch) { "2" } + + it "displayed the correct ownership type" do + result = render_inline(described_class.new(current_user: support_user, log: sales_log)) + + expect(result).not_to have_content("Shared ownership") + expect(result).to have_content("Discounted ownership") + expect(result).not_to have_content("Outright or other sale") + end + end + + context "when the ownership scheme is outright or other sale" do + let(:ownershipsch) { "3" } + + it "displayed the correct ownership type" do + result = render_inline(described_class.new(current_user: support_user, log: sales_log)) + + expect(result).not_to have_content("Shared ownership") + expect(result).not_to have_content("Discounted ownership") + expect(result).to have_content("Outright or other sale") + end + end + end +end