From fd85f2a19e8388fab7729695591ec016d0f115d6 Mon Sep 17 00:00:00 2001 From: Jack S <113976590+bibblobcode@users.noreply.github.com> Date: Mon, 17 Oct 2022 10:01:22 +0100 Subject: [PATCH 01/12] [CLDC-1512] Add buyer1 income (#940) * Add tests for household wheelchair * [CLDC-1512] Add buyer 1 income * Add guidance to question --- app/models/form/sales/pages/buyer1_income.rb | 16 ++++++ .../form/sales/questions/buyer1_income.rb | 14 +++++ .../sales/questions/buyer1_income_known.rb | 21 +++++++ app/models/form/sales/sections/finances.rb | 12 ++++ .../income_benefits_and_outgoings.rb | 15 +++++ app/models/form_handler.rb | 1 + .../_what_counts_as_income_sales.html.erb | 17 ++++++ ...20221007142742_add_income1_to_sales_log.rb | 6 ++ db/schema.rb | 3 + spec/factories/sales_log.rb | 2 + .../form/sales/pages/buyer1_income_spec.rb | 33 +++++++++++ .../sales/pages/household_wheelchair_spec.rb | 33 +++++++++++ .../questions/buyer1_income_known_spec.rb | 55 +++++++++++++++++++ .../sales/questions/buyer1_income_spec.rb | 53 ++++++++++++++++++ .../questions/household_wheelchair_spec.rb | 49 +++++++++++++++++ .../form/sales/sections/finances_spec.rb | 33 +++++++++++ .../income_benefits_and_outgoings_spec.rb | 33 +++++++++++ spec/models/form_handler_spec.rb | 4 +- 18 files changed, 398 insertions(+), 2 deletions(-) create mode 100644 app/models/form/sales/pages/buyer1_income.rb create mode 100644 app/models/form/sales/questions/buyer1_income.rb create mode 100644 app/models/form/sales/questions/buyer1_income_known.rb create mode 100644 app/models/form/sales/sections/finances.rb create mode 100644 app/models/form/sales/subsections/income_benefits_and_outgoings.rb create mode 100644 app/views/form/guidance/_what_counts_as_income_sales.html.erb create mode 100644 db/migrate/20221007142742_add_income1_to_sales_log.rb create mode 100644 spec/models/form/sales/pages/buyer1_income_spec.rb create mode 100644 spec/models/form/sales/pages/household_wheelchair_spec.rb create mode 100644 spec/models/form/sales/questions/buyer1_income_known_spec.rb create mode 100644 spec/models/form/sales/questions/buyer1_income_spec.rb create mode 100644 spec/models/form/sales/questions/household_wheelchair_spec.rb create mode 100644 spec/models/form/sales/sections/finances_spec.rb create mode 100644 spec/models/form/sales/subsections/income_benefits_and_outgoings_spec.rb diff --git a/app/models/form/sales/pages/buyer1_income.rb b/app/models/form/sales/pages/buyer1_income.rb new file mode 100644 index 000000000..e4f88be81 --- /dev/null +++ b/app/models/form/sales/pages/buyer1_income.rb @@ -0,0 +1,16 @@ +class Form::Sales::Pages::Buyer1Income < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "buyer_1_income" + @header = "" + @description = "" + @subsection = subsection + end + + def questions + @questions ||= [ + Form::Sales::Questions::Buyer1IncomeKnown.new(nil, nil, self), + Form::Sales::Questions::Buyer1Income.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/buyer1_income.rb b/app/models/form/sales/questions/buyer1_income.rb new file mode 100644 index 000000000..f4e586b39 --- /dev/null +++ b/app/models/form/sales/questions/buyer1_income.rb @@ -0,0 +1,14 @@ +class Form::Sales::Questions::Buyer1Income < ::Form::Question + def initialize(id, hsh, page) + super + @id = "income1" + @check_answer_label = "Buyer 1’s gross annual income" + @header = "Buyer 1’s gross annual income" + @type = "numeric" + @page = page + @min = 0 + @step = 1 + @width = 5 + @prefix = "£" + end +end diff --git a/app/models/form/sales/questions/buyer1_income_known.rb b/app/models/form/sales/questions/buyer1_income_known.rb new file mode 100644 index 000000000..923045ef9 --- /dev/null +++ b/app/models/form/sales/questions/buyer1_income_known.rb @@ -0,0 +1,21 @@ +class Form::Sales::Questions::Buyer1IncomeKnown < ::Form::Question + def initialize(id, hsh, page) + super + @id = "income1nk" + @check_answer_label = "Buyer 1’s gross annual income" + @header = "Do you know buyer 1’s annual income?" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @page = page + @guidance_position = GuidancePosition::BOTTOM + @guidance_partial = "what_counts_as_income_sales" + @conditional_for = { + "income1" => [0], + } + end + + ANSWER_OPTIONS = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }.freeze +end diff --git a/app/models/form/sales/sections/finances.rb b/app/models/form/sales/sections/finances.rb new file mode 100644 index 000000000..c2c4082fd --- /dev/null +++ b/app/models/form/sales/sections/finances.rb @@ -0,0 +1,12 @@ +class Form::Sales::Sections::Finances < ::Form::Section + def initialize(id, hsh, form) + super + @id = "finances" + @label = "Finances" + @description = "" + @form = form + @subsections = [ + Form::Sales::Subsections::IncomeBenefitsAndOutgoings.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/subsections/income_benefits_and_outgoings.rb b/app/models/form/sales/subsections/income_benefits_and_outgoings.rb new file mode 100644 index 000000000..2c9d779b4 --- /dev/null +++ b/app/models/form/sales/subsections/income_benefits_and_outgoings.rb @@ -0,0 +1,15 @@ +class Form::Sales::Subsections::IncomeBenefitsAndOutgoings < ::Form::Subsection + def initialize(id, hsh, section) + super + @id = "income_benefits_and_outgoings" + @label = "Income, benefits and outgoings" + @section = section + @depends_on = [{ "setup" => "completed" }] + end + + def pages + @pages ||= [ + Form::Sales::Pages::Buyer1Income.new(nil, nil, self), + ] + end +end diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index c9d45e876..c6dde13ab 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -22,6 +22,7 @@ class FormHandler sales_sections = [ Form::Sales::Sections::PropertyInformation, Form::Sales::Sections::Household, + Form::Sales::Sections::Finances, ] current_form = Form.new(nil, current_collection_start_year, sales_sections, "sales") previous_form = Form.new(nil, current_collection_start_year - 1, sales_sections, "sales") diff --git a/app/views/form/guidance/_what_counts_as_income_sales.html.erb b/app/views/form/guidance/_what_counts_as_income_sales.html.erb new file mode 100644 index 000000000..c5e2c7116 --- /dev/null +++ b/app/views/form/guidance/_what_counts_as_income_sales.html.erb @@ -0,0 +1,17 @@ +<%= govuk_details(summary_text: "What counts as income?") do %> +
You should include any income from:
+Don’t include:
+This organisation can submit logs for its housing providers.
+<% else %> + <%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: nil } %> +Your organisation can submit logs for its housing providers.
+<% end %> + +<% if @total_count == 0 %> +This organisation does not currently have any housing providers.
+<% end %> +<% if current_user.data_coordinator? || current_user.support? %> + <%= govuk_button_link_to "Add a housing provider", housing_providers_organisation_path(organisation_id: @organisation.id), html: { method: :get } %> +<% end %> +<% if @total_count != 0 %> + <%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> + <%= render partial: "organisation_relationships/housing_provider_list", locals: { index: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> + <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %> +<% end %> diff --git a/app/views/organisations/index.html.erb b/app/views/organisations/index.html.erb index b81922c5e..75a4d799c 100644 --- a/app/views/organisations/index.html.erb +++ b/app/views/organisations/index.html.erb @@ -1,4 +1,4 @@ -<% item_label = format_label(@pagy.count, "organisation") %> +<% item_label = format_label(@pagy.count, "organisations") %> <% title = format_title(@searched, "Organisations", current_user, item_label, @pagy.count, nil) %> <% content_for :title, title %> diff --git a/app/views/organisations/logs.html.erb b/app/views/organisations/logs.html.erb index f954a0839..94fe8e9bc 100644 --- a/app/views/organisations/logs.html.erb +++ b/app/views/organisations/logs.html.erb @@ -1,4 +1,4 @@ -<% item_label = format_label(@pagy.count, "log") %> +<% item_label = format_label(@pagy.count, "logs") %> <% title = format_title(@searched, "Logs", current_user, item_label, @pagy.count, @organisation.name) %> <% content_for :title, title %> diff --git a/config/routes.rb b/config/routes.rb index 0be5f5b6a..e703b853d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -79,6 +79,7 @@ Rails.application.routes.draw do post "logs/email-csv", to: "organisations#email_csv" get "logs/csv-confirmation", to: "lettings_logs#csv_confirmation" get "schemes", to: "organisations#schemes" + get "housing-providers", to: "organisation_relationships#housing_providers" end end diff --git a/db/migrate/20221019082625_rename_managing_agents_column.rb b/db/migrate/20221019082625_rename_managing_agents_column.rb new file mode 100644 index 000000000..dd03a7435 --- /dev/null +++ b/db/migrate/20221019082625_rename_managing_agents_column.rb @@ -0,0 +1,5 @@ +class RenameManagingAgentsColumn < ActiveRecord::Migration[7.0] + def change + rename_column :organisations, :managing_agents, :managing_agents_label + end +end diff --git a/db/schema.rb b/db/schema.rb index 59a0dbd24..80f37a6b0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_10_17_095918) do +ActiveRecord::Schema[7.0].define(version: 2022_10_19_082625) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -297,7 +297,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_17_095918) do t.string "postcode" t.boolean "holds_own_stock" t.string "other_stock_owners" - t.string "managing_agents" + t.string "managing_agents_label" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "active" diff --git a/db/seeds.rb b/db/seeds.rb index 8491db6b6..2ad174195 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,6 +8,17 @@ # rubocop:disable Rails/Output unless Rails.env.test? + housing_provider = Organisation.find_or_create_by!( + name: "Housing Provider", + address_line1: "2 Marsham Street", + address_line2: "London", + postcode: "SW1P 4DF", + holds_own_stock: true, + other_stock_owners: "None", + managing_agents_label: "None", + provider_type: "LA", + ) + org = Organisation.find_or_create_by!( name: "DLUHC", address_line1: "2 Marsham Street", @@ -15,7 +26,7 @@ unless Rails.env.test? postcode: "SW1P 4DF", holds_own_stock: false, other_stock_owners: "None", - managing_agents: "None", + managing_agents_label: "None", provider_type: "LA", ) do info = "Seeded DLUHC Organisation" @@ -26,6 +37,12 @@ unless Rails.env.test? end end + OrganisationRelationship.create!( + child_organisation: org, + parent_organisation: housing_provider, + relationship_type: OrganisationRelationship::OWNING, + ) + if Rails.env.development? && User.count.zero? User.create!( name: "Provider", @@ -65,7 +82,7 @@ unless Rails.env.test? postcode: "BA21 4AT", holds_own_stock: false, other_stock_owners: "None", - managing_agents: "None", + managing_agents_label: "None", provider_type: "LA", ) diff --git a/spec/factories/organisation.rb b/spec/factories/organisation.rb index 8b02f030a..fa40663ac 100644 --- a/spec/factories/organisation.rb +++ b/spec/factories/organisation.rb @@ -17,9 +17,4 @@ FactoryBot.define do created_at { Time.zone.now } updated_at { Time.zone.now } end - - factory :organisation_relationship do - child_organisation { FactoryBot.create(:organisation) } - parent_organisation { FactoryBot.create(:organisation) } - end end diff --git a/spec/factories/organisation_relationship.rb b/spec/factories/organisation_relationship.rb new file mode 100644 index 000000000..418599902 --- /dev/null +++ b/spec/factories/organisation_relationship.rb @@ -0,0 +1,14 @@ +FactoryBot.define do + factory :organisation_relationship do + child_organisation { FactoryBot.create(:organisation) } + parent_organisation { FactoryBot.create(:organisation) } + + trait :owning do + relationship_type { OrganisationRelationship::OWNING } + end + + trait :managing do + relationship_type { OrganisationRelationship::MANAGING } + end + end +end diff --git a/spec/helpers/navigation_items_helper_spec.rb b/spec/helpers/navigation_items_helper_spec.rb index fc656d024..05599c3cf 100644 --- a/spec/helpers/navigation_items_helper_spec.rb +++ b/spec/helpers/navigation_items_helper_spec.rb @@ -20,6 +20,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", users_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -35,6 +36,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", users_path, true), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -50,6 +52,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", users_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, true), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -65,6 +68,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -80,6 +84,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -95,6 +100,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -246,6 +252,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -272,6 +279,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -298,6 +306,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", true), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -324,6 +333,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", true), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -346,6 +356,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", users_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -362,6 +373,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", users_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -378,6 +390,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", users_path, true), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -394,6 +407,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", users_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, true), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -410,6 +424,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -426,6 +441,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -442,6 +458,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -618,6 +635,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -646,6 +664,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -674,6 +693,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", true), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end @@ -702,6 +722,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", true), + NavigationItemsHelper::NavigationItem.new("Housing providers", "/organisations/#{current_user.organisation.id}/housing-providers", false), ] end diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index b6011cf20..ec83e7469 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -27,35 +27,67 @@ RSpec.describe Organisation, type: :model do .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type #{I18n.t('validations.organisation.provider_type_missing')}") end - context "with managing association" do - let(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } + context "with parent/child associations", :aggregate_failures do + let!(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } + let!(:grandchild_organisation) { FactoryBot.create(:organisation, name: "DLUHC Grandchild") } before do - FactoryBot.create(:organisation_relationship, child_organisation:, parent_organisation: organisation, relationship_type: 0) + FactoryBot.create( + :organisation_relationship, + :owning, + child_organisation:, + parent_organisation: organisation, + ) + + FactoryBot.create( + :organisation_relationship, + :owning, + child_organisation: grandchild_organisation, + parent_organisation: child_organisation, + ) end - it "has correct child" do - expect(organisation.child_organisations.first).to eq(child_organisation) + it "has correct child_organisations" do + expect(organisation.child_organisations).to eq([child_organisation]) + expect(child_organisation.child_organisations).to eq([grandchild_organisation]) end - it "has correct parent" do - expect(child_organisation.parent_organisations.first).to eq(organisation) + it "has correct parent_organisations" do + expect(child_organisation.parent_organisations).to eq([organisation]) + expect(grandchild_organisation.parent_organisations).to eq([child_organisation]) end end - context "with owning association" do - let(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } + context "with owning association", :aggregate_failures do + let!(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } + let!(:grandchild_organisation) { FactoryBot.create(:organisation, name: "DLUHC Grandchild") } before do - FactoryBot.create(:organisation_relationship, child_organisation:, parent_organisation: organisation, relationship_type: 1) - end + FactoryBot.create( + :organisation_relationship, + :managing, + child_organisation:, + parent_organisation: organisation, + ) + + FactoryBot.create( + :organisation_relationship, + :owning, + child_organisation:, + parent_organisation: organisation, + ) - it "has correct child" do - expect(organisation.child_organisations.first).to eq(child_organisation) + FactoryBot.create( + :organisation_relationship, + :owning, + child_organisation: grandchild_organisation, + parent_organisation: child_organisation, + ) end - it "has correct parent" do - expect(child_organisation.parent_organisations.first).to eq(organisation) + it "has correct housing_providers" do + expect(child_organisation.housing_providers).to eq([organisation]) + expect(grandchild_organisation.housing_providers).to eq([child_organisation]) end end diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index 651655139..db4226152 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -365,7 +365,7 @@ RSpec.describe LettingsLogsController, type: :request do it "has search results in the title" do get "/lettings-logs?search=#{log_to_search.id}", headers: headers, params: {} - expect(page).to have_title("Logs (1 log matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") + expect(page).to have_title("Logs (1 logs matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") end it "shows lettings logs matching the id" do diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 6bc335921..25a1eb256 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -284,6 +284,54 @@ RSpec.describe OrganisationsController, type: :request do end end + context "when accessing the housing providers tab" do + context "with an organisation that the user belongs to" do + let!(:housing_provider) { FactoryBot.create(:organisation) } + let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } + let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") } + + before do + FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) + FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) + get "/organisations/#{organisation.id}/housing-providers", headers:, params: {} + end + + it "shows the tab navigation" do + expected_html = "