Browse Source

Add purchaser code question (#872)

pull/873/head
baarkerlounger 2 years ago committed by GitHub
parent
commit
200b9a2527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      app/models/form/sales/setup/pages/purchaser_code.rb
  2. 11
      app/models/form/sales/setup/questions/purchaser_code.rb
  3. 1
      app/models/form/sales/setup/subsections/setup.rb
  4. 5
      db/migrate/20220915093559_add_purchid.rb
  5. 3
      db/schema.rb
  6. 1
      spec/factories/sales_log.rb
  7. 43
      spec/features/lettings_log_spec.rb
  8. 31
      spec/features/sales_log_spec.rb
  9. 29
      spec/models/form/sales/setup/pages/purchaser_code_spec.rb
  10. 37
      spec/models/form/sales/setup/questions/purchaser_code_spec.rb
  11. 2
      spec/models/form/sales/setup/subsections/setup_spec.rb
  12. 8
      spec/models/form_spec.rb
  13. 2
      spec/requests/sales_logs_controller_spec.rb

15
app/models/form/sales/setup/pages/purchaser_code.rb

@ -0,0 +1,15 @@
class Form::Sales::Setup::Pages::PurchaserCode < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "purchaser_code"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Setup::Questions::PurchaserCode.new(nil, nil, self),
]
end
end

11
app/models/form/sales/setup/questions/purchaser_code.rb

@ -0,0 +1,11 @@
class Form::Sales::Setup::Questions::PurchaserCode < ::Form::Question
def initialize(id, hsh, page)
super
@id = "purchid"
@check_answer_label = "Purchaser code"
@header = "What is the purchaser code?"
@type = "text"
@width = 10
@page = page
end
end

1
app/models/form/sales/setup/subsections/setup.rb

@ -8,6 +8,7 @@ class Form::Sales::Setup::Subsections::Setup < ::Form::Subsection
def pages def pages
@pages ||= [ @pages ||= [
Form::Sales::Setup::Pages::PurchaserCode.new(nil, nil, self),
Form::Sales::Setup::Pages::SaleDate.new(nil, nil, self), Form::Sales::Setup::Pages::SaleDate.new(nil, nil, self),
] ]
end end

5
db/migrate/20220915093559_add_purchid.rb

@ -0,0 +1,5 @@
class AddPurchid < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :purchid, :string
end
end

3
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_09_02_082245) do ActiveRecord::Schema[7.0].define(version: 2022_09_15_093559) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -321,6 +321,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_02_082245) do
t.bigint "owning_organisation_id" t.bigint "owning_organisation_id"
t.bigint "managing_organisation_id" t.bigint "managing_organisation_id"
t.bigint "created_by_id" t.bigint "created_by_id"
t.string "purchid"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" 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 ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

1
spec/factories/sales_log.rb

@ -6,6 +6,7 @@ FactoryBot.define do
created_at { Time.utc(2022, 2, 8, 16, 52, 15) } created_at { Time.utc(2022, 2, 8, 16, 52, 15) }
updated_at { Time.utc(2022, 2, 8, 16, 52, 15) } updated_at { Time.utc(2022, 2, 8, 16, 52, 15) }
trait :completed do trait :completed do
purchid { "PC123" }
saledate { Time.utc(2022, 2, 2, 10, 36, 49) } saledate { Time.utc(2022, 2, 2, 10, 36, 49) }
end end
end end

43
spec/features/lettings_log_spec.rb

@ -93,22 +93,6 @@ RSpec.describe "Lettings Log Features" do
expect(page).to have_content("You have answered 2 of 8 questions") expect(page).to have_content("You have answered 2 of 8 questions")
end end
end end
context "when completing the setup sales log section" do
it "includes the sale completion date question" do
visit("/sales-logs")
click_button("Create a new sales log")
click_link("Set up this sales log")
fill_in("sales_log[saledate(1i)]", with: "2022")
fill_in("sales_log[saledate(2i)]", with: "08")
fill_in("sales_log[saledate(3i)]", with: "10")
click_button("Save and continue")
log_id = page.current_path.scan(/\d/).join
visit("sales-logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Sale completion date")
expect(page).to have_content("2022")
end
end
end end
context "when the signed is user is not a Support user" do context "when the signed is user is not a Support user" do
@ -140,33 +124,6 @@ RSpec.describe "Lettings Log Features" do
end end
end end
context "when completing the setup sales log section" do
it "includes the sale completion date question" do
visit("/sales-logs")
click_button("Create a new sales log")
click_link("Set up this sales log")
fill_in("sales_log[saledate(1i)]", with: "2022")
fill_in("sales_log[saledate(2i)]", with: "08")
fill_in("sales_log[saledate(3i)]", with: "10")
click_button("Save and continue")
log_id = page.current_path.scan(/\d/).join
visit("sales-logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Sale completion date")
expect(page).to have_content("2022")
end
end
context "when the sales log feature flag is toggled" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
it "hides the create sales log button in production" do
visit("/lettings-logs")
expect(page).not_to have_content("Create a new sales log")
end
end
context "when returning to the list of logs via breadcrumbs link" do context "when returning to the list of logs via breadcrumbs link" do
before do before do
visit("/lettings-logs") visit("/lettings-logs")

