diff --git a/.github/workflows/review_pipeline.yml b/.github/workflows/review_pipeline.yml
index 90d7b3b44..603a8315c 100644
--- a/.github/workflows/review_pipeline.yml
+++ b/.github/workflows/review_pipeline.yml
@@ -1,5 +1,7 @@
name: Review app pipeline
+concurrency: ${{ github.workflow }}-${{ github.event.pull_request.number }}
+
on:
pull_request:
types:
@@ -143,6 +145,14 @@ jobs:
run: |
cf bind-service $APP_NAME $SERVICE_NAME --wait
+ - name: Bind S3 buckets services
+ env:
+ APP_NAME: dluhc-core-review-${{ github.event.pull_request.number }}
+ run: |
+ cf bind-service $APP_NAME dluhc-core-review-csv-bucket --wait
+ cf bind-service $APP_NAME dluhc-core-review-export-bucket --wait
+ cf bind-service $APP_NAME dluhc-core-review-import-bucket --wait
+
- name: Start review app
env:
APP_NAME: dluhc-core-review-${{ github.event.pull_request.number }}
diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb
index f06d9b89f..394d3cf4d 100644
--- a/app/controllers/locations_controller.rb
+++ b/app/controllers/locations_controller.rb
@@ -178,8 +178,13 @@ class LocationsController < ApplicationController
end
def deactivate_confirm
- @deactivation_date = params[:deactivation_date]
- @deactivation_date_type = params[:deactivation_date_type]
+ @affected_logs = @location.lettings_logs.filter_by_before_startdate(params[:deactivation_date])
+ if @affected_logs.count.zero?
+ deactivate
+ else
+ @deactivation_date = params[:deactivation_date]
+ @deactivation_date_type = params[:deactivation_date_type]
+ end
end
def deactivate
diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb
index 415db5c7a..389446b7f 100644
--- a/app/controllers/schemes_controller.rb
+++ b/app/controllers/schemes_controller.rb
@@ -9,7 +9,7 @@ class SchemesController < ApplicationController
def index
redirect_to schemes_organisation_path(current_user.organisation) unless current_user.support?
- all_schemes = Scheme.all.order("service_name ASC")
+ all_schemes = Scheme.order(confirmed: :asc, service_name: :asc)
@pagy, @schemes = pagy(filtered_collection(all_schemes, search_term))
@searched = search_term.presence
@@ -39,8 +39,13 @@ class SchemesController < ApplicationController
end
def deactivate_confirm
- @deactivation_date = params[:deactivation_date]
- @deactivation_date_type = params[:deactivation_date_type]
+ @affected_logs = @scheme.lettings_logs.filter_by_before_startdate(params[:deactivation_date])
+ if @affected_logs.count.zero?
+ deactivate
+ else
+ @deactivation_date = params[:deactivation_date]
+ @deactivation_date_type = params[:deactivation_date_type]
+ end
end
def deactivate
diff --git a/app/models/form/sales/pages/buyer1_mortgage.rb b/app/models/form/sales/pages/buyer1_mortgage.rb
new file mode 100644
index 000000000..e17e9124b
--- /dev/null
+++ b/app/models/form/sales/pages/buyer1_mortgage.rb
@@ -0,0 +1,15 @@
+class Form::Sales::Pages::Buyer1Mortgage < ::Form::Page
+ def initialize(id, hsh, subsection)
+ super
+ @id = "buyer_1_mortgage"
+ @header = ""
+ @description = ""
+ @subsection = subsection
+ end
+
+ def questions
+ @questions ||= [
+ Form::Sales::Questions::Buyer1Mortgage.new(nil, nil, self),
+ ]
+ end
+end
diff --git a/app/models/form/sales/pages/buyer2_income.rb b/app/models/form/sales/pages/buyer2_income.rb
new file mode 100644
index 000000000..207b6ec46
--- /dev/null
+++ b/app/models/form/sales/pages/buyer2_income.rb
@@ -0,0 +1,19 @@
+class Form::Sales::Pages::Buyer2Income < ::Form::Page
+ def initialize(id, hsh, subsection)
+ super
+ @id = "buyer_2_income"
+ @header = ""
+ @description = ""
+ @subsection = subsection
+ @depends_on = [{
+ "jointpur" => 1,
+ }]
+ end
+
+ def questions
+ @questions ||= [
+ Form::Sales::Questions::Buyer2IncomeKnown.new(nil, nil, self),
+ Form::Sales::Questions::Buyer2Income.new(nil, nil, self),
+ ]
+ end
+end
diff --git a/app/models/form/sales/questions/buyer1_mortgage.rb b/app/models/form/sales/questions/buyer1_mortgage.rb
new file mode 100644
index 000000000..c524c3495
--- /dev/null
+++ b/app/models/form/sales/questions/buyer1_mortgage.rb
@@ -0,0 +1,16 @@
+class Form::Sales::Questions::Buyer1Mortgage < ::Form::Question
+ def initialize(id, hsh, page)
+ super
+ @id = "inc1mort"
+ @check_answer_label = "Buyer 1's income used for mortgage application"
+ @header = "Was buyer 1's income used for a mortgage application"
+ @type = "radio"
+ @answer_options = ANSWER_OPTIONS
+ @page = page
+ end
+
+ ANSWER_OPTIONS = {
+ "1" => { "value" => "Yes" },
+ "2" => { "value" => "No" },
+ }.freeze
+end
diff --git a/app/models/form/sales/questions/buyer2_income.rb b/app/models/form/sales/questions/buyer2_income.rb
new file mode 100644
index 000000000..4abb306a0
--- /dev/null
+++ b/app/models/form/sales/questions/buyer2_income.rb
@@ -0,0 +1,14 @@
+class Form::Sales::Questions::Buyer2Income < ::Form::Question
+ def initialize(id, hsh, page)
+ super
+ @id = "income2"
+ @check_answer_label = "Buyer 2’s gross annual income"
+ @header = "Buyer 2’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/buyer2_income_known.rb b/app/models/form/sales/questions/buyer2_income_known.rb
new file mode 100644
index 000000000..f0897f6be
--- /dev/null
+++ b/app/models/form/sales/questions/buyer2_income_known.rb
@@ -0,0 +1,21 @@
+class Form::Sales::Questions::Buyer2IncomeKnown < ::Form::Question
+ def initialize(id, hsh, page)
+ super
+ @id = "income2nk"
+ @check_answer_label = "Buyer 2’s gross annual income"
+ @header = "Do you know buyer 2’s annual income?"
+ @type = "radio"
+ @answer_options = ANSWER_OPTIONS
+ @page = page
+ @guidance_position = GuidancePosition::BOTTOM
+ @guidance_partial = "what_counts_as_income_sales"
+ @conditional_for = {
+ "income2" => [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
index c2c4082fd..eb5c1a7f5 100644
--- a/app/models/form/sales/sections/finances.rb
+++ b/app/models/form/sales/sections/finances.rb
@@ -6,7 +6,7 @@ class Form::Sales::Sections::Finances < ::Form::Section
@description = ""
@form = form
@subsections = [
- Form::Sales::Subsections::IncomeBenefitsAndOutgoings.new(nil, nil, self),
+ Form::Sales::Subsections::IncomeBenefitsAndSavings.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
deleted file mode 100644
index 6ec5c6488..000000000
--- a/app/models/form/sales/subsections/income_benefits_and_outgoings.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-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?" => true }]
- end
-
- def pages
- @pages ||= [
- Form::Sales::Pages::Buyer1Income.new(nil, nil, self),
- ]
- end
-end
diff --git a/app/models/form/sales/subsections/income_benefits_and_savings.rb b/app/models/form/sales/subsections/income_benefits_and_savings.rb
new file mode 100644
index 000000000..26ab3310b
--- /dev/null
+++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb
@@ -0,0 +1,17 @@
+class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
+ def initialize(id, hsh, section)
+ super
+ @id = "income_benefits_and_savings"
+ @label = "Income, benefits and savings"
+ @section = section
+ @depends_on = [{ "setup_completed?" => true }]
+ end
+
+ def pages
+ @pages ||= [
+ Form::Sales::Pages::Buyer1Income.new(nil, nil, self),
+ Form::Sales::Pages::Buyer1Mortgage.new(nil, nil, self),
+ Form::Sales::Pages::Buyer2Income.new(nil, nil, self),
+ ]
+ end
+end
diff --git a/app/views/locations/deactivate_confirm.html.erb b/app/views/locations/deactivate_confirm.html.erb
index 47b7bbf60..6748af918 100644
--- a/app/views/locations/deactivate_confirm.html.erb
+++ b/app/views/locations/deactivate_confirm.html.erb
@@ -4,7 +4,7 @@
<% end %>
<%= @location.postcode %>
- This change will affect <%= @location.lettings_logs.count %> logs
+ This change will affect <%= @affected_logs.count %> logs
<%= govuk_warning_text text: I18n.t("warnings.location.deactivate.review_logs") %>
<%= f.hidden_field :confirm, value: true %>
diff --git a/app/views/schemes/deactivate_confirm.html.erb b/app/views/schemes/deactivate_confirm.html.erb
index 92479d93b..b5dda160e 100644
--- a/app/views/schemes/deactivate_confirm.html.erb
+++ b/app/views/schemes/deactivate_confirm.html.erb
@@ -4,7 +4,7 @@
<% end %>
<%= @scheme.service_name %>
- This change will affect <%= @scheme.lettings_logs.count %> logs
+ This change will affect <%= @affected_logs.count %> logs
<%= govuk_warning_text text: I18n.t("warnings.scheme.deactivate.review_logs") %>
<%= f.hidden_field :confirm, value: true %>
diff --git a/db/migrate/20221124102329_add_mortgage1_to_sales.rb b/db/migrate/20221124102329_add_mortgage1_to_sales.rb
new file mode 100644
index 000000000..472ac28b7
--- /dev/null
+++ b/db/migrate/20221124102329_add_mortgage1_to_sales.rb
@@ -0,0 +1,7 @@
+class AddMortgage1ToSales < ActiveRecord::Migration[7.0]
+ def change
+ change_table :sales_logs, bulk: true do |t|
+ t.column :inc1mort, :int
+ end
+ end
+end
diff --git a/db/migrate/20221125142847_add_buyer2_to_sales.rb b/db/migrate/20221125142847_add_buyer2_to_sales.rb
new file mode 100644
index 000000000..883ad44dd
--- /dev/null
+++ b/db/migrate/20221125142847_add_buyer2_to_sales.rb
@@ -0,0 +1,6 @@
+class AddBuyer2ToSales < ActiveRecord::Migration[7.0]
+ change_table :sales_logs, bulk: true do |t|
+ t.column :income2, :int
+ t.column :income2nk, :int
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ff2619f43..e5a4d27e4 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_11_22_130928) do
+ActiveRecord::Schema[7.0].define(version: 2022_11_25_142847) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -374,15 +374,18 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
t.integer "la_known"
t.integer "income1"
t.integer "income1nk"
+ t.integer "details_known_2"
+ t.integer "details_known_3"
+ t.integer "details_known_4"
t.integer "age4"
t.integer "age4_known"
t.integer "age5"
t.integer "age5_known"
t.integer "age6"
t.integer "age6_known"
- t.integer "details_known_2"
- t.integer "details_known_3"
- t.integer "details_known_4"
+ t.integer "inc1mort"
+ t.integer "income2"
+ t.integer "income2nk"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"
diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb
index 8e37581c5..e55287d67 100644
--- a/spec/factories/sales_log.rb
+++ b/spec/factories/sales_log.rb
@@ -52,6 +52,9 @@ FactoryBot.define do
age6 { 40 }
income1nk { 0 }
income1 { 10_000 }
+ inc1mort { 1 }
+ income2nk { 0 }
+ income2 { 10_000 }
la_known { "1" }
la { "E09000003" }
end
diff --git a/spec/models/form/sales/pages/buyer1_mortgage_spec.rb b/spec/models/form/sales/pages/buyer1_mortgage_spec.rb
new file mode 100644
index 000000000..d3aa2e1bb
--- /dev/null
+++ b/spec/models/form/sales/pages/buyer1_mortgage_spec.rb
@@ -0,0 +1,33 @@
+require "rails_helper"
+
+RSpec.describe Form::Sales::Pages::Buyer1Mortgage, 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) }
+
+ 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[inc1mort])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq("buyer_1_mortgage")
+ 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 correct depends_on" do
+ expect(page.depends_on).to be_nil
+ end
+end
diff --git a/spec/models/form/sales/pages/buyer2_income_spec.rb b/spec/models/form/sales/pages/buyer2_income_spec.rb
new file mode 100644
index 000000000..0450ceed1
--- /dev/null
+++ b/spec/models/form/sales/pages/buyer2_income_spec.rb
@@ -0,0 +1,33 @@
+require "rails_helper"
+
+RSpec.describe Form::Sales::Pages::Buyer2Income, 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) }
+
+ 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[income2nk income2])
+ end
+
+ it "has the correct id" do
+ expect(page.id).to eq("buyer_2_income")
+ 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 correct depends_on" do
+ expect(page.depends_on).to eq([{ "jointpur" => 1 }])
+ end
+end
diff --git a/spec/models/form/sales/questions/buyer1_mortgage_spec.rb b/spec/models/form/sales/questions/buyer1_mortgage_spec.rb
new file mode 100644
index 000000000..0e5f49117
--- /dev/null
+++ b/spec/models/form/sales/questions/buyer1_mortgage_spec.rb
@@ -0,0 +1,40 @@
+require "rails_helper"
+
+RSpec.describe Form::Sales::Questions::Buyer1Mortgage, 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) }
+
+ it "has correct page" do
+ expect(question.page).to eq(page)
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("inc1mort")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Was buyer 1's income used for a mortgage application")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Buyer 1's income used for mortgage application")
+ end
+
+ it "has the correct type" do
+ expect(question.type).to eq("radio")
+ end
+
+ it "is not marked as derived" do
+ expect(question.derived?).to be false
+ end
+
+ it "has the correct answer_options" do
+ expect(question.answer_options).to eq({
+ "1" => { "value" => "Yes" },
+ "2" => { "value" => "No" },
+ })
+ end
+end
diff --git a/spec/models/form/sales/questions/buyer2_income_known_spec.rb b/spec/models/form/sales/questions/buyer2_income_known_spec.rb
new file mode 100644
index 000000000..06e7afc3e
--- /dev/null
+++ b/spec/models/form/sales/questions/buyer2_income_known_spec.rb
@@ -0,0 +1,55 @@
+require "rails_helper"
+
+RSpec.describe Form::Sales::Questions::Buyer2IncomeKnown, 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) }
+
+ it "has correct page" do
+ expect(question.page).to eq(page)
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("income2nk")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Do you know buyer 2’s annual income?")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Buyer 2’s gross annual income")
+ end
+
+ it "has the correct type" do
+ expect(question.type).to eq("radio")
+ end
+
+ it "is not marked as derived" do
+ expect(question.derived?).to be false
+ end
+
+ it "has the correct answer_options" do
+ expect(question.answer_options).to eq({
+ "0" => { "value" => "Yes" },
+ "1" => { "value" => "No" },
+ })
+ end
+
+ it "has correct conditional for" do
+ expect(question.conditional_for).to eq({
+ "income2" => [0],
+ })
+ end
+
+ it "has the correct guidance_partial" do
+ expect(question.guidance_partial).to eq("what_counts_as_income_sales")
+ end
+
+ it "has the correct guidance position", :aggregate_failures do
+ expect(question.bottom_guidance?).to eq(true)
+ expect(question.top_guidance?).to eq(false)
+ end
+end
diff --git a/spec/models/form/sales/questions/buyer2_income_spec.rb b/spec/models/form/sales/questions/buyer2_income_spec.rb
new file mode 100644
index 000000000..b7828918a
--- /dev/null
+++ b/spec/models/form/sales/questions/buyer2_income_spec.rb
@@ -0,0 +1,53 @@
+require "rails_helper"
+
+RSpec.describe Form::Sales::Questions::Buyer2Income, 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) }
+
+ it "has correct page" do
+ expect(question.page).to eq(page)
+ end
+
+ it "has the correct id" do
+ expect(question.id).to eq("income2")
+ end
+
+ it "has the correct header" do
+ expect(question.header).to eq("Buyer 2’s gross annual income")
+ end
+
+ it "has the correct check_answer_label" do
+ expect(question.check_answer_label).to eq("Buyer 2’s gross annual income")
+ end
+
+ it "has the correct type" do
+ expect(question.type).to eq("numeric")
+ end
+
+ it "is not marked as derived" do
+ expect(question.derived?).to be false
+ end
+
+ it "has the correct hint" do
+ expect(question.hint_text).to be_nil
+ end
+
+ it "has correct width" do
+ expect(question.width).to eq(5)
+ end
+
+ it "has correct step" do
+ expect(question.step).to eq(1)
+ end
+
+ it "has correct prefix" do
+ expect(question.prefix).to eq("£")
+ end
+
+ it "has correct min" do
+ expect(question.min).to eq(0)
+ end
+end
diff --git a/spec/models/form/sales/sections/finances_spec.rb b/spec/models/form/sales/sections/finances_spec.rb
index 4797f6b4e..6c2f63ded 100644
--- a/spec/models/form/sales/sections/finances_spec.rb
+++ b/spec/models/form/sales/sections/finances_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe Form::Sales::Sections::Finances, type: :model do
it "has correct subsections" do
expect(section.subsections.map(&:id)).to eq(
%w[
- income_benefits_and_outgoings
+ income_benefits_and_savings
],
)
end
diff --git a/spec/models/form/sales/subsections/income_benefits_and_outgoings_spec.rb b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
similarity index 71%
rename from spec/models/form/sales/subsections/income_benefits_and_outgoings_spec.rb
rename to spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
index 01028b0a8..bea0fe88d 100644
--- a/spec/models/form/sales/subsections/income_benefits_and_outgoings_spec.rb
+++ b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
@@ -1,6 +1,6 @@
require "rails_helper"
-RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndOutgoings, type: :model do
+RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model do
subject(:subsection) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil }
@@ -15,16 +15,18 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndOutgoings, type: :mode
expect(subsection.pages.map(&:id)).to eq(
%w[
buyer_1_income
+ buyer_1_mortgage
+ buyer_2_income
],
)
end
it "has the correct id" do
- expect(subsection.id).to eq("income_benefits_and_outgoings")
+ expect(subsection.id).to eq("income_benefits_and_savings")
end
it "has the correct label" do
- expect(subsection.label).to eq("Income, benefits and outgoings")
+ expect(subsection.label).to eq("Income, benefits and savings")
end
it "has correct depends on" do
diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb
index e0ef853ae..6a335e232 100644
--- a/spec/models/form_handler_spec.rb
+++ b/spec/models/form_handler_spec.rb
@@ -61,14 +61,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
- expect(form.pages.count).to eq(44)
+ expect(form.pages.count).to eq(46)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
- expect(form.pages.count).to eq(44)
+ expect(form.pages.count).to eq(46)
expect(form.name).to eq("2021_2022_sales")
end
end
diff --git a/spec/models/scheme_spec.rb b/spec/models/scheme_spec.rb
index 58d0a8da8..43a4112d4 100644
--- a/spec/models/scheme_spec.rb
+++ b/spec/models/scheme_spec.rb
@@ -175,4 +175,19 @@ RSpec.describe Scheme, type: :model do
end
end
end
+
+ describe "all schemes" do
+ before do
+ FactoryBot.create_list(:scheme, 4)
+ FactoryBot.create_list(:scheme, 3, confirmed: false)
+ end
+
+ it "can sort the schemes by status" do
+ all_schemes = described_class.all.order(confirmed: :asc, service_name: :asc)
+ expect(all_schemes.count).to eq(7)
+ expect(all_schemes[0].status).to eq(:incomplete)
+ expect(all_schemes[1].status).to eq(:incomplete)
+ expect(all_schemes[2].status).to eq(:incomplete)
+ end
+ end
end
diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb
index 237149f7d..b1cffd3bf 100644
--- a/spec/requests/locations_controller_spec.rb
+++ b/spec/requests/locations_controller_spec.rb
@@ -1243,11 +1243,13 @@ RSpec.describe LocationsController, type: :request do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) }
let(:startdate) { Time.utc(2022, 10, 11) }
let(:add_deactivations) { nil }
+ let(:setup_locations) { nil }
before do
Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user
add_deactivations
+ setup_locations
location.save!
patch "/schemes/#{scheme.id}/locations/#{location.id}/new-deactivation", params:
end
@@ -1259,20 +1261,52 @@ RSpec.describe LocationsController, type: :request do
context "with default date" do
let(:params) { { location_deactivation_period: { deactivation_date_type: "default", deactivation_date: } } }
- it "redirects to the confirmation page" do
- follow_redirect!
- expect(response).to have_http_status(:ok)
- expect(page).to have_content("This change will affect #{location.lettings_logs.count} logs")
+ context "and affected logs" do
+ it "redirects to the confirmation page" do
+ follow_redirect!
+ expect(response).to have_http_status(:ok)
+ expect(page).to have_content("This change will affect 1 logs")
+ end
+ end
+
+ context "and no affected logs" do
+ let(:setup_locations) { location.lettings_logs.update(location: nil) }
+
+ it "redirects to the location page and updates the deactivation period" do
+ follow_redirect!
+ follow_redirect!
+ expect(response).to have_http_status(:ok)
+ expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
+ location.reload
+ expect(location.location_deactivation_periods.count).to eq(1)
+ expect(location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2022, 4, 1))
+ end
end
end
context "with other date" do
let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "10", "deactivation_date(1i)": "2022" } } }
- it "redirects to the confirmation page" do
- follow_redirect!
- expect(response).to have_http_status(:ok)
- expect(page).to have_content("This change will affect #{location.lettings_logs.count} logs")
+ context "and afected logs" do
+ it "redirects to the confirmation page" do
+ follow_redirect!
+ expect(response).to have_http_status(:ok)
+ expect(page).to have_content("This change will affect #{location.lettings_logs.count} logs")
+ end
+ end
+
+ context "and no affected logs" do
+ let(:setup_locations) { location.lettings_logs.update(location: nil) }
+
+ it "redirects to the location page and updates the deactivation period" do
+ follow_redirect!
+ follow_redirect!
+ expect(response).to have_http_status(:ok)
+ expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
+ location.reload
+ expect(location.location_deactivation_periods.count).to eq(1)
+ expect(location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2022, 10, 10))
+ end
end
end
diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb
index ee9cca533..4de927f8f 100644
--- a/spec/requests/schemes_controller_spec.rb
+++ b/spec/requests/schemes_controller_spec.rb
@@ -1772,10 +1772,12 @@ RSpec.describe SchemesController, type: :request do
let(:deactivation_date) { Time.utc(2022, 10, 10) }
let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) }
let(:startdate) { Time.utc(2022, 10, 11) }
+ let(:setup_schemes) { nil }
before do
Timecop.freeze(Time.utc(2022, 10, 10))
sign_in user
+ setup_schemes
patch "/schemes/#{scheme.id}/new-deactivation", params:
end
@@ -1786,20 +1788,54 @@ RSpec.describe SchemesController, type: :request do
context "with default date" do
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "default", deactivation_date: } } }
- it "redirects to the confirmation page" do
- follow_redirect!
- expect(response).to have_http_status(:ok)
- expect(page).to have_content("This change will affect #{scheme.lettings_logs.count} logs")
+ context "and affected logs" do
+ it "redirects to the confirmation page" do
+ follow_redirect!
+ expect(response).to have_http_status(:ok)
+ expect(page).to have_content("This change will affect #{scheme.lettings_logs.count} logs")
+ end
+ end
+
+ context "and no affected logs" do
+ let(:setup_schemes) { scheme.lettings_logs.update(scheme: nil) }
+
+ it "redirects to the location page and updates the deactivation period" do
+ follow_redirect!
+ follow_redirect!
+ follow_redirect!
+ expect(response).to have_http_status(:ok)
+ expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
+ scheme.reload
+ expect(scheme.scheme_deactivation_periods.count).to eq(1)
+ expect(scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2022, 4, 1))
+ end
end
end
context "with other date" do
let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "10", "deactivation_date(1i)": "2022" } } }
- it "redirects to the confirmation page" do
- follow_redirect!
- expect(response).to have_http_status(:ok)
- expect(page).to have_content("This change will affect #{scheme.lettings_logs.count} logs")
+ context "and affected logs" do
+ it "redirects to the confirmation page" do
+ follow_redirect!
+ expect(response).to have_http_status(:ok)
+ expect(page).to have_content("This change will affect #{scheme.lettings_logs.count} logs")
+ end
+ end
+
+ context "and no affected logs" do
+ let(:setup_schemes) { scheme.lettings_logs.update(scheme: nil) }
+
+ it "redirects to the location page and updates the deactivation period" do
+ follow_redirect!
+ follow_redirect!
+ follow_redirect!
+ expect(response).to have_http_status(:ok)
+ expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
+ scheme.reload
+ expect(scheme.scheme_deactivation_periods.count).to eq(1)
+ expect(scheme.scheme_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2022, 10, 10))
+ end
end
end