From 0c5dea5b4454dec9b721fbad4e52d8f4b1a0fd5e Mon Sep 17 00:00:00 2001 From: JS Date: Mon, 26 Sep 2022 08:32:15 +0100 Subject: [PATCH] [CLDC-1484] Add buyer 1 questions to Sales form --- app/models/form/sales/questions/age1.rb | 11 ++++ .../form/sales/questions/buyer1_age_known.rb | 20 ++++++++ .../20220922084008_add_age1_to_sales_logs.rb | 6 +++ db/schema.rb | 2 + spec/models/form/sales/questions/age1_spec.rb | 41 +++++++++++++++ .../sales/questions/buyer1_age_known_spec.rb | 50 +++++++++++++++++++ 6 files changed, 130 insertions(+) create mode 100644 app/models/form/sales/questions/age1.rb create mode 100644 app/models/form/sales/questions/buyer1_age_known.rb create mode 100644 db/migrate/20220922084008_add_age1_to_sales_logs.rb create mode 100644 spec/models/form/sales/questions/age1_spec.rb create mode 100644 spec/models/form/sales/questions/buyer1_age_known_spec.rb diff --git a/app/models/form/sales/questions/age1.rb b/app/models/form/sales/questions/age1.rb new file mode 100644 index 000000000..390fba3a6 --- /dev/null +++ b/app/models/form/sales/questions/age1.rb @@ -0,0 +1,11 @@ +class Form::Sales::Questions::Age1 < ::Form::Question + def initialize(id, hsh, page) + super + @id = "age1" + @check_answer_label = "Lead buyer’s age" + @header = "Age" + @type = "numeric" + @page = page + @width = 2 + end +end diff --git a/app/models/form/sales/questions/buyer1_age_known.rb b/app/models/form/sales/questions/buyer1_age_known.rb new file mode 100644 index 000000000..234cb6be8 --- /dev/null +++ b/app/models/form/sales/questions/buyer1_age_known.rb @@ -0,0 +1,20 @@ +class Form::Sales::Questions::Buyer1AgeKnown < ::Form::Question + def initialize(id, hsh, page) + super + @id = "age1_known" + @check_answer_label = "Buyer 1's age" + @header = "Do you know buyer 1's age?" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @page = page + @hint_text = "Buyer 1 is the person in the household who does the most paid work. If it's a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest." + @conditional_for = { + "age1" => [0], + } + end + + ANSWER_OPTIONS = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }.freeze +end diff --git a/db/migrate/20220922084008_add_age1_to_sales_logs.rb b/db/migrate/20220922084008_add_age1_to_sales_logs.rb new file mode 100644 index 000000000..83aee8a3a --- /dev/null +++ b/db/migrate/20220922084008_add_age1_to_sales_logs.rb @@ -0,0 +1,6 @@ +class AddAge1ToSalesLogs < ActiveRecord::Migration[7.0] + def change + add_column :sales_logs, :age1, :integer + add_column :sales_logs, :age1_known, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 27b896016..720018e19 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -336,6 +336,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_23_093628) do t.integer "beds" t.integer "jointmore" t.integer "jointpur" + t.integer "age1" + t.integer "age1_known" 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/models/form/sales/questions/age1_spec.rb b/spec/models/form/sales/questions/age1_spec.rb new file mode 100644 index 000000000..7739a123f --- /dev/null +++ b/spec/models/form/sales/questions/age1_spec.rb @@ -0,0 +1,41 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Age1, 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("age1") + end + + it "has the correct header" do + expect(question.header).to eq("Age") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Lead buyer’s age") + 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 the correct width" do + expect(question.width).to eq(2) + end +end diff --git a/spec/models/form/sales/questions/buyer1_age_known_spec.rb b/spec/models/form/sales/questions/buyer1_age_known_spec.rb new file mode 100644 index 000000000..9a585cdb0 --- /dev/null +++ b/spec/models/form/sales/questions/buyer1_age_known_spec.rb @@ -0,0 +1,50 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Buyer1AgeKnown, 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("age1_known") + end + + it "has the correct header" do + expect(question.header).to eq("Do you know buyer 1's age?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer 1's age") + 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({ + "age1" => [0], + }) + end + + it "has the correct hint" do + expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it's a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.") + end +end