From 8de3570e88e6f0688edbcc0ea9ad009763f0ac77 Mon Sep 17 00:00:00 2001 From: Jack S <113976590+bibblobcode@users.noreply.github.com> Date: Fri, 25 Nov 2022 11:20:32 +0000 Subject: [PATCH 1/6] [CLDC-1513] Add buyer 1 mortgage question (#1025) * Rename section from outgoings to savings * Fix specs * Add inc1mort column --- .../form/sales/pages/buyer1_mortgage.rb | 15 +++++++ .../form/sales/questions/buyer1_mortgage.rb | 16 ++++++++ app/models/form/sales/sections/finances.rb | 2 +- ...ings.rb => income_benefits_and_savings.rb} | 7 ++-- .../20221124102329_add_mortgage1_to_sales.rb | 7 ++++ db/schema.rb | 3 +- spec/factories/sales_log.rb | 1 + .../form/sales/pages/buyer1_mortgage_spec.rb | 33 +++++++++++++++ .../sales/questions/buyer1_mortgage_spec.rb | 40 +++++++++++++++++++ .../form/sales/sections/finances_spec.rb | 2 +- ...rb => income_benefits_and_savings_spec.rb} | 7 ++-- spec/models/form_handler_spec.rb | 4 +- 12 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 app/models/form/sales/pages/buyer1_mortgage.rb create mode 100644 app/models/form/sales/questions/buyer1_mortgage.rb rename app/models/form/sales/subsections/{income_benefits_and_outgoings.rb => income_benefits_and_savings.rb} (50%) create mode 100644 db/migrate/20221124102329_add_mortgage1_to_sales.rb create mode 100644 spec/models/form/sales/pages/buyer1_mortgage_spec.rb create mode 100644 spec/models/form/sales/questions/buyer1_mortgage_spec.rb rename spec/models/form/sales/subsections/{income_benefits_and_outgoings_spec.rb => income_benefits_and_savings_spec.rb} (73%) 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/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/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_savings.rb similarity index 50% rename from app/models/form/sales/subsections/income_benefits_and_outgoings.rb rename to app/models/form/sales/subsections/income_benefits_and_savings.rb index 6ec5c6488..a9e7080db 100644 --- a/app/models/form/sales/subsections/income_benefits_and_outgoings.rb +++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb @@ -1,8 +1,8 @@ -class Form::Sales::Subsections::IncomeBenefitsAndOutgoings < ::Form::Subsection +class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection def initialize(id, hsh, section) super - @id = "income_benefits_and_outgoings" - @label = "Income, benefits and outgoings" + @id = "income_benefits_and_savings" + @label = "Income, benefits and savings" @section = section @depends_on = [{ "setup_completed?" => true }] end @@ -10,6 +10,7 @@ class Form::Sales::Subsections::IncomeBenefitsAndOutgoings < ::Form::Subsection def pages @pages ||= [ Form::Sales::Pages::Buyer1Income.new(nil, nil, self), + Form::Sales::Pages::Buyer1Mortgage.new(nil, nil, self), ] end end 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/schema.rb b/db/schema.rb index 9df577686..4ceb57dbc 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_24_102329) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -383,6 +383,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do t.integer "age5_known" t.integer "age6" t.integer "age6_known" + t.integer "inc1mort" 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..e6c45a009 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -52,6 +52,7 @@ FactoryBot.define do age6 { 40 } income1nk { 0 } income1 { 10_000 } + inc1mort { 1 } 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/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/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 73% 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..0ebbac6ab 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,17 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndOutgoings, type: :mode expect(subsection.pages.map(&:id)).to eq( %w[ buyer_1_income + buyer_1_mortgage ], ) 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..7db258b53 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(45) 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(45) expect(form.name).to eq("2021_2022_sales") end end From 41c726ce9c8bc0564e3c71c59e38dab09e8459a3 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Fri, 25 Nov 2022 14:22:21 +0000 Subject: [PATCH 2/6] Add a default ordering for schemes (#1030) * Add a default ordering for schemes * Move ordering back to the controller * Update app/controllers/schemes_controller.rb Co-authored-by: James Rose Co-authored-by: James Rose --- app/controllers/schemes_controller.rb | 2 +- spec/models/scheme_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 415db5c7a..a26471ca1 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 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 From 3ea0c80c2402a284533d9bd58dee09293cdfc433 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Fri, 25 Nov 2022 14:38:01 +0000 Subject: [PATCH 3/6] limit review pipeline to single concurrency (#1033) --- .github/workflows/review_pipeline.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/review_pipeline.yml b/.github/workflows/review_pipeline.yml index 90d7b3b44..22f99afde 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: From 464e5f96278c6a9eb744be3cb473bc9627d4a9ef Mon Sep 17 00:00:00 2001 From: Jack S <113976590+bibblobcode@users.noreply.github.com> Date: Fri, 25 Nov 2022 17:11:03 +0000 Subject: [PATCH 4/6] [CLDC-1514] Add buyer 2 income question (#1036) --- app/models/form/sales/pages/buyer2_income.rb | 19 +++++++ .../form/sales/questions/buyer2_income.rb | 14 +++++ .../sales/questions/buyer2_income_known.rb | 21 +++++++ .../income_benefits_and_savings.rb | 1 + .../20221125142847_add_buyer2_to_sales.rb | 6 ++ db/schema.rb | 4 +- spec/factories/sales_log.rb | 2 + .../form/sales/pages/buyer2_income_spec.rb | 33 +++++++++++ .../questions/buyer2_income_known_spec.rb | 55 +++++++++++++++++++ .../sales/questions/buyer2_income_spec.rb | 53 ++++++++++++++++++ .../income_benefits_and_savings_spec.rb | 1 + spec/models/form_handler_spec.rb | 4 +- 12 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 app/models/form/sales/pages/buyer2_income.rb create mode 100644 app/models/form/sales/questions/buyer2_income.rb create mode 100644 app/models/form/sales/questions/buyer2_income_known.rb create mode 100644 db/migrate/20221125142847_add_buyer2_to_sales.rb create mode 100644 spec/models/form/sales/pages/buyer2_income_spec.rb create mode 100644 spec/models/form/sales/questions/buyer2_income_known_spec.rb create mode 100644 spec/models/form/sales/questions/buyer2_income_spec.rb 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/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/subsections/income_benefits_and_savings.rb b/app/models/form/sales/subsections/income_benefits_and_savings.rb index a9e7080db..26ab3310b 100644 --- a/app/models/form/sales/subsections/income_benefits_and_savings.rb +++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb @@ -11,6 +11,7 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection @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/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 4ceb57dbc..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_24_102329) 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" @@ -384,6 +384,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_24_102329) do t.integer "age6" t.integer "age6_known" 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 e6c45a009..e55287d67 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -53,6 +53,8 @@ FactoryBot.define do 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/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/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/subsections/income_benefits_and_savings_spec.rb b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb index 0ebbac6ab..bea0fe88d 100644 --- a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb +++ b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb @@ -16,6 +16,7 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model %w[ buyer_1_income buyer_1_mortgage + buyer_2_income ], ) end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 7db258b53..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(45) + 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(45) + expect(form.pages.count).to eq(46) expect(form.name).to eq("2021_2022_sales") end end From 3a60c4cd02f6dc0e7cc0848be93b5b8fa925aa0c Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 28 Nov 2022 10:46:12 +0000 Subject: [PATCH 5/6] Deactivation does not affect logs (#1018) * Update affected logs count and skip the confirmation page if no logs are affected for locations * Update affected logs count and skip the confirmation page if no logs are affected for schemes * refactor --- app/controllers/locations_controller.rb | 9 +++- app/controllers/schemes_controller.rb | 9 +++- .../locations/deactivate_confirm.html.erb | 2 +- app/views/schemes/deactivate_confirm.html.erb | 2 +- spec/requests/locations_controller_spec.rb | 50 +++++++++++++++--- spec/requests/schemes_controller_spec.rb | 52 ++++++++++++++++--- 6 files changed, 102 insertions(+), 22 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index b3f3ab203..1da3bf5c4 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -38,8 +38,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 a26471ca1..389446b7f 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -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/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/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 From 5bd41fae995ba322f0cd781e09f69943bcac7093 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Tue, 29 Nov 2022 13:39:32 +0000 Subject: [PATCH 6/6] bind S3 buckets for review apps (#1037) --- .github/workflows/review_pipeline.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/review_pipeline.yml b/.github/workflows/review_pipeline.yml index 22f99afde..603a8315c 100644 --- a/.github/workflows/review_pipeline.yml +++ b/.github/workflows/review_pipeline.yml @@ -145,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 }}