From 610dad81a8e64afe725fa673fe27333cfde49418 Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Fri, 22 Jul 2022 08:36:49 +0100 Subject: [PATCH 01/20] CLDC-1382: Add location and search to scheme locations (#756) * Add search * Add "Add location" button * Add confirmed flag to schemes * Show location tab is location is being added to an existing scheme * Switch button text when scheme exists already * Remove change links for confirmed schemes * Fix spec after rebase * added title showing search results and tests for it Co-authored-by: JG --- app/controllers/locations_controller.rb | 16 +- app/controllers/schemes_controller.rb | 6 +- app/models/location.rb | 4 + app/views/locations/index.html.erb | 10 +- .../organisations/_organisation_list.html.erb | 4 +- app/views/schemes/check_answers.html.erb | 67 ++++--- .../20220719145718_add_confirmed_to_scheme.rb | 7 + db/schema.rb | 1 + db/seeds.rb | 3 + spec/factories/scheme.rb | 1 + spec/features/schemes_spec.rb | 174 +++++++++++++++++- spec/models/location_spec.rb | 28 +++ spec/requests/locations_controller_spec.rb | 48 +++++ 13 files changed, 334 insertions(+), 35 deletions(-) create mode 100644 db/migrate/20220719145718_add_confirmed_to_scheme.rb diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 6ac482fef..46aceb650 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -6,9 +6,12 @@ class LocationsController < ApplicationController before_action :find_scheme before_action :authenticate_action! + include Modules::SearchFilter + def index - @pagy, @locations = pagy(@scheme.locations) + @pagy, @locations = pagy(filtered_collection(@scheme.locations, search_term)) @total_count = @scheme.locations.size + @searched = search_term.presence end def new @@ -19,7 +22,12 @@ class LocationsController < ApplicationController if date_params_missing?(location_params) || valid_date_params?(location_params) @location = Location.new(location_params) if @location.save - location_params[:add_another_location] == "Yes" ? redirect_to(new_location_path(id: @scheme.id)) : redirect_to(scheme_check_answers_path(scheme_id: @scheme.id)) + if location_params[:add_another_location] == "Yes" + redirect_to new_location_path(@scheme) + else + check_answers_path = @scheme.confirmed? ? scheme_check_answers_path(@scheme, anchor: "locations") : scheme_check_answers_path(@scheme) + redirect_to check_answers_path + end else render :new, status: :unprocessable_entity end @@ -92,4 +100,8 @@ private required_params[:postcode] = PostcodeService.clean(required_params[:postcode]) if required_params[:postcode] required_params end + + def search_term + params["search"] + end end diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 44c5ab869..c3bafa318 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -47,7 +47,6 @@ class SchemesController < ApplicationController page = params[:scheme][:page] validation_errors scheme_params - if @scheme.errors.empty? && @scheme.update(scheme_params) if check_answers if confirm_secondary_page? page @@ -150,6 +149,8 @@ private end when "edit-name" scheme_path(@scheme) + when "check-answers" + schemes_path(scheme_id: @scheme.id) end end @@ -166,7 +167,8 @@ private :secondary_client_group, :support_type, :arrangement_type, - :intended_stay) + :intended_stay, + :confirmed) full_params = required_params[:arrangement_type] == "D" && required_params[:owning_organisation_id].present? ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params diff --git a/app/models/location.rb b/app/models/location.rb index 4812e2cd5..22d3b9607 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -7,6 +7,10 @@ class Location < ApplicationRecord attr_accessor :add_another_location + scope :search_by_postcode, ->(postcode) { where("postcode ILIKE ?", "%#{postcode.gsub(/\s+/, '')}%") } + scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } + scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) } + MOBILITY_TYPE = { "Wheelchair-user standard": "W", "Fitted with equipment and adaptations": "A", diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb index 891b4c320..20b6c7beb 100644 --- a/app/views/locations/index.html.erb +++ b/app/views/locations/index.html.erb @@ -1,4 +1,5 @@ -<% title = @scheme.service_name %> +<% item_label = format_label(@pagy.count, "location") %> +<% title = format_title(@searched, @scheme.service_name, current_user, item_label, @pagy.count, nil) %> <% content_for :title, title %> <% content_for :before_content do %> @@ -12,9 +13,13 @@ <%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, "Locations")) %> +<%= render SearchComponent.new(current_user:, search_label: "Search by location name or postcode", value: @searched) %> + +<%= govuk_section_break(visible: true, size: "m") %> + <%= govuk_table do |table| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> - <%= @scheme.locations.count %> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %> + <%= render(SearchResultCaptionComponent.new(searched: @searched, count: @pagy.count, item_label:, total_count: @total_count, item: "locations", path: request.path)) %> <% end %> <%= table.head do |head| %> <%= head.row do |row| %> @@ -47,5 +52,6 @@ <% end %> <% end %> <% end %> +<%= govuk_button_link_to "Add a location", new_location_path(id: @scheme.id), secondary: true %> <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "locations" } %> diff --git a/app/views/organisations/_organisation_list.html.erb b/app/views/organisations/_organisation_list.html.erb index c16366d19..68b8f3233 100644 --- a/app/views/organisations/_organisation_list.html.erb +++ b/app/views/organisations/_organisation_list.html.erb @@ -1,8 +1,8 @@
<%= govuk_table do |table| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> - <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "organisations", path: request.path)) %> - <% end %> + <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "organisations", path: request.path)) %> + <% end %> <%= table.head do |head| %> <%= head.row do |row| %> <% row.cell(header: true, text: "Name", html_attributes: { diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index 74009a84e..179a1afca 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -11,40 +11,48 @@ <%= summary_list.row do |row| %> <% row.key { attr[:name].to_s } %> <% row.value { details_html(attr) } %> - <% row.action( - text: "Change", - href: scheme_details_path(scheme_id: @scheme.id, check_answers: true), - ) %> + <% unless @scheme.confirmed? && attr[:name] != "Name" %> + <% row.action( + text: "Change", + href: scheme_details_path(@scheme, check_answers: true), + ) %> + <% end %> <% end %> <% end %> <% @scheme.check_support_services_provider_attributes.each do |attr| %> <%= summary_list.row do |row| %> <% row.key { attr[:name].to_s } %> <% row.value { details_html(attr) } %> - <% row.action( - text: "Change", - href: scheme_support_services_provider_path(scheme_id: @scheme.id, check_answers: true), - ) %> + <% unless @scheme.confirmed? %> + <% row.action( + text: "Change", + href: scheme_support_services_provider_path(@scheme, check_answers: true), + ) %> + <% end %> <% end %> <% end %> <% @scheme.check_primary_client_attributes.each do |attr| %> <%= summary_list.row do |row| %> <% row.key { attr[:name].to_s } %> <% row.value { details_html(attr) } %> - <% row.action( - text: "Change", - href: scheme_primary_client_group_path(scheme_id: @scheme.id, check_answers: true), - ) %> + <% unless @scheme.confirmed? %> + <% row.action( + text: "Change", + href: scheme_primary_client_group_path(@scheme, check_answers: true), + ) %> + <% end %> <% end %> <% end %> <% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %> <%= summary_list.row do |row| %> <% row.key { attr[:name].to_s } %> <% row.value { details_html(attr) } %> - <% row.action( - text: "Change", - href: scheme_confirm_secondary_client_group_path(scheme_id: @scheme.id, check_answers: true), - ) %> + <% unless @scheme.confirmed? %> + <% row.action( + text: "Change", + href: scheme_confirm_secondary_client_group_path(@scheme, check_answers: true), + ) %> + <% end %> <% end %> <% end %> <% if @scheme.has_other_client_group == "Yes" %> @@ -52,10 +60,12 @@ <%= summary_list.row do |row| %> <% row.key { attr[:name].to_s } %> <% row.value { details_html(attr) } %> - <% row.action( - text: "Change", - href: scheme_secondary_client_group_path(scheme_id: @scheme.id, check_answers: true), - ) %> + <% unless @scheme.confirmed? %> + <% row.action( + text: "Change", + href: scheme_secondary_client_group_path(@scheme, check_answers: true), + ) %> + <% end %> <% end %> <% end %> <% end %> @@ -63,10 +73,12 @@ <%= summary_list.row do |row| %> <% row.key { attr[:name].to_s } %> <% row.value { details_html(attr) } %> - <% row.action( - text: "Change", - href: scheme_support_path(scheme_id: @scheme.id, check_answers: true), - ) %> + <% unless @scheme.confirmed? %> + <% row.action( + text: "Change", + href: scheme_support_path(@scheme, check_answers: true), + ) %> + <% end %> <% end %> <% end %> <% end %> @@ -113,4 +125,9 @@ -<%= govuk_button_link_to "Create scheme", schemes_path(scheme_id: @scheme.id), html: { method: :get } %> +<%= form_for(@scheme, as: :scheme, method: :patch) do |f| %> + <%= f.hidden_field :page, value: "check-answers" %> + <%= f.hidden_field :confirmed, value: "true" %> + <% button_label = @scheme.confirmed? ? "Save" : "Create scheme" %> + <%= f.govuk_submit button_label %> +<% end %> diff --git a/db/migrate/20220719145718_add_confirmed_to_scheme.rb b/db/migrate/20220719145718_add_confirmed_to_scheme.rb new file mode 100644 index 000000000..f0372554e --- /dev/null +++ b/db/migrate/20220719145718_add_confirmed_to_scheme.rb @@ -0,0 +1,7 @@ +class AddConfirmedToScheme < ActiveRecord::Migration[7.0] + def change + change_table :schemes, bulk: true do |t| + t.column :confirmed, :boolean + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c05d38920..978fc7af6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -320,6 +320,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_20_111635) do t.string "old_id" t.integer "old_visible_id" t.integer "total_units" + t.boolean "confirmed" t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id" end diff --git a/db/seeds.rb b/db/seeds.rb index 3a084e436..264b25d69 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -80,6 +80,7 @@ unless Rails.env.test? primary_client_group: "O", secondary_client_group: "H", owning_organisation: org, + confirmed: true, created_at: Time.zone.now, ) @@ -93,6 +94,7 @@ unless Rails.env.test? primary_client_group: "D", secondary_client_group: "E", owning_organisation: org, + confirmed: true, created_at: Time.zone.now, ) @@ -106,6 +108,7 @@ unless Rails.env.test? primary_client_group: "G", secondary_client_group: "R", owning_organisation: dummy_org, + confirmed: true, created_at: Time.zone.now, ) diff --git a/spec/factories/scheme.rb b/spec/factories/scheme.rb index 4e35d0b8e..ab3342fea 100644 --- a/spec/factories/scheme.rb +++ b/spec/factories/scheme.rb @@ -10,6 +10,7 @@ FactoryBot.define do primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } owning_organisation { FactoryBot.create(:organisation) } + confirmed { true } created_at { Time.zone.now } trait :export do sensitive { 1 } diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 4001b5c05..078d0ab36 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -202,6 +202,91 @@ RSpec.describe "Schemes scheme Features" do end end end + + context "when I search for a specific location" do + before do + click_link("Locations") + end + + it "there is a search bar with a message and search button for locations" do + expect(page).to have_field("search") + expect(page).to have_content("Search by location name or postcode") + expect(page).to have_button("Search") + end + + context "when I fill in search information and press the search button" do + let(:postcode_to_search) { "NW38RR" } + let(:location_name_to_search) { "search name location" } + let(:location_to_search) { FactoryBot.create(:location, postcode: postcode_to_search, name: location_name_to_search, scheme:) } + + before do + fill_in("search", with: location_to_search.name) + click_button("Search") + end + + it "displays scheme matching the location name" do + expect(page).to have_content(location_name_to_search) + end + + context "when I want to clear results" do + it "there is link to clear the search results" do + expect(page).to have_link("Clear search") + end + + it "displays all schemes after I clear the search results" do + click_link("Clear search") + Location.all.each do |location| + expect(page).to have_content(location.name) + end + end + end + end + end + + context "when the user clicks add location" do + before do + click_link("Locations") + click_link("Add a location") + end + + it "shows the new location form" do + expect(page).to have_content("Add a location to this scheme") + end + + context "when the user completes the new location form" do + let(:location_name) { "Area 42" } + + before do + fill_in "Postcode", with: "NW1L 5DP" + fill_in "Location name (optional)", with: location_name + fill_in "Total number of units at this location", with: 1 + choose "Bungalow" + choose "location-mobility-type-none-field" + choose "location-add-another-location-no-field" + click_button "Save and continue" + end + + it "shows the check answers page location tab" do + expect(page.current_url.split("/").last).to eq("check-answers#locations") + expect(page).to have_content(location_name) + end + + it "has the correct action button text" do + expect(page).to have_button("Save") + expect(page).not_to have_button("Create scheme") + end + + context "when you click to view the scheme details" do + before do + click_link("Scheme") + end + + it "does not let you change details other than the name" do + assert_selector "a", text: "Change", count: 1 + end + end + end + end end end end @@ -457,7 +542,7 @@ RSpec.describe "Schemes scheme Features" do before do create_and_save_a_scheme fill_in_and_save_location - click_link "Create scheme" + click_button "Create scheme" end it "adds scheme to the list of schemes" do @@ -465,7 +550,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content scheme.id_to_display expect(page).to have_content scheme.service_name expect(page).to have_content scheme.owning_organisation.name - expect(page).to have_content "#{scheme.owning_organisation.name} has been created." + expect(page).to have_content "#{scheme.service_name} has been created." end end @@ -641,6 +726,91 @@ RSpec.describe "Schemes scheme Features" do end end end + + context "when I search for a specific location" do + before do + click_link("Locations") + end + + it "there is a search bar with a message and search button for locations" do + expect(page).to have_field("search") + expect(page).to have_content("Search by location name or postcode") + expect(page).to have_button("Search") + end + + context "when I fill in search information and press the search button" do + let(:postcode_to_search) { "NW38RR" } + let(:location_name_to_search) { "search name location" } + let(:location_to_search) { FactoryBot.create(:location, postcode: postcode_to_search, name: location_name_to_search, scheme:) } + + before do + fill_in("search", with: location_to_search.name) + click_button("Search") + end + + it "displays scheme matching the location name" do + expect(page).to have_content(location_name_to_search) + end + + context "when I want to clear results" do + it "there is link to clear the search results" do + expect(page).to have_link("Clear search") + end + + it "displays all schemes after I clear the search results" do + click_link("Clear search") + Location.all.each do |location| + expect(page).to have_content(location.name) + end + end + end + end + end + + context "when the user clicks add location" do + before do + click_link("Locations") + click_link("Add a location") + end + + it "shows the new location form" do + expect(page).to have_content("Add a location to this scheme") + end + + context "when the user completes the new location form" do + let(:location_name) { "Area 42" } + + before do + fill_in "Postcode", with: "NW1L 5DP" + fill_in "Location name (optional)", with: location_name + fill_in "Total number of units at this location", with: 1 + choose "Bungalow" + choose "location-mobility-type-none-field" + choose "location-add-another-location-no-field" + click_button "Save and continue" + end + + it "shows the check answers page location tab" do + expect(page.current_url.split("/").last).to eq("check-answers#locations") + expect(page).to have_content(location_name) + end + + it "has the correct action button text" do + expect(page).to have_button("Save") + expect(page).not_to have_button("Create scheme") + end + + context "when you click to view the scheme details" do + before do + click_link("Scheme") + end + + it "does not let you change details other than the name" do + assert_selector "a", text: "Change", count: 1 + end + end + end + end end end end diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index e5feaec24..9cebd09ef 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -55,4 +55,32 @@ RSpec.describe Location, type: :model do .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Type of unit Select the most common type of unit at this location") end end + + describe "scopes" do + before do + FactoryBot.create(:location, name: "ABC", postcode: "NW18RR") + FactoryBot.create(:location, name: "XYZ", postcode: "SE16HJ") + end + + context "when searching by name" do + it "returns case insensitive matching records" do + expect(described_class.search_by_name("abc").count).to eq(1) + expect(described_class.search_by_name("AbC").count).to eq(1) + end + end + + context "when searching by postcode" do + it "returns case insensitive matching records" do + expect(described_class.search_by_postcode("se1 6hj").count).to eq(1) + expect(described_class.search_by_postcode("SE1 6HJ").count).to eq(1) + end + end + + context "when searching by all searchable field" do + it "returns case insensitive matching records" do + expect(described_class.search_by("aBc").count).to eq(1) + expect(described_class.search_by("nw18rr").count).to eq(1) + end + end + end end diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 3e099e32d..ea9018c0c 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -864,6 +864,30 @@ RSpec.describe LocationsController, type: :request do end end end + + context "when searching" do + let(:searched_location) { locations.first } + let(:search_param) { searched_location.name } + + before do + get "/schemes/#{scheme.id}/locations?search=#{search_param}" + end + + it "returns matching results" do + expect(page).to have_content(searched_location.name) + locations[1..].each do |location| + expect(page).not_to have_content(location.name) + end + end + + it "updates the table caption" do + expect(page).to have_content("1 location found matching ‘#{search_param}’") + end + + it "has search in the title" do + expect(page).to have_title("#{scheme.service_name} (1 location matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") + end + end end context "when signed in as a support user" do @@ -942,6 +966,30 @@ RSpec.describe LocationsController, type: :request do end end end + + context "when searching" do + let(:searched_location) { locations.first } + let(:search_param) { searched_location.name } + + before do + get "/schemes/#{scheme.id}/locations?search=#{search_param}" + end + + it "returns matching results" do + expect(page).to have_content(searched_location.name) + locations[1..].each do |location| + expect(page).not_to have_content(location.name) + end + end + + it "updates the table caption" do + expect(page).to have_content("1 location found matching ‘#{search_param}’") + end + + it "has search in the title" do + expect(page).to have_title("#{scheme.service_name} (1 location matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") + end + end end end From 40f3992959b48ca325ee7cdf98cf41a9172654dd Mon Sep 17 00:00:00 2001 From: Dushan <47317567+dushan-madetech@users.noreply.github.com> Date: Fri, 22 Jul 2022 10:04:20 +0100 Subject: [PATCH 02/20] Fix page display (#770) --- app/views/schemes/support_services_provider.html.erb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/schemes/support_services_provider.html.erb b/app/views/schemes/support_services_provider.html.erb index 5a1dae620..cf1891ef0 100644 --- a/app/views/schemes/support_services_provider.html.erb +++ b/app/views/schemes/support_services_provider.html.erb @@ -7,8 +7,6 @@ ) %> <% end %> -<%= render partial: "organisations/headings", locals: { main: "Which organisation provides the support services used by this scheme?", sub: nil } %> - <%= form_for(@scheme, method: :patch) do |f| %>
@@ -22,7 +20,7 @@ managing_org_answer_options, :id, :name, - label: { text: "Which organisation manages this scheme?", size: "m" }, + label: { text: "Which organisation provides the support services used by this scheme?", size: "m" }, options: { required: true }, "data-controller": %w[accessible-autocomplete conditional-filter] %> From 2a6774d904e3274bf5fe92c354db2beca90e69b0 Mon Sep 17 00:00:00 2001 From: Dushan <47317567+dushan-madetech@users.noreply.github.com> Date: Fri, 22 Jul 2022 11:00:18 +0100 Subject: [PATCH 03/20] make email appear in created by if name is blank (#773) --- app/models/form/setup/questions/created_by_id.rb | 5 +++-- spec/models/form/setup/questions/created_by_id_spec.rb | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/form/setup/questions/created_by_id.rb b/app/models/form/setup/questions/created_by_id.rb index eee7d9485..f32163a0f 100644 --- a/app/models/form/setup/questions/created_by_id.rb +++ b/app/models/form/setup/questions/created_by_id.rb @@ -13,8 +13,9 @@ class Form::Setup::Questions::CreatedById < ::Form::Question answer_opts = { "" => "Select an option" } return answer_opts unless ActiveRecord::Base.connected? - User.select(:id, :name).each_with_object(answer_opts) do |user, hsh| - hsh[user.id] = user.name + User.select(:id, :name, :email).each_with_object(answer_opts) do |user, hsh| + hsh[user.id] = user.name if user.name.present? + hsh[user.id] = user.email if user.name.blank? hsh end end diff --git a/spec/models/form/setup/questions/created_by_id_spec.rb b/spec/models/form/setup/questions/created_by_id_spec.rb index 84a7083be..80744d94b 100644 --- a/spec/models/form/setup/questions/created_by_id_spec.rb +++ b/spec/models/form/setup/questions/created_by_id_spec.rb @@ -10,11 +10,13 @@ RSpec.describe Form::Setup::Questions::CreatedById, type: :model do let(:form) { instance_double(Form) } let!(:user_1) { FactoryBot.create(:user, name: "first user") } let!(:user_2) { FactoryBot.create(:user, name: "second user") } + let!(:user_3) { FactoryBot.create(:user, name: nil, email: "madeupmail@example.com") } let(:expected_answer_options) do { "" => "Select an option", user_1.id => user_1.name, user_2.id => user_2.name, + user_3.id => user_3.email, } end From 3a6dfaa30d5ce2ea72a39d67bd07930b9e65582b Mon Sep 17 00:00:00 2001 From: J G <7750475+moarpheus@users.noreply.github.com> Date: Fri, 22 Jul 2022 11:16:23 +0100 Subject: [PATCH 04/20] Cldc 1388 Show local authority for location (#769) * failing test to display local authority * passing tests - sadly with not allowed net connections * added relevant tests and tweaked the webmock * shorter output from api * location_admin_district for location * location_admin_district for location * fixed tests --- app/models/case_log.rb | 3 ++- app/models/location.rb | 10 +++++++--- app/services/postcode_service.rb | 7 +++++-- app/views/locations/index.html.erb | 4 ++++ app/views/schemes/check_answers.html.erb | 4 ++++ ...2083835_add_location_admin_district_to_locations.rb | 5 +++++ db/schema.rb | 3 ++- spec/features/schemes_helpers.rb | 2 +- spec/features/schemes_spec.rb | 7 +++++-- spec/request_helper.rb | 4 ++++ spec/services/imports/case_logs_import_service_spec.rb | 2 +- 11 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20220722083835_add_location_admin_district_to_locations.rb diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 83e7b6550..c8ab60ed0 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -603,7 +603,8 @@ private end def get_inferred_la(postcode) - PIO.infer_la(postcode) + result = PIO.lookup(postcode) + result[:location_code] if result end def get_has_benefits diff --git a/app/models/location.rb b/app/models/location.rb index 22d3b9607..c21917b70 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -3,7 +3,7 @@ class Location < ApplicationRecord validates :units, :type_of_unit, :mobility_type, presence: true belongs_to :scheme - before_save :infer_la!, if: :postcode_changed? + before_save :lookup_postcode!, if: :postcode_changed? attr_accessor :add_another_location @@ -52,7 +52,11 @@ private end end - def infer_la! - self.location_code = PIO.infer_la(postcode) + def lookup_postcode! + result = PIO.lookup(postcode) + if result + self.location_code = result[:location_code] + self.location_admin_district = result[:location_admin_district] + end end end diff --git a/app/services/postcode_service.rb b/app/services/postcode_service.rb index a82dcc2aa..74c1f4895 100644 --- a/app/services/postcode_service.rb +++ b/app/services/postcode_service.rb @@ -3,7 +3,7 @@ class PostcodeService @pio = Postcodes::IO.new end - def infer_la(postcode) + def lookup(postcode) # Avoid network calls when postcode is invalid return unless postcode.match(POSTCODE_REGEXP) @@ -16,7 +16,10 @@ class PostcodeService Rails.logger.warn("Postcodes.io lookup timed out") end if postcode_lookup && postcode_lookup.info.present? - postcode_lookup.codes["admin_district"] + { + location_code: postcode_lookup.codes["admin_district"], + location_admin_district: postcode_lookup&.admin_district, + } end end diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb index 20b6c7beb..9dad4e9fe 100644 --- a/app/views/locations/index.html.erb +++ b/app/views/locations/index.html.erb @@ -38,6 +38,9 @@ <% row.cell(header: true, text: "Mobility type", html_attributes: { scope: "col", }) %> + <% row.cell(header: true, text: "Local authority", html_attributes: { + scope: "col", + }) %> <% end %> <% end %> <% @locations.each do |location| %> @@ -48,6 +51,7 @@ <% row.cell(text: location.units) %> <% row.cell(text: simple_format("#{location.type_of_unit}")) %> <% row.cell(text: location.mobility_type) %> + <% row.cell(text: location.location_admin_district) %> <% end %> <% end %> <% end %> diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index 179a1afca..845b75560 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -105,6 +105,9 @@ <% row.cell(header: true, text: "Mobility type", html_attributes: { scope: "col", }) %> + <% row.cell(header: true, text: "Local authority", html_attributes: { + scope: "col", + }) %> <% end %> <% end %> <% @scheme.locations.each do |location| %> @@ -115,6 +118,7 @@ <% row.cell(text: location.units) %> <% row.cell(text: simple_format("#{location.type_of_unit}")) %> <% row.cell(text: location.mobility_type) %> + <% row.cell(text: location.location_admin_district) %> <% end %> <% end %> <% end %> diff --git a/db/migrate/20220722083835_add_location_admin_district_to_locations.rb b/db/migrate/20220722083835_add_location_admin_district_to_locations.rb new file mode 100644 index 000000000..05c354099 --- /dev/null +++ b/db/migrate/20220722083835_add_location_admin_district_to_locations.rb @@ -0,0 +1,5 @@ +class AddLocationAdminDistrictToLocations < ActiveRecord::Migration[7.0] + def change + add_column :locations, :location_admin_district, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 978fc7af6..39bc35e94 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_07_20_111635) do +ActiveRecord::Schema[7.0].define(version: 2022_07_22_083835) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -250,6 +250,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_20_111635) do t.integer "old_visible_id" t.string "mobility_type" t.datetime "startdate", precision: nil + t.string "location_admin_district" t.index ["old_id"], name: "index_locations_on_old_id", unique: true t.index ["scheme_id"], name: "index_locations_on_scheme_id" end diff --git a/spec/features/schemes_helpers.rb b/spec/features/schemes_helpers.rb index 7bf087bab..3814a2f4c 100644 --- a/spec/features/schemes_helpers.rb +++ b/spec/features/schemes_helpers.rb @@ -55,7 +55,7 @@ module SchemesHelpers end def fill_in_and_save_location - fill_in "Postcode", with: "SW1P 4DF" + fill_in "Postcode", with: "AA1 1AA" fill_in "Location name (optional)", with: "Some name" fill_in "Total number of units at this location", with: 1 choose "Self-contained house" diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 078d0ab36..ae8ed5aba 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -175,7 +175,7 @@ RSpec.describe "Schemes scheme Features" do context "when there are locations that belong to the selected scheme" do let!(:schemes) { FactoryBot.create_list(:scheme, 5) } let(:scheme) { schemes.first } - let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) } + let!(:locations) { FactoryBot.create_list(:location, 3, scheme:, postcode: "AA11AA") } before do visit("schemes") @@ -199,6 +199,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content(location.units) expect(page).to have_content(location.type_of_unit) expect(page).to have_content(location.mobility_type) + expect(page).to have_content(location.location_admin_district) end end end @@ -468,10 +469,12 @@ RSpec.describe "Schemes scheme Features" do end it "displays information about the first created location" do - expect(page).to have_content "SW1P4DF" + expect(page).to have_content "AA11AA" expect(page).to have_content "Some name" expect(page).to have_content "Self-contained house" expect(page).to have_content "None" + expect(page).to have_content "Local authority" + expect(page).to have_content "Westminster" end it "displays information about another location" do diff --git a/spec/request_helper.rb b/spec/request_helper.rb index d2bef6d5c..93dc6f1dc 100644 --- a/spec/request_helper.rb +++ b/spec/request_helper.rb @@ -5,6 +5,10 @@ module RequestHelper WebMock.disable_net_connect!(allow_localhost: true) WebMock.stub_request(:get, /api.postcodes.io/) .to_return(status: 200, body: "{\"status\":404,\"error\":\"Postcode not found\"}", headers: {}) + + WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/AA11AA") + .to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"AA1 1AA\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {}) + WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/email/) .to_return(status: 200, body: "", headers: {}) WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/sms/) diff --git a/spec/services/imports/case_logs_import_service_spec.rb b/spec/services/imports/case_logs_import_service_spec.rb index 281a7b600..e763099b9 100644 --- a/spec/services/imports/case_logs_import_service_spec.rb +++ b/spec/services/imports/case_logs_import_service_spec.rb @@ -20,7 +20,7 @@ RSpec.describe Imports::CaseLogsImportService do before do WebMock.stub_request(:get, /api.postcodes.io\/postcodes\/LS166FT/) - .to_return(status: 200, body: '{"status":200,"result":{"codes":{"admin_district":"E08000035"}}}', headers: {}) + .to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Westminster","codes":{"admin_district":"E08000035"}}}', headers: {}) allow(Organisation).to receive(:find_by).and_return(nil) allow(Organisation).to receive(:find_by).with(old_visible_id: organisation.old_visible_id.to_i).and_return(organisation) From 49b74ab1d9d00c5ab94e0ac78399d98d606996c0 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 22 Jul 2022 11:35:07 +0100 Subject: [PATCH 05/20] Bump deps --- Gemfile.lock | 4 ++-- yarn.lock | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7dd945071..8da6b2c8d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -82,7 +82,7 @@ GEM public_suffix (>= 2.0.2, < 5.0) ast (2.4.2) aws-eventstream (1.2.0) - aws-partitions (1.608.0) + aws-partitions (1.609.0) aws-sdk-core (3.131.3) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.525.0) @@ -157,7 +157,7 @@ GEM rubocop smart_properties erubi (1.10.0) - excon (0.92.3) + excon (0.92.4) factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) diff --git a/yarn.lock b/yarn.lock index 79dc0eae7..04538a43c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1448,9 +1448,9 @@ acorn@^7.1.1: integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== acorn@^8.4.1, acorn@^8.5.0, acorn@^8.7.1: - version "8.7.1" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.1.tgz#0197122c843d1bf6d0a5e83220a788f278f63c30" - integrity sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A== + version "8.8.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8" + integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w== ajv-formats@^2.1.1: version "2.1.1" @@ -1915,9 +1915,9 @@ camelcase@^5.3.1: integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== caniuse-lite@^1.0.30001366: - version "1.0.30001367" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001367.tgz#2b97fe472e8fa29c78c5970615d7cd2ee414108a" - integrity sha512-XDgbeOHfifWV3GEES2B8rtsrADx4Jf+juKX2SICJcaUhjYBO3bR96kvEIHa15VU6ohtOhBZuPGGYGbXMRn0NCw== + version "1.0.30001368" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001368.tgz#c5c06381c6051cd863c45021475434e81936f713" + integrity sha512-wgfRYa9DenEomLG/SdWgQxpIyvdtH3NW8Vq+tB6AwR9e56iOIcu1im5F/wNdDf04XlKHXqIx4N8Jo0PemeBenQ== chalk@^1.1.3: version "1.1.3" @@ -2384,9 +2384,9 @@ ejs@^3.1.6: jake "^10.8.5" electron-to-chromium@^1.4.188: - version "1.4.195" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.195.tgz#139b2d95a42a3f17df217589723a1deac71d1473" - integrity sha512-vefjEh0sk871xNmR5whJf9TEngX+KTKS3hOHpjoMpauKkwlGwtMz1H8IaIjAT/GNnX0TbGwAdmVoXCAzXf+PPg== + version "1.4.198" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.198.tgz#36a8e7871046f7f94c01dc0133912fd5cf226c6a" + integrity sha512-jwqQPdKGeAslcq8L+1SZZgL6uDiIDmTe9Gq4brsdWAH27y7MJ2g9Ue6MyST3ogmSM49EAQP7bype1V5hsuNrmQ== element-closest@^2.0.2: version "2.0.2" @@ -3090,9 +3090,9 @@ globals@^11.1.0: integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== globals@^13.15.0: - version "13.16.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-13.16.0.tgz#9be4aca28f311aaeb974ea54978ebbb5e35ce46a" - integrity sha512-A1lrQfpNF+McdPOnnFqY3kSN0AFTy485bTi1bkLk4mVPODIUEcSfhHgRqA+QdXPksrSTTztYXx37NFV+GpGk3Q== + version "13.17.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-13.17.0.tgz#902eb1e680a41da93945adbdcb5a9f361ba69bd4" + integrity sha512-1C+6nQRb1GwGMKm2dH/E7enFAMxGTmGI7/dEdhy/DNelv85w9B72t3uc5frtMNXIbzrarJJ/lTCjcaZwbLJmyw== dependencies: type-fest "^0.20.2" @@ -3822,9 +3822,9 @@ linkify-it@^3.0.1: uc.micro "^1.0.1" liquidjs@^9.36.1: - version "9.39.1" - resolved "https://registry.yarnpkg.com/liquidjs/-/liquidjs-9.39.1.tgz#850039c7c95ad5fa5ff66aa3dddfd6d2fad93128" - integrity sha512-TFu19Cml0K2T34UY50ZKUApHgiiEaayqNW9J3o3ubLQCuhMFhY7jqwNpY1oVvvAJxCCxVqL6bJnGc1Fktth0Fw== + version "9.39.2" + resolved "https://registry.yarnpkg.com/liquidjs/-/liquidjs-9.39.2.tgz#f2409f1108b91fc4f1b06e1f51f2be70f434cb92" + integrity sha512-7fdd8hn7U/FUANGWaBbF41LmsRS40uXj/jFldyddYqgLDGMyZSYJsajOvZIZGkAxJdUYbZksrHRU4Q8kg8sTPg== list-to-array@^1.1.0: version "1.1.0" From 405853b4b52bc9bff7e45f95129631a9dadb377f Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 22 Jul 2022 11:41:58 +0100 Subject: [PATCH 06/20] Bump doc deps --- docs/Gemfile.lock | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/Gemfile.lock b/docs/Gemfile.lock index 4756571a5..7b69acce2 100644 --- a/docs/Gemfile.lock +++ b/docs/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - activesupport (6.0.5) + activesupport (6.0.5.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -32,7 +32,7 @@ GEM ffi (1.15.5) forwardable-extended (2.6.0) gemoji (3.0.1) - github-pages (226) + github-pages (227) github-pages-health-check (= 1.17.9) jekyll (= 3.9.2) jekyll-avatar (= 0.7.0) @@ -74,7 +74,7 @@ GEM liquid (= 4.0.3) mercenary (~> 0.3) minima (= 2.5.1) - nokogiri (>= 1.13.4, < 2.0) + nokogiri (>= 1.13.6, < 2.0) rouge (= 3.26.0) terminal-table (~> 1.4) github-pages-health-check (1.17.9) @@ -211,7 +211,9 @@ GEM jekyll-feed (~> 0.9) jekyll-seo-tag (~> 2.1) minitest (5.16.2) - nokogiri (1.13.6-arm64-darwin) + nokogiri (1.13.7-arm64-darwin) + racc (~> 1.4) + nokogiri (1.13.7-x86_64-linux) racc (~> 1.4) octokit (4.25.1) faraday (>= 1, < 3) @@ -243,7 +245,7 @@ GEM thread_safe (0.3.6) typhoeus (1.4.0) ethon (>= 0.9.0) - tzinfo (1.2.9) + tzinfo (1.2.10) thread_safe (~> 0.1) unf (0.1.4) unf_ext @@ -254,10 +256,11 @@ GEM PLATFORMS arm64-darwin-21 + x86_64-linux DEPENDENCIES github-pages webrick BUNDLED WITH - 2.3.4 + 2.3.14 From 17ed0f1b0553b06957021e48b17658250ffe04c7 Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Fri, 22 Jul 2022 15:31:14 +0100 Subject: [PATCH 07/20] Fix scheme question when case log doesn't have an organisation yet (#774) * Fix scheme question when case log doesn't have an organisation yet * Reset scheme if it doesn't match org --- app/models/case_log.rb | 7 +++++ app/models/form/setup/questions/scheme_id.rb | 8 +++--- spec/models/case_log_spec.rb | 25 ++++++++++++++++- .../form/setup/questions/location_id_spec.rb | 2 +- spec/requests/form_controller_spec.rb | 27 +++++++++++++++++++ .../exports/case_log_export_service_spec.rb | 7 +++-- 6 files changed, 68 insertions(+), 8 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index c8ab60ed0..93e3a4cc4 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -539,10 +539,17 @@ private self.created_by = nil if created_by.organisation != owning_organisation end + def reset_scheme + return unless scheme && owning_organisation + + self.scheme = nil if scheme.owning_organisation != owning_organisation + end + def reset_invalidated_dependent_fields! return unless form reset_created_by + reset_scheme reset_not_routed_questions reset_derived_questions end diff --git a/app/models/form/setup/questions/scheme_id.rb b/app/models/form/setup/questions/scheme_id.rb index fe811f28a..cf6173591 100644 --- a/app/models/form/setup/questions/scheme_id.rb +++ b/app/models/form/setup/questions/scheme_id.rb @@ -20,11 +20,11 @@ class Form::Setup::Questions::SchemeId < ::Form::Question end def displayed_answer_options(case_log) - return {} unless case_log.created_by - - user_org_scheme_ids = Scheme.select(:id).where(owning_organisation_id: case_log.created_by.organisation_id).joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL", Time.zone.today)).map(&:id) + organisation = case_log.owning_organisation || case_log.created_by&.organisation + schemes = organisation ? Scheme.select(:id).where(owning_organisation_id: organisation.id) : Scheme.select(:id) + filtered_scheme_ids = schemes.joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL", Time.zone.today)).map(&:id) answer_options.select do |k, _v| - user_org_scheme_ids.include?(k.to_i) || k.blank? + filtered_scheme_ids.include?(k.to_i) || k.blank? end end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index af64ab06f..81da18de9 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1875,6 +1875,28 @@ RSpec.describe CaseLog do expect { case_log.update!(owning_organisation: organisation_2) } .to change { case_log.reload.created_by }.from(created_by_user).to(nil) end + + context "when the organisation selected doesn't match the scheme set" do + let(:scheme) { FactoryBot.create(:scheme, owning_organisation: created_by_user.organisation) } + let(:location) { FactoryBot.create(:location, scheme:) } + let(:case_log) { FactoryBot.create(:case_log, owning_organisation: nil, needstype: 2, scheme_id: scheme.id) } + + it "clears the scheme value" do + case_log.update!(owning_organisation: organisation_2) + expect(case_log.reload.scheme).to be nil + end + end + + context "when the organisation selected still matches the scheme set" do + let(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation_2) } + let(:location) { FactoryBot.create(:location, scheme:) } + let(:case_log) { FactoryBot.create(:case_log, owning_organisation: nil, needstype: 2, scheme_id: scheme.id) } + + it "does not clear the scheme value" do + case_log.update!(owning_organisation: organisation_2) + expect(case_log.reload.scheme_id).to eq(scheme.id) + end + end end end @@ -2240,13 +2262,14 @@ RSpec.describe CaseLog do let(:csv_export_file) { File.open("spec/fixtures/files/case_logs_download.csv", "r:UTF-8") } let(:scheme) { FactoryBot.create(:scheme) } let(:location) { FactoryBot.create(:location, scheme:, type_of_unit: 6, postcode: "SE11TE") } + let(:user) { FactoryBot.create(:user, organisation: location.scheme.owning_organisation) } before do Timecop.freeze(Time.utc(2022, 6, 5)) end it "generates a correct csv from a case log" do - case_log = FactoryBot.create(:case_log, needstype: 2, scheme:, location:) + case_log = FactoryBot.create(:case_log, needstype: 2, scheme:, location:, owning_organisation: scheme.owning_organisation, created_by: user) expected_content = csv_export_file.read expected_content.sub!(/\{id\}/, case_log["id"].to_s) expected_content.sub!(/\{owning_org_id\}/, case_log["owning_organisation_id"].to_s) diff --git a/spec/models/form/setup/questions/location_id_spec.rb b/spec/models/form/setup/questions/location_id_spec.rb index c8681810f..1d544ebad 100644 --- a/spec/models/form/setup/questions/location_id_spec.rb +++ b/spec/models/form/setup/questions/location_id_spec.rb @@ -39,7 +39,7 @@ RSpec.describe Form::Setup::Questions::LocationId, type: :model do context "when getting available locations" do let(:scheme) { FactoryBot.create(:scheme) } - let(:case_log) { FactoryBot.create(:case_log, scheme:, needstype: 2) } + let(:case_log) { FactoryBot.create(:case_log, owning_organisation: scheme.owning_organisation, scheme:, needstype: 2) } context "when there are no locations" do it "the displayed_answer_options is an empty hash" do diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 0ad7494e0..d6b4a5a30 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -93,6 +93,33 @@ RSpec.describe FormController, type: :request do expect(response.body).to match("What counts as income?") end end + + context "when viewing the setup section schemes page" do + context "when the user is support" do + let(:user) { FactoryBot.create(:user, :support) } + + context "when organisation and user have not been selected yet" do + let(:case_log) do + FactoryBot.create( + :case_log, + owning_organisation: nil, + managing_organisation: nil, + created_by: nil, + needstype: 2, + ) + end + + before do + FactoryBot.create_list(:location, 5) + end + + it "returns an unfiltered list of schemes" do + get "/logs/#{case_log.id}/scheme", headers: headers, params: {} + expect(response.body.scan("