31
spec/features/sales_log_spec.rb

@ -32,6 +32,37 @@ RSpec.describe "Sales Log Features" do
expect(page).to have_current_path("/sales-logs") expect(page).to have_current_path("/sales-logs")
end end
end end
context "when completing the setup sales log section" do
it "includes the purchaser code and sale completion date questions" do
visit("/sales-logs")
click_button("Create a new sales log")
click_link("Set up this sales log")
fill_in("sales_log[purchid]", with: "PC123")
click_button("Save and continue")
fill_in("sales_log[saledate(1i)]", with: "2022")
fill_in("sales_log[saledate(2i)]", with: "08")
fill_in("sales_log[saledate(3i)]", with: "10")
click_button("Save and continue")
log_id = page.current_path.scan(/\d/).join
visit("sales-logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Purchaser code")
expect(page).to have_content("PC123")
expect(page).to have_content("Sale completion date")
expect(page).to have_content("2022")
end
end
context "when the sales log feature flag is toggled" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
it "hides the create sales log button in production" do
visit("/sales-logs")
expect(page).not_to have_content("Create a new sales log")
end
end
end end
end end
end end

29
spec/models/form/sales/setup/pages/purchaser_code_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Setup::Pages::PurchaserCode, 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[purchid])
end
it "has the correct id" do
expect(page.id).to eq("purchaser_code")
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
end

37
spec/models/form/sales/setup/questions/purchaser_code_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Sales::Setup::Questions::PurchaserCode, 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("purchid")
end
it "has the correct header" do
expect(question.header).to eq("What is the purchaser code?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Purchaser code")
end
it "has the correct type" do
expect(question.type).to eq("text")
end
it "has the correct width" do
expect(question.width).to eq(10)
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
end

2
spec/models/form/sales/setup/subsections/setup_spec.rb

@ -13,7 +13,7 @@ RSpec.describe Form::Sales::Setup::Subsections::Setup, type: :model do
it "has correct pages" do it "has correct pages" do
expect(setup.pages.map(&:id)).to eq( expect(setup.pages.map(&:id)).to eq(
%w[sale_date], %w[purchaser_code sale_date],
) )
end end

8
spec/models/form_spec.rb

@ -218,10 +218,10 @@ RSpec.describe Form, type: :model do
expect(form.sections[0].class).to eq(Form::Sales::Setup::Sections::Setup) expect(form.sections[0].class).to eq(Form::Sales::Setup::Sections::Setup)
expect(form.subsections.count).to eq(1) expect(form.subsections.count).to eq(1)
expect(form.subsections.first.id).to eq("setup") expect(form.subsections.first.id).to eq("setup")
expect(form.pages.count).to eq(1) expect(form.pages.count).to eq(2)
expect(form.pages.first.id).to eq("sale_date") expect(form.pages.first.id).to eq("purchaser_code")
expect(form.questions.count).to eq(1) expect(form.questions.count).to eq(2)
expect(form.questions.first.id).to eq("saledate") expect(form.questions.first.id).to eq("purchid")
expect(form.start_date).to eq(Time.zone.parse("2022-04-01")) expect(form.start_date).to eq(Time.zone.parse("2022-04-01"))
expect(form.end_date).to eq(Time.zone.parse("2023-07-01")) expect(form.end_date).to eq(Time.zone.parse("2023-07-01"))
end end

2
spec/requests/sales_logs_controller_spec.rb

@ -239,7 +239,7 @@ RSpec.describe SalesLogsController, type: :request do
end end
it "shows sales logs for multiple selected statuses and years" do it "shows sales logs for multiple selected statuses and years" do
get "/sales-logs?years[]=2021&years[]=2022&status[]=not_started&status[]=completed", headers: headers, params: {} get "/sales-logs?years[]=2021&years[]=2022&status[]=in_progress&status[]=completed", headers: headers, params: {}
expect(page).to have_link(sales_log_2021.id.to_s) expect(page).to have_link(sales_log_2021.id.to_s)
expect(page).to have_link(sales_log_2022.id.to_s) expect(page).to have_link(sales_log_2022.id.to_s)
end end

Loading…
Cancel
Save