107 changed files with 2451 additions and 330 deletions
@ -0,0 +1,2 @@
|
||||
--format progress |
||||
--format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log |
@ -0,0 +1,26 @@
|
||||
module SchemesHelper |
||||
def display_scheme_attributes(scheme) |
||||
base_attributes = [ |
||||
{ name: "Scheme code", value: scheme.id_to_display }, |
||||
{ name: "Name", value: scheme.service_name, edit: true }, |
||||
{ name: "Confidential information", value: scheme.sensitive, edit: true }, |
||||
{ name: "Type of scheme", value: scheme.scheme_type }, |
||||
{ name: "Registered under Care Standards Act 2000", value: scheme.registered_under_care_act }, |
||||
{ name: "Housing stock owned by", value: scheme.owning_organisation.name, edit: true }, |
||||
{ name: "Support services provided by", value: scheme.arrangement_type }, |
||||
{ name: "Organisation providing support", value: scheme.managing_organisation&.name }, |
||||
{ name: "Primary client group", value: scheme.primary_client_group }, |
||||
{ name: "Has another client group", value: scheme.has_other_client_group }, |
||||
{ name: "Secondary client group", value: scheme.secondary_client_group }, |
||||
{ name: "Level of support given", value: scheme.support_type }, |
||||
{ name: "Intended length of stay", value: scheme.intended_stay }, |
||||
{ name: "Availability", value: "Available from #{scheme.available_from.to_formatted_s(:govuk_date)}" }, |
||||
{ name: "Status", value: scheme.status }, |
||||
] |
||||
|
||||
if scheme.arrangement_type_same? |
||||
base_attributes.delete({ name: "Organisation providing support", value: scheme.managing_organisation&.name }) |
||||
end |
||||
base_attributes |
||||
end |
||||
end |
@ -0,0 +1,19 @@
|
||||
class Form::Lettings::Pages::CreatedBy < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "created_by" |
||||
@header = "" |
||||
@description = "" |
||||
@subsection = subsection |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::CreatedById.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def routed_to?(_log, current_user) |
||||
!!current_user&.support? |
||||
end |
||||
end |
@ -0,0 +1,30 @@
|
||||
class Form::Lettings::Pages::HousingProvider < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "housing_provider" |
||||
@header = "" |
||||
@description = "" |
||||
@subsection = subsection |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::HousingProvider.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def routed_to?(log, current_user) |
||||
return false unless current_user |
||||
return true if current_user.support? |
||||
return true unless current_user.organisation.holds_own_stock? |
||||
|
||||
housing_providers = current_user.organisation.housing_providers |
||||
|
||||
return false if housing_providers.count.zero? |
||||
return true if housing_providers.count > 1 |
||||
|
||||
log.update!(owning_organisation: housing_providers.first) |
||||
|
||||
false |
||||
end |
||||
end |
@ -0,0 +1,30 @@
|
||||
class Form::Lettings::Pages::ManagingOrganisation < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "managing_organisation" |
||||
@header = "" |
||||
@description = "" |
||||
@subsection = subsection |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::ManagingOrganisation.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def routed_to?(log, current_user) |
||||
return false unless current_user |
||||
return true if current_user.support? |
||||
return true unless current_user.organisation.holds_own_stock? |
||||
|
||||
managing_agents = current_user.organisation.managing_agents |
||||
|
||||
return false if managing_agents.count.zero? |
||||
return true if managing_agents.count > 1 |
||||
|
||||
log.update!(managing_organisation: managing_agents.first) |
||||
|
||||
false |
||||
end |
||||
end |
@ -0,0 +1,48 @@
|
||||
class Form::Lettings::Questions::CreatedById < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "created_by_id" |
||||
@check_answer_label = "Log owner" |
||||
@header = "Which user are you creating this log for?" |
||||
@hint_text = "" |
||||
@type = "select" |
||||
@page = page |
||||
end |
||||
|
||||
def answer_options |
||||
answer_opts = { "" => "Select an option" } |
||||
return answer_opts unless ActiveRecord::Base.connected? |
||||
|
||||
User.select(:id, :name, :email).each_with_object(answer_opts) do |user, hsh| |
||||
hsh[user.id] = "#{user.name} (#{user.email})" |
||||
hsh |
||||
end |
||||
end |
||||
|
||||
def displayed_answer_options(log, _user = nil) |
||||
return answer_options unless log.owning_organisation |
||||
|
||||
user_ids = log.owning_organisation.users.pluck(:id) + [""] |
||||
answer_options.select { |k, _v| user_ids.include?(k) } |
||||
end |
||||
|
||||
def label_from_value(value) |
||||
return unless value |
||||
|
||||
answer_options[value] |
||||
end |
||||
|
||||
def hidden_in_check_answers?(_log, current_user) |
||||
!current_user.support? |
||||
end |
||||
|
||||
def derived? |
||||
true |
||||
end |
||||
|
||||
private |
||||
|
||||
def selected_answer_option_is_derived?(_log) |
||||
true |
||||
end |
||||
end |
@ -0,0 +1,68 @@
|
||||
class Form::Lettings::Questions::HousingProvider < ::Form::Question |
||||
attr_accessor :current_user, :log |
||||
|
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "owning_organisation_id" |
||||
@check_answer_label = "Housing provider" |
||||
@header = "Which organisation owns this property?" |
||||
@type = "select" |
||||
@page = page |
||||
end |
||||
|
||||
def answer_options |
||||
answer_opts = { "" => "Select an option" } |
||||
return answer_opts unless ActiveRecord::Base.connected? |
||||
return answer_opts unless current_user |
||||
|
||||
if !current_user.support? && current_user.organisation.holds_own_stock? |
||||
answer_opts[current_user.organisation.id] = "#{current_user.organisation.name} (Your organisation)" |
||||
end |
||||
|
||||
answer_opts.merge(housing_providers_answer_options) |
||||
end |
||||
|
||||
def displayed_answer_options(log, user = nil) |
||||
@current_user = user |
||||
@log = log |
||||
|
||||
answer_options |
||||
end |
||||
|
||||
def label_from_value(value) |
||||
return unless value |
||||
|
||||
answer_options[value] |
||||
end |
||||
|
||||
def derived? |
||||
true |
||||
end |
||||
|
||||
def hidden_in_check_answers?(_log, user = nil) |
||||
@current_user = user |
||||
|
||||
return false unless @current_user |
||||
return false if @current_user.support? |
||||
|
||||
housing_providers_answer_options.count < 2 |
||||
end |
||||
|
||||
def enabled |
||||
true |
||||
end |
||||
|
||||
private |
||||
|
||||
def selected_answer_option_is_derived?(_log) |
||||
true |
||||
end |
||||
|
||||
def housing_providers_answer_options |
||||
if current_user.support? |
||||
Organisation |
||||
else |
||||
current_user.organisation.housing_providers |
||||
end.pluck(:id, :name).to_h |
||||
end |
||||
end |
@ -0,0 +1,74 @@
|
||||
class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question |
||||
attr_accessor :current_user, :log |
||||
|
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "managing_organisation_id" |
||||
@check_answer_label = "Managing agent" |
||||
@header = "Which organisation manages this letting?" |
||||
@type = "select" |
||||
@answer_options = answer_options |
||||
@page = page |
||||
end |
||||
|
||||
def answer_options |
||||
opts = { "" => "Select an option" } |
||||
return opts unless ActiveRecord::Base.connected? |
||||
return opts unless current_user |
||||
return opts unless log |
||||
|
||||
if current_user.support? |
||||
if log.owning_organisation.holds_own_stock? |
||||
opts[log.owning_organisation.id] = "#{log.owning_organisation.name} (Owning organisation)" |
||||
end |
||||
elsif current_user.organisation.holds_own_stock? |
||||
opts[current_user.organisation.id] = "#{current_user.organisation.name} (Your organisation)" |
||||
end |
||||
|
||||
opts.merge(managing_organisations_answer_options) |
||||
end |
||||
|
||||
def displayed_answer_options(log, user) |
||||
@current_user = user |
||||
@log = log |
||||
|
||||
answer_options |
||||
end |
||||
|
||||
def label_from_value(value) |
||||
return unless value |
||||
|
||||
answer_options[value] |
||||
end |
||||
|
||||
def derived? |
||||
true |
||||
end |
||||
|
||||
def hidden_in_check_answers?(_log, user = nil) |
||||
@current_user = user |
||||
|
||||
return false unless @current_user |
||||
return false if @current_user.support? |
||||
|
||||
managing_organisations_answer_options.count < 2 |
||||
end |
||||
|
||||
def enabled |
||||
true |
||||
end |
||||
|
||||
private |
||||
|
||||
def selected_answer_option_is_derived?(_log) |
||||
true |
||||
end |
||||
|
||||
def managing_organisations_answer_options |
||||
if current_user.support? |
||||
log.owning_organisation |
||||
else |
||||
current_user.organisation |
||||
end.managing_agents.pluck(:id, :name).to_h |
||||
end |
||||
end |
@ -0,0 +1,17 @@
|
||||
<%= form_with model: @location, url: scheme_location_deactivate_path(@location), method: "patch", local: true do |f| %> |
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link(href: :back) %> |
||||
<% end %> |
||||
<h1 class="govuk-heading-l"> |
||||
<span class="govuk-caption-l"><%= @location.postcode %></span> |
||||
This change will affect <%= @location.lettings_logs.count %> logs |
||||
</h1> |
||||
<%= govuk_warning_text text: I18n.t("warnings.location.deactivation.review_logs") %> |
||||
<%= f.hidden_field :confirm, value: true %> |
||||
<%= f.hidden_field :deactivation_date, value: @deactivation_date %> |
||||
<%= f.hidden_field :deactivation_date_type, value: @deactivation_date_type %> |
||||
<div class="govuk-button-group"> |
||||
<%= f.govuk_submit "Deactivate this location" %> |
||||
<%= govuk_button_link_to "Cancel", scheme_location_path(@scheme, @location), html: { method: :get }, secondary: true %> |
||||
</div> |
||||
<% end %> |
@ -0,0 +1,32 @@
|
||||
<% title = @location.name %> |
||||
<% content_for :title, title %> |
||||
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link( |
||||
text: "Back", |
||||
href: scheme_locations_path(@scheme), |
||||
) %> |
||||
<% end %> |
||||
|
||||
<%= render partial: "organisations/headings", locals: { main: @location.postcode, sub: @location.name } %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||
<%= govuk_summary_list do |summary_list| %> |
||||
<% display_location_attributes(@location).each do |attr| %> |
||||
<%= summary_list.row do |row| %> |
||||
<% row.key { attr[:name] } %> |
||||
<% row.value { attr[:name].eql?("Status") ? status_tag(attr[:value]) : details_html(attr) } %> |
||||
<% row.action(text: "Change", href: scheme_location_edit_name_path(scheme_id: @scheme.id, location_id: @location.id)) if attr[:edit] %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
</div> |
||||
</div> |
||||
<% if FeatureToggle.location_toggle_enabled? %> |
||||
<% if @location.active? %> |
||||
<%= govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(scheme_id: @scheme.id, location_id: @location.id), warning: true %> |
||||
<% else %> |
||||
<%= govuk_button_link_to "Reactivate this location", scheme_location_reactivate_path(scheme_id: @scheme.id, location_id: @location.id) %> |
||||
<% end %> |
||||
<% end %> |
@ -0,0 +1,39 @@
|
||||
<% title = "#{action.humanize} #{@location.postcode}" %> |
||||
<% content_for :title, title %> |
||||
|
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link( |
||||
text: "Back", |
||||
href: scheme_location_path(@location.scheme, @location), |
||||
) %> |
||||
<% end %> |
||||
|
||||
<%= form_with model: @location, url: scheme_location_new_deactivation_path(scheme_id: @location.scheme.id, location_id: @location.id), method: "patch", local: true do |f| %> |
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<% collection_start_date = FormHandler.instance.current_collection_start_date %> |
||||
<%= f.govuk_error_summary %> |
||||
<%= f.govuk_radio_buttons_fieldset :deactivation_date_type, |
||||
legend: { text: I18n.t("questions.location.deactivation.apply_from") }, |
||||
caption: { text: "Deactivate #{@location.postcode}" }, |
||||
hint: { text: I18n.t("hints.location.deactivation", date: collection_start_date.to_formatted_s(:govuk_date)) } do %> |
||||
<%= govuk_warning_text text: I18n.t("warnings.location.deactivation.existing_logs") %> |
||||
<%= f.govuk_radio_button :deactivation_date_type, |
||||
"default", |
||||
label: { text: "From the start of the current collection period (#{collection_start_date.to_formatted_s(:govuk_date)})" } %> |
||||
|
||||
<%= f.govuk_radio_button :deactivation_date_type, |
||||
"other", |
||||
label: { text: "For tenancies starting after a certain date" }, |
||||
**basic_conditional_html_attributes({ "deactivation_date" => %w[other] }, "location") do %> |
||||
<%= f.govuk_date_field :deactivation_date, |
||||
legend: { text: "Date", size: "m" }, |
||||
hint: { text: "For example, 27 3 2022" }, |
||||
width: 20 %> |
||||
<% end %> |
||||
<% end %> |
||||
|
||||
<%= f.govuk_submit "Continue" %> |
||||
</div> |
||||
</div> |
||||
<% end %> |
@ -0,0 +1,19 @@
|
||||
<% title = "Deactivate #{@scheme.service_name}" %> |
||||
<% content_for :title, title %> |
||||
<%= form_with model: @scheme, url: scheme_deactivate_path(@scheme), method: "patch", local: true do |f| %> |
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link(href: :back) %> |
||||
<% end %> |
||||
<h1 class="govuk-heading-l"> |
||||
<span class="govuk-caption-l"><%= @scheme.service_name %></span> |
||||
This change will affect <%= @scheme.lettings_logs.count %> logs |
||||
</h1> |
||||
<%= govuk_warning_text text: I18n.t("warnings.scheme.deactivation.review_logs") %> |
||||
<%= f.hidden_field :confirm, value: true %> |
||||
<%= f.hidden_field :deactivation_date, value: @deactivation_date %> |
||||
<%= f.hidden_field :deactivation_date_type, value: @deactivation_date_type %> |
||||
<div class="govuk-button-group"> |
||||
<%= f.govuk_submit "Deactivate this scheme" %> |
||||
<%= govuk_button_link_to "Cancel", scheme_details_path(@scheme), html: { method: :get }, secondary: true %> |
||||
</div> |
||||
<% end %> |
@ -0,0 +1,35 @@
|
||||
<% title = "#{action.humanize} #{@scheme.service_name}" %> |
||||
<% content_for :title, title %> |
||||
<% content_for :before_content do %> |
||||
<%= govuk_back_link( |
||||
text: "Back", |
||||
href: scheme_details_path(@scheme), |
||||
) %> |
||||
<% end %> |
||||
<%= form_with model: @scheme, url: scheme_new_deactivation_path(@scheme), method: "patch", local: true do |f| %> |
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<% collection_start_date = FormHandler.instance.current_collection_start_date %> |
||||
<%= f.govuk_error_summary %> |
||||
<%= f.govuk_radio_buttons_fieldset :deactivation_date_type, |
||||
legend: { text: I18n.t("questions.scheme.deactivation.apply_from") }, |
||||
caption: { text: title }, |
||||
hint: { text: I18n.t("hints.scheme.deactivation", date: collection_start_date.to_formatted_s(:govuk_date)) } do %> |
||||
<%= govuk_warning_text text: I18n.t("warnings.scheme.deactivation.existing_logs") %> |
||||
<%= f.govuk_radio_button :deactivation_date_type, |
||||
"default", |
||||
label: { text: "From the start of the current collection period (#{collection_start_date.to_formatted_s(:govuk_date)})" } %> |
||||
<%= f.govuk_radio_button :deactivation_date_type, |
||||
"other", |
||||
label: { text: "For tenancies starting after a certain date" }, |
||||
**basic_conditional_html_attributes({ "deactivation_date" => %w[other] }, "scheme") do %> |
||||
<%= f.govuk_date_field :deactivation_date, |
||||
legend: { text: "Date", size: "m" }, |
||||
hint: { text: "For example, 27 3 2022" }, |
||||
width: 20 %> |
||||
<% end %> |
||||
<% end %> |
||||
<%= f.govuk_submit "Continue" %> |
||||
</div> |
||||
</div> |
||||
<% end %> |
@ -0,0 +1,5 @@
|
||||
class AddDeactivationDateToLocations < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :locations, :deactivation_date, :datetime |
||||
end |
||||
end |
@ -0,0 +1,5 @@
|
||||
class AddDeactivationDateToSchemes < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :schemes, :deactivation_date, :datetime |
||||
end |
||||
end |
@ -0,0 +1,13 @@
|
||||
class ChangeOldVisibleIdType < ActiveRecord::Migration[7.0] |
||||
def up |
||||
change_column :organisations, :old_visible_id, :string |
||||
change_column :schemes, :old_visible_id, :string |
||||
change_column :locations, :old_visible_id, :string |
||||
end |
||||
|
||||
def down |
||||
change_column :organisations, :old_visible_id, :integer |
||||
change_column :schemes, :old_visible_id, :integer |
||||
change_column :locations, :old_visible_id, :integer |
||||
end |
||||
end |
@ -0,0 +1,19 @@
|
||||
<user xmlns="dclg:user"> |
||||
<id>80d9b73aa1c88b6e5c36ee49be9050b923b4a1bb</id> |
||||
<user-name>Jane Doe</user-name> |
||||
<institution>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</institution> |
||||
<user-stamp>1158 1158</user-stamp> |
||||
<active>true</active> |
||||
<user-type>Data Provider</user-type> |
||||
<association-site-id /> |
||||
<e-core-download>false</e-core-download> |
||||
<raw-data-download>false</raw-data-download> |
||||
<licence>false</licence> |
||||
<contact-priority-id>None</contact-priority-id> |
||||
<email>jane.doe@gov.uk</email> |
||||
<password>REDACTED</password> |
||||
<full-name>Jane Doe</full-name> |
||||
<telephone-no>01111 000000</telephone-no> |
||||
<deleted>false</deleted> |
||||
<date-deactivated>2021-09-28Z</date-deactivated> |
||||
</user> |
@ -0,0 +1,27 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe SchemesHelper do |
||||
describe "display_scheme_attributes" do |
||||
let!(:scheme) { FactoryBot.create(:scheme, created_at: Time.zone.local(2022, 8, 8)) } |
||||
|
||||
it "returns correct display attributes" do |
||||
attributes = [ |
||||
{ name: "Scheme code", value: scheme.id_to_display }, |
||||
{ name: "Name", value: scheme.service_name, edit: true }, |
||||
{ name: "Confidential information", value: scheme.sensitive, edit: true }, |
||||
{ name: "Type of scheme", value: scheme.scheme_type }, |
||||
{ name: "Registered under Care Standards Act 2000", value: scheme.registered_under_care_act }, |
||||
{ name: "Housing stock owned by", value: scheme.owning_organisation.name, edit: true }, |
||||
{ name: "Support services provided by", value: scheme.arrangement_type }, |
||||
{ name: "Primary client group", value: scheme.primary_client_group }, |
||||
{ name: "Has another client group", value: scheme.has_other_client_group }, |
||||
{ name: "Secondary client group", value: scheme.secondary_client_group }, |
||||
{ name: "Level of support given", value: scheme.support_type }, |
||||
{ name: "Intended length of stay", value: scheme.intended_stay }, |
||||
{ name: "Availability", value: "Available from 8 August 2022" }, |
||||
{ name: "Status", value: :active }, |
||||
] |
||||
expect(display_scheme_attributes(scheme)).to eq(attributes) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,55 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Pages::CreatedBy, 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) } |
||||
let(:form) { instance_double(Form) } |
||||
let(:lettings_log) { instance_double(LettingsLog) } |
||||
|
||||
describe "#routed_to?" do |
||||
context "when nil" do |
||||
it "is not shown" do |
||||
expect(page.routed_to?(nil, nil)).to eq(false) |
||||
end |
||||
end |
||||
|
||||
context "when support" do |
||||
it "is shown" do |
||||
expect(page.routed_to?(nil, create(:user, :support))).to eq(true) |
||||
end |
||||
end |
||||
|
||||
context "when not support" do |
||||
it "is not shown" do |
||||
expect(page.routed_to?(nil, create(:user, :data_coordinator))).to eq(false) |
||||
end |
||||
end |
||||
end |
||||
|
||||
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[created_by_id]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("created_by") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("") |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to eq("") |
||||
end |
||||
|
||||
it "has the correct depends_on" do |
||||
expect(page.depends_on).to be nil |
||||
end |
||||
end |
@ -0,0 +1,128 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Pages::HousingProvider, 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) } |
||||
let(:form) { instance_double(Form) } |
||||
|
||||
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("housing_provider") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("") |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to eq("") |
||||
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 |
||||
|
||||
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 holds own stock" do |
||||
let(:user) do |
||||
create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) |
||||
end |
||||
|
||||
context "with 0 housing_providers" 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).from(nil) |
||||
end |
||||
end |
||||
|
||||
context "with >1 housing_providers" do |
||||
before do |
||||
create(:organisation_relationship, :owning, child_organisation: user.organisation) |
||||
create(:organisation_relationship, :owning, 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 |
||||
|
||||
context "with 1 housing_providers" do |
||||
let(:housing_provider) { create(:organisation) } |
||||
|
||||
before do |
||||
create( |
||||
:organisation_relationship, |
||||
:owning, |
||||
child_organisation: user.organisation, |
||||
parent_organisation: housing_provider, |
||||
) |
||||
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(housing_provider) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,130 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Pages::ManagingOrganisation, 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) } |
||||
let(:form) { instance_double(Form) } |
||||
|
||||
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[managing_organisation_id]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("managing_organisation") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("") |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to eq("") |
||||
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) } |
||||
let(:organisation) { create(:organisation) } |
||||
|
||||
context "when user nil" do |
||||
it "is not shown" do |
||||
expect(page.routed_to?(log, nil)).to eq(false) |
||||
end |
||||
|
||||
it "does not update managing_organisation_id" do |
||||
expect { page.routed_to?(log, nil) }.not_to change(log.reload, :managing_organisation) |
||||
end |
||||
end |
||||
|
||||
context "when support" do |
||||
let(:organisation) { create(:organisation) } |
||||
let(:user) { create(:user, :support, organisation:) } |
||||
|
||||
it "is shown" do |
||||
expect(page.routed_to?(log, user)).to eq(true) |
||||
end |
||||
|
||||
it "does not update managing_organisation_id" do |
||||
expect { page.routed_to?(log, user) }.not_to change(log.reload, :managing_organisation) |
||||
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 |
||||
|
||||
it "is shown" do |
||||
expect(page.routed_to?(log, user)).to eq(true) |
||||
end |
||||
|
||||
it "does not update managing_organisation_id" do |
||||
expect { page.routed_to?(log, user) }.not_to change(log.reload, :managing_organisation) |
||||
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 managing_agents" do |
||||
it "is not shown" do |
||||
expect(page.routed_to?(log, user)).to eq(false) |
||||
end |
||||
|
||||
it "does not update managing_organisation_id" do |
||||
expect { page.routed_to?(log, user) }.not_to change(log.reload, :managing_organisation) |
||||
end |
||||
end |
||||
|
||||
context "with >1 managing_agents" do |
||||
before do |
||||
create(:organisation_relationship, :managing, parent_organisation: user.organisation) |
||||
create(:organisation_relationship, :managing, parent_organisation: user.organisation) |
||||
end |
||||
|
||||
it "is shown" do |
||||
expect(page.routed_to?(log, user)).to eq(true) |
||||
end |
||||
|
||||
it "does not update managing_organisation_id" do |
||||
expect { page.routed_to?(log, user) }.not_to change(log.reload, :managing_organisation) |
||||
end |
||||
end |
||||
|
||||
context "with 1 managing_agents" do |
||||
let(:managing_agent) { create(:organisation) } |
||||
|
||||
before do |
||||
create( |
||||
:organisation_relationship, |
||||
:managing, |
||||
child_organisation: managing_agent, |
||||
parent_organisation: user.organisation, |
||||
) |
||||
end |
||||
|
||||
it "is not shown" do |
||||
expect(page.routed_to?(log, user)).to eq(false) |
||||
end |
||||
|
||||
it "updates managing_organisation_id" do |
||||
expect { page.routed_to?(log, user) }.to change(log.reload, :managing_organisation).to(managing_agent) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,82 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
let(:form) { instance_double(Form) } |
||||
let(:user_1) { FactoryBot.create(:user, name: "first user") } |
||||
let(:user_2) { FactoryBot.create(:user, name: "second user") } |
||||
let!(:expected_answer_options) do |
||||
{ |
||||
"" => "Select an option", |
||||
user_1.id => "#{user_1.name} (#{user_1.email})", |
||||
user_2.id => "#{user_2.name} (#{user_2.email})", |
||||
} |
||||
end |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("created_by_id") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Which user are you creating this log for?") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Log owner") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("select") |
||||
end |
||||
|
||||
it "has the correct hint_text" do |
||||
expect(question.hint_text).to eq("") |
||||
end |
||||
|
||||
it "has the correct answer options" do |
||||
expect(question.answer_options).to eq(expected_answer_options) |
||||
end |
||||
|
||||
it "is marked as derived" do |
||||
expect(question.derived?).to be true |
||||
end |
||||
|
||||
context "when the current user is support" do |
||||
let(:support_user) { FactoryBot.build(:user, :support) } |
||||
|
||||
it "is shown in check answers" do |
||||
expect(question.hidden_in_check_answers?(nil, support_user)).to be false |
||||
end |
||||
end |
||||
|
||||
context "when the current user is not support" do |
||||
let(:user) { FactoryBot.build(:user) } |
||||
|
||||
it "is not shown in check answers" do |
||||
expect(question.hidden_in_check_answers?(nil, user)).to be true |
||||
end |
||||
end |
||||
|
||||
context "when the owning organisation is already set" do |
||||
let(:lettings_log) { FactoryBot.create(:lettings_log, owning_organisation: user_2.organisation) } |
||||
let(:expected_answer_options) do |
||||
{ |
||||
"" => "Select an option", |
||||
user_2.id => "#{user_2.name} (#{user_2.email})", |
||||
} |
||||
end |
||||
|
||||
it "only displays users that belong to that organisation" do |
||||
expect(question.displayed_answer_options(lettings_log)).to eq(expected_answer_options) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,117 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
let(:form) { instance_double(Form) } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("owning_organisation_id") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Which organisation owns this property?") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Housing provider") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("select") |
||||
end |
||||
|
||||
it "has the correct hint_text" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
describe "answer options" do |
||||
let(:options) { { "" => "Select an option" } } |
||||
|
||||
context "when current_user nil" do |
||||
it "shows default options" do |
||||
expect(question.answer_options).to eq(options) |
||||
end |
||||
end |
||||
|
||||
context "when user not support and owns own stock" do |
||||
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) } |
||||
let(:options) do |
||||
{ |
||||
"" => "Select an option", |
||||
user.organisation.id => "#{user.organisation.name} (Your organisation)", |
||||
} |
||||
end |
||||
|
||||
before do |
||||
question.current_user = user |
||||
end |
||||
|
||||
it "shows housing providers with own org at the top" do |
||||
expect(question.answer_options).to eq(options) |
||||
end |
||||
end |
||||
|
||||
context "when user support" do |
||||
before do |
||||
question.current_user = create(:user, :support) |
||||
end |
||||
|
||||
let(:expected_opts) do |
||||
Organisation.all.each_with_object(options) do |organisation, hsh| |
||||
hsh[organisation.id] = organisation.name |
||||
hsh |
||||
end |
||||
end |
||||
|
||||
it "shows all orgs" do |
||||
expect(question.answer_options).to eq(expected_opts) |
||||
end |
||||
end |
||||
end |
||||
|
||||
it "is marked as derived" do |
||||
expect(question.derived?).to be true |
||||
end |
||||
|
||||
describe "#hidden_in_check_answers?" do |
||||
context "when housing providers < 2" do |
||||
context "when not support user" do |
||||
let(:user) { create(:user) } |
||||
|
||||
it "is hidden in check answers" do |
||||
expect(question.hidden_in_check_answers?(nil, user)).to be true |
||||
end |
||||
end |
||||
|
||||
context "when support" do |
||||
let(:user) { create(:user, :support) } |
||||
|
||||
it "is not hiddes in check answers" do |
||||
expect(question.hidden_in_check_answers?(nil, user)).to be false |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when housing providers >= 2" do |
||||
let(:user) { create(:user) } |
||||
|
||||
before do |
||||
create(:organisation_relationship, :owning, child_organisation: user.organisation) |
||||
create(:organisation_relationship, :owning, child_organisation: user.organisation) |
||||
end |
||||
|
||||
it "is not hidden in check answers" do |
||||
expect(question.hidden_in_check_answers?(nil, user)).to be false |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,155 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:subsection) { instance_double(Form::Subsection) } |
||||
let(:form) { instance_double(Form) } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("managing_organisation_id") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Which organisation manages this letting?") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Managing agent") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("select") |
||||
end |
||||
|
||||
it "has the correct hint_text" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
describe "#displayed_answer_options" do |
||||
let(:options) { { "" => "Select an option" } } |
||||
|
||||
context "when current_user nil" do |
||||
let(:log) { create(:lettings_log) } |
||||
|
||||
it "shows default options" do |
||||
expect(question.displayed_answer_options(log, nil)).to eq(options) |
||||
end |
||||
end |
||||
|
||||
context "when log nil" do |
||||
let(:user) { create(:user) } |
||||
|
||||
it "shows default options" do |
||||
expect(question.displayed_answer_options(nil, user)).to eq(options) |
||||
end |
||||
end |
||||
|
||||
context "when user not support and owns own stock" do |
||||
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) } |
||||
|
||||
let(:log) { create(:lettings_log) } |
||||
let!(:org_rel1) { create(:organisation_relationship, :managing, parent_organisation: user.organisation) } |
||||
let!(:org_rel2) { create(:organisation_relationship, :managing, parent_organisation: user.organisation) } |
||||
|
||||
let(:options) do |
||||
{ |
||||
"" => "Select an option", |
||||
user.organisation.id => "#{user.organisation.name} (Your organisation)", |
||||
org_rel1.child_organisation.id => org_rel1.child_organisation.name, |
||||
org_rel2.child_organisation.id => org_rel2.child_organisation.name, |
||||
} |
||||
end |
||||
|
||||
it "shows managing agents with own org at the top" do |
||||
expect(question.displayed_answer_options(log, user)).to eq(options) |
||||
end |
||||
end |
||||
|
||||
context "when support user and org does not own own stock" do |
||||
let(:user) { create(:user, :support) } |
||||
let(:log_owning_org) { create(:organisation, holds_own_stock: false) } |
||||
let(:log) { create(:lettings_log, owning_organisation: log_owning_org) } |
||||
let!(:org_rel1) { create(:organisation_relationship, :managing, parent_organisation: log_owning_org) } |
||||
let!(:org_rel2) { create(:organisation_relationship, :managing, parent_organisation: log_owning_org) } |
||||
|
||||
let(:options) do |
||||
{ |
||||
"" => "Select an option", |
||||
org_rel1.child_organisation.id => org_rel1.child_organisation.name, |
||||
org_rel2.child_organisation.id => org_rel2.child_organisation.name, |
||||
} |
||||
end |
||||
|
||||
it "shows owning org managing agents with hint" do |
||||
expect(question.displayed_answer_options(log, user)).to eq(options) |
||||
end |
||||
end |
||||
|
||||
context "when support user and org does own stock" do |
||||
let(:user) { create(:user, :support) } |
||||
let(:log_owning_org) { create(:organisation, holds_own_stock: true) } |
||||
let(:log) { create(:lettings_log, owning_organisation: log_owning_org) } |
||||
let!(:org_rel1) { create(:organisation_relationship, :managing, parent_organisation: log_owning_org) } |
||||
let!(:org_rel2) { create(:organisation_relationship, :managing, parent_organisation: log_owning_org) } |
||||
|
||||
let(:options) do |
||||
{ |
||||
"" => "Select an option", |
||||
log_owning_org.id => "#{log_owning_org.name} (Owning organisation)", |
||||
org_rel1.child_organisation.id => org_rel1.child_organisation.name, |
||||
org_rel2.child_organisation.id => org_rel2.child_organisation.name, |
||||
} |
||||
end |
||||
|
||||
it "shows owning org managing agents |
||||
" do |
||||
expect(question.displayed_answer_options(log, user)).to eq(options) |
||||
end |
||||
end |
||||
end |
||||
|
||||
it "is marked as derived" do |
||||
expect(question.derived?).to be true |
||||
end |
||||
|
||||
describe "#hidden_in_check_answers?" do |
||||
context "when housing providers < 2" do |
||||
context "when not support user" do |
||||
let(:user) { create(:user) } |
||||
|
||||
it "is hidden in check answers" do |
||||
expect(question.hidden_in_check_answers?(nil, user)).to be true |
||||
end |
||||
end |
||||
|
||||
context "when support" do |
||||
let(:user) { create(:user, :support) } |
||||
|
||||
it "is not hiddes in check answers" do |
||||
expect(question.hidden_in_check_answers?(nil, user)).to be false |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when managing agents >= 2" do |
||||
let(:user) { create(:user) } |
||||
|
||||
before do |
||||
create(:organisation_relationship, :managing, parent_organisation: user.organisation) |
||||
create(:organisation_relationship, :managing, parent_organisation: user.organisation) |
||||
end |
||||
|
||||
it "is not hidden in check answers" do |
||||
expect(question.hidden_in_check_answers?(nil, user)).to be false |
||||
end |
||||
end |
||||
end |
||||
end |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue