Browse Source

test: refactor managing orgs opts tests for support user case

fix-remove-attr-accessors-from-questions-in-cldc-1723
Sam Seed 2 years ago
parent
commit
bb04ed0d9a
  1. 68
      spec/models/form/lettings/questions/managing_organisation_spec.rb

68
spec/models/form/lettings/questions/managing_organisation_spec.rb

@ -74,46 +74,44 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end end
end end
context "when user is support and org does own stock" do context "when user is support" do
let(:user) { create(:user, :support) } let(:user) { create(:user, :support) }
let(:log_owning_org) { create(:organisation, name: "Owning org", holds_own_stock: true) } let(:log_owning_org) { create(:organisation, name: "Owning org") }
let(:log) { create(:lettings_log, owning_organisation: log_owning_org, managing_organisation: create(:organisation, name: "Managing org 1"), created_by: nil) } let(:log) { create(:lettings_log, owning_organisation: log_owning_org, managing_organisation: create(:organisation, name: "Managing org 1"), created_by: nil) }
let!(:org_rel1) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: create(:organisation, name: "Managing org 2")) } let!(:org_rel1) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: create(:organisation, name: "Managing org 2")) }
let!(:org_rel2) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: create(:organisation, name: "Managing org 3")) } let!(:org_rel2) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: create(:organisation, name: "Managing org 3")) }
let(:options) do context "when org owns stock" do
{ let(:options) do
"" => "Select an option", {
log.managing_organisation.id => "Managing org 1", "" => "Select an option",
log_owning_org.id => "Owning org (Owning organisation)", log.managing_organisation.id => "Managing org 1",
org_rel1.child_organisation.id => "Managing org 2", log_owning_org.id => "Owning org (Owning organisation)",
org_rel2.child_organisation.id => "Managing org 3", org_rel1.child_organisation.id => "Managing org 2",
} org_rel2.child_organisation.id => "Managing org 3",
end }
end
it "shows current managing agent at top, followed by the current owning organisation (with hint), followed by the managing agents of the current owning organisation" do
expect(question.displayed_answer_options(log, user)).to eq(options) it "shows current managing agent at top, followed by the current owning organisation (with hint), followed by the managing agents of the current owning organisation" do
end log_owning_org.update(holds_own_stock: true)
end expect(question.displayed_answer_options(log, user)).to eq(options)
end
context "when user is support and org does not own stock" do end
let(:user) { create(:user, :support) }
let(:log_owning_org) { create(:organisation, name: "Owning org", holds_own_stock: false) } context "when org does not own stock" do
let(:log) { create(:lettings_log, owning_organisation: log_owning_org, managing_organisation: create(:organisation, name: "Managing org 1"), created_by: nil) } let(:options) do
let!(:org_rel1) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: create(:organisation, name: "Managing org 2")) } {
let!(:org_rel2) { create(:organisation_relationship, parent_organisation: log_owning_org, child_organisation: create(:organisation, name: "Managing org 3")) } "" => "Select an option",
log.managing_organisation.id => "Managing org 1",
let(:options) do org_rel1.child_organisation.id => "Managing org 2",
{ org_rel2.child_organisation.id => "Managing org 3",
"" => "Select an option", }
log.managing_organisation.id => "Managing org 1", end
org_rel1.child_organisation.id => "Managing org 2",
org_rel2.child_organisation.id => "Managing org 3", it "shows current managing agent at top, followed by the managing agents of the current owning organisation" do
} log_owning_org.update(holds_own_stock: false)
end expect(question.displayed_answer_options(log, user)).to eq(options)
end
it "shows current managing agent at top, followed by the managing agents of the current owning organisation" do
expect(question.displayed_answer_options(log, user)).to eq(options)
end end
end end

Loading…
Cancel
Save