Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
4.7 KiB

require "rails_helper"
RSpec.describe Form::Lettings::Pages::StockOwner, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1))) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[owning_organisation_id])
end
it "has the correct id" do
expect(page.id).to eq("stock_owner")
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has the correct depends_on" do
expect(page.depends_on).to be nil
end
describe "#routed_to?" do
let(:log) { create(:lettings_log, owning_organisation_id: nil) }
context "when user nil" do
it "is not shown" do
expect(page.routed_to?(log, nil)).to eq(false)
end
it "does not update owning_organisation_id" do
expect { page.routed_to?(log, nil) }.not_to change(log.reload, :owning_organisation).from(nil)
end
end
context "when support" do
let(:user) { create(:user, :support) }
it "is shown" do
expect(page.routed_to?(log, user)).to eq(true)
end
it "does not update owning_organisation_id" do
expect { page.routed_to?(log, user) }.not_to change(log.reload, :owning_organisation).from(nil)
end
end
context "when not support" do
context "when does not hold own stock" do
let(:user) do
create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false))
end
context "with 0 stock_owners" do
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
it "does not update owning_organisation_id" do
expect { page.routed_to?(log, user) }.not_to change(log.reload, :owning_organisation)
end
end
context "with 1 stock_owners" do
let(:stock_owner) { create(:organisation) }
before do
create(
:organisation_relationship,
child_organisation: user.organisation,
parent_organisation: stock_owner,
)
end
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
it "updates owning_organisation_id" do
expect { page.routed_to?(log, user) }.to change(log.reload, :owning_organisation).from(nil).to(stock_owner)
end
end
context "with >1 stock_owners" do
let(:stock_owner1) { create(:organisation) }
let(:stock_owner2) { create(:organisation) }
before do
create(
:organisation_relationship,
child_organisation: user.organisation,
parent_organisation: stock_owner1,
)
create(
:organisation_relationship,
child_organisation: user.organisation,
parent_organisation: stock_owner2,
)
end
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(true)
end
it "updates owning_organisation_id" do
expect { page.routed_to?(log, user) }.not_to change(log.reload, :owning_organisation)
end
end
end
context "when holds own stock" do
let(:user) do
create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true))
end
context "with 0 stock_owners" do
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
it "updates owning_organisation_id to user organisation" do
CLDC-1911 Add form definition for 23/24 lettings (#1254) * Spike for generating form * Add remaining field mappings * Add question attributes conditionally * Display page attributes conditionally * update subsection formatting * Update section formatting * fix generator * Fix generator * Update the form handler and form to create post 2021 forms programatically * Initially generated and linted form * Cover lettings sections and subsections wiht tests * Cover age pages and questions with tests * Add reusable age questions and adjust the tests * Add a generic person age page using generic questions and adjust specs * Multiline arrays in subsections * Use generic person age page in household characteristics and remove unused pages/questions * Combine and reduce tests * Backfill duplicate rsnvac question * Backfill repeating question * Backfill repeating voiddate * Backfill repeating tenancy question * Backfill ethnic questions * Backfill reason question * Backfill prevten question * Backfill referral questions * Backfill chcharges questions * Backfill brent questions * Backfill scharge * Backfill pscharge * Backfill supcharg * Backfill tcharge * Backfill retirement value check question * Make person known questions generic * Make person gender identity questions generic * Make relationship questions generic * Make working situation questions generic * make retirement check generic * make pregnant household check generic * Make pregnancy value checks generic, again * Undo for and form handler changes * Remove generate form task and service * Remove empty headers, descriptions and initializers from pages * Fix tests * lint
2 years ago
expect {
page.routed_to?(log, user)
}.to change(log.reload, :owning_organisation).from(nil).to(user.organisation)
end
end
context "with >0 stock_owners" do
before do
create(:organisation_relationship, child_organisation: user.organisation)
create(:organisation_relationship, child_organisation: user.organisation)
end
it "is shown" do
expect(page.routed_to?(log, user)).to eq(true)
end
it "does not update owning_organisation_id" do
expect { page.routed_to?(log, user) }.not_to change(log.reload, :owning_organisation).from(nil)
end
end
end
end
end
end