Browse Source

Merge branch 'main' into CLDC-3557-Only-return-visible-locations

pull/2506/head
Manny Dinssa 2 years ago committed by GitHub
parent
commit
d14deba527
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 121
      .github/workflows/staging_pipeline.yml
  2. 6
      db/seeds.rb
  3. 49
      docs/testing.md
  4. 25
      lib/tasks/fix_nil_letting_allocation_values.rake
  5. 2
      spec/components/create_log_actions_component_spec.rb
  6. 16
      spec/components/data_protection_confirmation_banner_component_spec.rb
  7. 1
      spec/factories/lettings_log.rb
  8. 4
      spec/factories/organisation.rb
  9. 16
      spec/factories/user.rb
  10. 2
      spec/features/user_spec.rb
  11. 20
      spec/helpers/locations_helper_spec.rb
  12. 73
      spec/lib/tasks/fix_nil_letting_allocation_values_spec.rb
  13. 1
      spec/mailers/resend_invitation_mailer_spec.rb
  14. 2
      spec/models/form/lettings/pages/address_matcher_spec.rb
  15. 2
      spec/models/form/lettings/pages/uprn_selection_spec.rb
  16. 2
      spec/models/form/lettings/pages/uprn_spec.rb
  17. 2
      spec/models/form/lettings/questions/property_reference_spec.rb
  18. 10
      spec/models/form/lettings/questions/uprn_confirmation_spec.rb
  19. 2
      spec/models/form/sales/pages/address_matcher_spec.rb
  20. 6
      spec/models/form/sales/pages/uprn_confirmation_spec.rb
  21. 2
      spec/models/form/sales/pages/uprn_selection_spec.rb
  22. 2
      spec/models/form/sales/pages/uprn_spec.rb
  23. 2
      spec/models/form/sales/questions/address_line1_for_address_matcher_spec.rb
  24. 2
      spec/models/form/sales/questions/buyer1_mortgage_spec.rb
  25. 2
      spec/models/form/sales/questions/buyer2_mortgage_spec.rb
  26. 2
      spec/models/form/sales/questions/buyers_organisations_spec.rb
  27. 88
      spec/models/form/sales/questions/deposit_amount_spec.rb
  28. 2
      spec/models/form/sales/questions/postcode_for_address_matcher_spec.rb
  29. 8
      spec/models/form/sales/questions/uprn_confirmation_spec.rb
  30. 2
      spec/models/form/sales/questions/uprn_selection_spec.rb
  31. 2
      spec/models/form/sales/questions/uprn_spec.rb
  32. 4
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  33. 4
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  34. 4
      spec/models/form/sales/subsections/outright_sale_spec.rb
  35. 4
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  36. 4
      spec/models/scheme_spec.rb
  37. 1
      spec/models/user_spec.rb
  38. 2
      spec/models/validations/date_validations_spec.rb
  39. 2
      spec/models/validations/local_authority_validations_spec.rb
  40. 2
      spec/models/validations/sales/soft_validations_spec.rb
  41. 4
      spec/models/validations/setup_validations_spec.rb
  42. 6
      spec/models/validations/tenancy_validations_spec.rb
  43. 2
      spec/policies/user_policy_spec.rb
  44. 2
      spec/requests/bulk_upload_lettings_logs_controller_spec.rb
  45. 2
      spec/requests/bulk_upload_sales_logs_controller_spec.rb
  46. 3
      spec/requests/organisations_controller_spec.rb
  47. 10
      spec/requests/start_controller_spec.rb
  48. 6
      spec/services/csv/sales_log_csv_service_spec.rb
  49. 2
      spec/views/logs/_create_for_org_actions.html.erb_spec.rb
  50. 2
      spec/views/organisations/data_sharing_agreement.html.erb_spec.rb
  51. 12
      spec/views/organisations/show.html.erb_spec.rb

121
.github/workflows/staging_pipeline.yml

@ -72,7 +72,7 @@ jobs:
- name: Run tests - name: Run tests
run: | run: |
bundle exec rake parallel:spec['spec\/(?!features)'] bundle exec rake parallel:spec['spec\/(?!features|models|requests)']
feature_test: feature_test:
name: Feature Tests name: Feature Tests
@ -132,6 +132,123 @@ jobs:
run: | run: |
bundle exec rspec spec/features --fail-fast bundle exec rspec spec/features --fail-fast
model_test:
name: Model tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13.5
env:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
POSTGRES_DB: data_collector
ports:
- 5432:5432
# Needed because the Postgres container does not provide a health check
# tmpfs makes database faster by using RAM
options: >-
--mount type=tmpfs,destination=/var/lib/postgresql/data
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
RAILS_ENV: test
GEMFILE_RUBY_VERSION: 3.1.1
DB_HOST: localhost
DB_DATABASE: data_collector
DB_USERNAME: postgres
DB_PASSWORD: password
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Set up Node.js
uses: actions/setup-node@v3
with:
cache: yarn
node-version: 20
- name: Create database
run: |
bundle exec rake db:prepare
- name: Compile assets
run: |
bundle exec rake assets:precompile
- name: Run tests
run: |
bundle exec rspec spec/models --fail-fast
requests_test:
name: Requests tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13.5
env:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
POSTGRES_DB: data_collector
ports:
- 5432:5432
# Needed because the Postgres container does not provide a health check
# tmpfs makes database faster by using RAM
options: >-
--mount type=tmpfs,destination=/var/lib/postgresql/data
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
RAILS_ENV: test
GEMFILE_RUBY_VERSION: 3.1.1
DB_HOST: localhost
DB_DATABASE: data_collector
DB_USERNAME: postgres
DB_PASSWORD: password
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
PARALLEL_TEST_PROCESSORS: 4
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Set up Node.js
uses: actions/setup-node@v3
with:
cache: yarn
node-version: 20
- name: Create database
run: |
bundle exec rake parallel:setup
- name: Compile assets
run: |
bundle exec rake assets:precompile
- name: Run tests
run: |
bundle exec rake parallel:spec['spec/requests']
lint: lint:
name: Lint name: Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -179,7 +296,7 @@ jobs:
aws_deploy: aws_deploy:
name: AWS Deploy name: AWS Deploy
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
needs: [lint, test, feature_test, audit] needs: [lint, test, feature_test, requests_test, model_test, audit]
uses: ./.github/workflows/aws_deploy.yml uses: ./.github/workflows/aws_deploy.yml
with: with:
aws_account_id: 107155005276 aws_account_id: 107155005276

6
db/seeds.rb

@ -255,7 +255,7 @@ unless Rails.env.test?
assigned_to: support_user, assigned_to: support_user,
owning_organisation: org, owning_organisation: org,
managing_organisation: org, managing_organisation: org,
saledate: Date.new(2023, 4, 1), saledate: Time.zone.today,
purchid: "1", purchid: "1",
ownershipsch: 1, ownershipsch: 1,
type: 2, type: 2,
@ -267,7 +267,7 @@ unless Rails.env.test?
assigned_to: support_user, assigned_to: support_user,
owning_organisation: org, owning_organisation: org,
managing_organisation: org, managing_organisation: org,
saledate: Date.new(2023, 4, 1), saledate: Time.zone.today,
purchid: "1", purchid: "1",
ownershipsch: 2, ownershipsch: 2,
type: 9, type: 9,
@ -279,7 +279,7 @@ unless Rails.env.test?
assigned_to: support_user, assigned_to: support_user,
owning_organisation: org, owning_organisation: org,
managing_organisation: org, managing_organisation: org,
saledate: Date.new(2023, 4, 1), saledate: Time.zone.today,
purchid: "1", purchid: "1",
ownershipsch: 3, ownershipsch: 3,
type: 10, type: 10,

49
docs/testing.md

@ -31,3 +31,52 @@ bundle exec rake parallel:setup
```sh ```sh
RAILS_ENV=test bundle exec rake parallel:spec RAILS_ENV=test bundle exec rake parallel:spec
``` ```
## Factories for Lettings Log, Sales Log, Organisation, and User
Each of these factories has nested relationships and callbacks that ensure associated objects are created and linked properly. For instance, creating a `lettings_log` involves creating or associating with a `user`, which in turn is linked to an `organisation`, potentially leading to creating `organisation_rent_periods` and a `data_protection_confirmation`.
This documentation outlines the objects that are created and/or persisted to the database when using FactoryBot to create or build models for LettingsLog, SalesLog, Organisation, and User. There are other factories, but they are simpler, less frequently used and don't have as much resource hierarchy.
### Lettings Log
Objects Created/Persisted:
- **User**: The `assigned_to` user is created.
- **Organisation**: The `assigned_to` user’s organisation created by `User` factory.
- **DataProtectionConfirmation**: If `organisation` does not have DSA signed, `DataProtectionConfirmation` gets created with `assigned_to` user as a `data_protection_officer`
- **OrganisationRentPeriod**: If `log.period` is present and the `managing_organisation` does not have an `OrganisationRentPeriod` for that period, a new `OrganisationRentPeriod` is created and associated with `managing_organisation`.
Example Usage:
```
let(:lettings_log) { create(:lettings_log) }
```
### Sales Log
Objects Created/Persisted:
- **User**: The `assigned_to` user is created.
- **Organisation**: The `assigned_to` user’s organisation created by `User` factory.
- **DataProtectionConfirmation**: If `organisation` does not have DSA signed, `DataProtectionConfirmation` gets created with `assigned_to` user as a `data_protection_officer`
Example Usage:
```
let(:sales_log) { create(:sales_log) }
```
### Organisation
Objects Created/Persisted:
- **OrganisationRentPeriod**: For each rent period in transient attribute `rent_periods`, an `OrganisationRentPeriod` is created.
- **DataProtectionConfirmation**: If `with_dsa` is `true` (default), a `DataProtectionConfirmation` is created with a `data_protection_officer`
- **User**: Data protection officer that signs the data protection confirmation
Example Usage:
```
let(:organisation) { create(:organisation, rent_periods: [1, 2])}
```
### User
Objects Created/Persisted:
- **Organisation**: User’s organisation.
- **DataProtectionConfirmation**: If `organisation` does not have DSA signed, `DataProtectionConfirmation` gets created with this user as a `data_protection_officer`
Example Usage:
```
let(:user) { create(:user) }
```

25
lib/tasks/fix_nil_letting_allocation_values.rake

@ -1,25 +0,0 @@
desc "Infer nil letting allocation values as no"
task fix_nil_letting_allocation_values: :environment do
LettingsLog.where(cbl: nil)
.or(LettingsLog.where(chr: nil))
.or(LettingsLog.where(cap: nil))
.or(LettingsLog.filter_by_year(2024).where(accessible_register: nil))
.find_each do |log|
next unless log.cbl.present? || log.chr.present? || log.cap.present? || log.accessible_register.present? || log.letting_allocation_unknown.present?
log.cbl = 0 if log.cbl.blank?
log.chr = 0 if log.chr.blank?
log.cap = 0 if log.cap.blank?
log.accessible_register = 0 if log.form.start_year_after_2024? && log.accessible_register.blank?
log.letting_allocation_unknown = if log.cbl == 1 || log.chr == 1 || log.cap == 1 || log.accessible_register == 1
0
else
1
end
next if log.save
Rails.logger.info("NilLettingsAllocationValues: Unable to save changes to log #{log.id}")
end
end

2
spec/components/create_log_actions_component_spec.rb

@ -66,7 +66,7 @@ RSpec.describe CreateLogActionsComponent, type: :component do
context "when not support user" do context "when not support user" do
context "without data sharing agreement" do context "without data sharing agreement" do
let(:user) { create(:user, organisation: create(:organisation, :without_dpc)) } let(:user) { create(:user, organisation: create(:organisation, :without_dpc), with_dsa: false) }
it "does not render actions" do it "does not render actions" do
expect(component).not_to be_display_actions expect(component).not_to be_display_actions

16
spec/components/data_protection_confirmation_banner_component_spec.rb

@ -5,11 +5,11 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
let(:component) { described_class.new(user:, organisation:) } let(:component) { described_class.new(user:, organisation:) }
let(:render) { render_inline(component) } let(:render) { render_inline(component) }
let(:user) { create(:user) } let(:user) { create(:user, with_dsa: false) }
let(:organisation) { user.organisation } let(:organisation) { user.organisation }
context "when user is support and organisation is blank" do context "when user is support and organisation is blank" do
let(:user) { create(:user, :support) } let(:user) { create(:user, :support, with_dsa: false) }
let(:organisation) { nil } let(:organisation) { nil }
it "does not display banner" do it "does not display banner" do
@ -37,8 +37,8 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
context "when org does not have a signed data sharing agreement" do context "when org does not have a signed data sharing agreement" do
context "when user is not a DPO" do context "when user is not a DPO" do
let(:organisation) { create(:organisation, :without_dpc) } let(:organisation) { create(:organisation, :without_dpc) }
let(:user) { create(:user, organisation:) } let(:user) { create(:user, organisation:, with_dsa: false) }
let!(:dpo) { create(:user, :data_protection_officer, organisation:) } let!(:dpo) { create(:user, :data_protection_officer, organisation:, with_dsa: false) }
it "displays the banner and shows DPOs" do it "displays the banner and shows DPOs" do
expect(component.display_banner?).to eq(true) expect(component.display_banner?).to eq(true)
@ -50,7 +50,7 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
context "when user is a DPO" do context "when user is a DPO" do
let(:organisation) { create(:organisation, :without_dpc) } let(:organisation) { create(:organisation, :without_dpc) }
let(:user) { create(:user, :data_protection_officer, organisation:) } let(:user) { create(:user, :data_protection_officer, organisation:, with_dsa: false) }
it "displays the banner and asks to sign" do it "displays the banner and asks to sign" do
expect(component.display_banner?).to eq(true) expect(component.display_banner?).to eq(true)
@ -141,8 +141,8 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
context "when org does not have a signed data sharing agreement" do context "when org does not have a signed data sharing agreement" do
context "when user is not a DPO" do context "when user is not a DPO" do
let(:organisation) { create(:organisation, :without_dpc) } let(:organisation) { create(:organisation, :without_dpc) }
let(:user) { create(:user, organisation:) } let(:user) { create(:user, organisation:, with_dsa: false) }
let!(:dpo) { create(:user, :data_protection_officer, organisation:) } let!(:dpo) { create(:user, :data_protection_officer, organisation:, with_dsa: false) }
it "displays the banner and shows DPOs" do it "displays the banner and shows DPOs" do
expect(component.display_banner?).to eq(true) expect(component.display_banner?).to eq(true)
@ -168,7 +168,7 @@ RSpec.describe DataProtectionConfirmationBannerComponent, type: :component do
context "when user is a DPO" do context "when user is a DPO" do
let(:organisation) { create(:organisation, :without_dpc) } let(:organisation) { create(:organisation, :without_dpc) }
let(:user) { create(:user, :data_protection_officer, organisation:) } let(:user) { create(:user, :data_protection_officer, organisation:, with_dsa: false) }
it "displays the banner and asks to sign" do it "displays the banner and asks to sign" do
expect(component.display_banner?).to eq(true) expect(component.display_banner?).to eq(true)

1
spec/factories/lettings_log.rb

@ -216,6 +216,7 @@ FactoryBot.define do
trait :ignore_validation_errors do trait :ignore_validation_errors do
to_create do |instance| to_create do |instance|
instance.valid? instance.valid?
instance.errors.clear
instance.save!(validate: false) instance.save!(validate: false)
end end
end end

4
spec/factories/organisation.rb

@ -25,11 +25,11 @@ FactoryBot.define do
end end
after(:create) do |org, evaluator| after(:create) do |org, evaluator|
if evaluator.with_dsa if evaluator.with_dsa && !org.data_protection_confirmed?
create( create(
:data_protection_confirmation, :data_protection_confirmation,
organisation: org, organisation: org,
data_protection_officer: org.users.any? ? org.users.first : create(:user, :data_protection_officer, organisation: org), data_protection_officer: org.users.any? ? org.users.first : create(:user, :data_protection_officer, organisation: org, with_dsa: false),
) )
end end
end end

16
spec/factories/user.rb

@ -3,7 +3,7 @@ FactoryBot.define do
sequence(:email) { "test#{SecureRandom.hex}@example.com" } sequence(:email) { "test#{SecureRandom.hex}@example.com" }
name { "Danny Rojas" } name { "Danny Rojas" }
password { "pAssword1" } password { "pAssword1" }
organisation organisation { association :organisation, with_dsa: is_dpo ? false : true }
role { "data_provider" } role { "data_provider" }
phone { "1234512345123" } phone { "1234512345123" }
trait :data_provider do trait :data_provider do
@ -27,10 +27,18 @@ FactoryBot.define do
old_user_id { SecureRandom.uuid } old_user_id { SecureRandom.uuid }
end end
after(:create) do |user, evaluator| transient do
FactoryBot.create(:legacy_user, old_user_id: evaluator.old_user_id, user:) with_dsa { true }
end
user.reload after(:create) do |user, evaluator|
if evaluator.with_dsa && !user.organisation.data_protection_confirmed?
create(
:data_protection_confirmation,
organisation: user.organisation,
data_protection_officer: user,
)
end
end end
end end
end end

2
spec/features/user_spec.rb

@ -594,7 +594,7 @@ RSpec.describe "User Features" do
end end
before do before do
other_user.update!(initial_confirmation_sent: true, last_sign_in_at: nil) other_user.update!(initial_confirmation_sent: true, last_sign_in_at: nil, old_user_id: "old-user-id")
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in(user) sign_in(user)
visit(user_path(other_user)) visit(user_path(other_user))

20
spec/helpers/locations_helper_spec.rb

@ -1,6 +1,8 @@
require "rails_helper" require "rails_helper"
RSpec.describe LocationsHelper do RSpec.describe LocationsHelper do
include CollectionTimeHelper
describe "mobility type selection" do describe "mobility type selection" do
expected_selection = [OpenStruct.new(id: "Wheelchair-user standard", name: "Wheelchair-user standard", description: "Suitable for someone who uses a wheelchair and offers the full use of all rooms and facilities."), expected_selection = [OpenStruct.new(id: "Wheelchair-user standard", name: "Wheelchair-user standard", description: "Suitable for someone who uses a wheelchair and offers the full use of all rooms and facilities."),
OpenStruct.new(id: "Fitted with equipment and adaptations", name: "Fitted with equipment and adaptations", description: "Fitted with stairlifts, ramps, level access showers or grab rails."), OpenStruct.new(id: "Fitted with equipment and adaptations", name: "Fitted with equipment and adaptations", description: "Fitted with stairlifts, ramps, level access showers or grab rails."),
@ -201,18 +203,26 @@ RSpec.describe LocationsHelper do
context "when viewing availability" do context "when viewing availability" do
context "with no deactivations" do context "with no deactivations" do
it "displays current collection start date as availability date if created_at is later than collection start date" do before do
location.update!(startdate: nil, created_at: Time.zone.local(2024, 1, 16)) allow(Time).to receive(:now).and_call_original
end
it "displays current collection start date as availability date if created_at is later than collection start date and not in a crossover period" do
allow(FormHandler.instance).to receive(:in_crossover_period?).with(anything).and_return(false)
location.update!(startdate: nil, created_at: current_collection_start_date + 6.months)
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2023") expect(availability_attribute).to eq("Active from 1 April #{current_collection_start_date.year}")
end end
it "displays previous collection start date as availability date if created_at is later than collection start date and in crossover" do it "displays previous collection start date as availability date if created_at is later than collection start date and in crossover" do
location.update!(startdate: nil, created_at: Time.zone.local(2023, 4, 16)) allow(FormHandler.instance).to receive(:in_crossover_period?).with(anything).and_return(true)
location.update!(startdate: nil, created_at: current_collection_start_date + 1.week)
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022") expect(availability_attribute).to eq("Active from 1 April #{previous_collection_start_date.year}")
end end
context "when location was merged" do context "when location was merged" do

73
spec/lib/tasks/fix_nil_letting_allocation_values_spec.rb

@ -1,73 +0,0 @@
require "rails_helper"
require "rake"
RSpec.describe "fix_nil_letting_allocation_values" do
describe ":fix_nil_letting_allocation_values", type: :task do
subject(:task) { Rake::Task["fix_nil_letting_allocation_values"] }
before do
Rake.application.rake_require("tasks/fix_nil_letting_allocation_values")
Rake::Task.define_task(:environment)
task.reenable
end
it "sets nil values to 0 when one allocation type value is non-nil" do
log = create(:lettings_log, :setup_completed, :startdate_today, cbl: nil, chr: nil, cap: 1, accessible_register: nil, letting_allocation_unknown: nil)
task.invoke
log.reload
expect(log.cbl).to be 0
expect(log.chr).to be 0
expect(log.cap).to be 1
expect(log.accessible_register).to be 0
expect(log.letting_allocation_unknown).to be 0
end
it "sets nil values to 0 and letting_allocation_unknown to 1 when non-nil allocation type values are 0" do
log = create(:lettings_log, :setup_completed, :startdate_today, cbl: 0, chr: 0, cap: nil, accessible_register: nil, letting_allocation_unknown: nil)
task.invoke
log.reload
expect(log.cbl).to be 0
expect(log.chr).to be 0
expect(log.cap).to be 0
expect(log.accessible_register).to be 0
expect(log.letting_allocation_unknown).to be 1
end
it "does not set anything when question has not been answered at all" do
log = create(:lettings_log, :setup_completed, :startdate_today, cbl: nil, chr: nil, cap: nil, accessible_register: nil, letting_allocation_unknown: nil)
task.invoke
log.reload
expect(log.cbl).to be_nil
expect(log.chr).to be_nil
expect(log.cap).to be_nil
expect(log.accessible_register).to be_nil
expect(log.letting_allocation_unknown).to be_nil
end
it "does not set accessible_register for logs before 2024" do
log = create(:lettings_log, :setup_completed, startdate: Time.zone.local(2023, 5, 1), cbl: 1, chr: nil, cap: nil, accessible_register: nil, letting_allocation_unknown: nil)
task.invoke
log.reload
expect(log.cbl).to be 1
expect(log.chr).to be 0
expect(log.cap).to be 0
expect(log.accessible_register).to be_nil
expect(log.letting_allocation_unknown).to be 0
end
it "logs the log id if the change cannot be saved" do
log = create(:lettings_log, :ignore_validation_errors, :setup_completed, startdate: Time.zone.local(2022, 4, 1), cbl: 1, chr: nil, cap: nil, letting_allocation_unknown: nil)
expect(Rails.logger).to receive(:info).with(match(/log #{log.id}/))
task.invoke
end
end
end

1
spec/mailers/resend_invitation_mailer_spec.rb

@ -41,6 +41,7 @@ RSpec.describe ResendInvitationMailer do
end end
it "sends an initial invitation" do it "sends an initial invitation" do
FactoryBot.create(:legacy_user, old_user_id: new_active_migrated_user.old_user_id, user: new_active_migrated_user)
expect(notify_client).to receive(:send_email).with(email_address: "new_active_migrated_user@example.com", template_id: User::BETA_ONBOARDING_TEMPLATE_ID, personalisation:).once expect(notify_client).to receive(:send_email).with(email_address: "new_active_migrated_user@example.com", template_id: User::BETA_ONBOARDING_TEMPLATE_ID, personalisation:).once
described_class.new.resend_invitation_email(new_active_migrated_user) described_class.new.resend_invitation_email(new_active_migrated_user)
end end

2
spec/models/form/lettings/pages/address_matcher_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Lettings::Pages::AddressMatcher, type: :model do
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:log) { create(:lettings_log) } let(:log) { build(:lettings_log) }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)

2
spec/models/form/lettings/pages/uprn_selection_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Lettings::Pages::UprnSelection, type: :model do
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:log) { create(:lettings_log) } let(:log) { build(:lettings_log) }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)

2
spec/models/form/lettings/pages/uprn_spec.rb

@ -45,7 +45,7 @@ RSpec.describe Form::Lettings::Pages::Uprn, type: :model do
end end
context "when log is present" do context "when log is present" do
let(:log) { create(:lettings_log) } let(:log) { build(:lettings_log) }
context "with 2023/24 form" do context "with 2023/24 form" do
it "points to address page" do it "points to address page" do

2
spec/models/form/lettings/questions/property_reference_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Lettings::Questions::PropertyReference, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) }
let(:lettings_log) { FactoryBot.create(:lettings_log) } let(:lettings_log) { FactoryBot.build(:lettings_log) }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)

10
spec/models/form/lettings/questions/uprn_confirmation_spec.rb

@ -42,7 +42,7 @@ RSpec.describe Form::Lettings::Questions::UprnConfirmation, type: :model do
describe "notification_banner" do describe "notification_banner" do
context "when address is not present" do context "when address is not present" do
it "returns nil" do it "returns nil" do
log = create(:lettings_log) log = build(:lettings_log)
expect(question.notification_banner(log)).to be_nil expect(question.notification_banner(log)).to be_nil
end end
@ -50,7 +50,7 @@ RSpec.describe Form::Lettings::Questions::UprnConfirmation, type: :model do
context "when address is present" do context "when address is present" do
it "returns formatted value" do it "returns formatted value" do
log = create(:lettings_log, :setup_completed, address_line1: "1, Test Street", town_or_city: "Test Town", postcode_full: "AA1 1AA", uprn: "1", uprn_known: 1) log = build(:lettings_log, :setup_completed, address_line1: "1, Test Street", town_or_city: "Test Town", postcode_full: "AA1 1AA", uprn: "1", uprn_known: 1)
expect(question.notification_banner(log)).to eq( expect(question.notification_banner(log)).to eq(
{ {
@ -64,7 +64,7 @@ RSpec.describe Form::Lettings::Questions::UprnConfirmation, type: :model do
describe "has the correct hidden_in_check_answers" do describe "has the correct hidden_in_check_answers" do
context "when uprn_known != 1 && uprn_confirmed == nil" do context "when uprn_known != 1 && uprn_confirmed == nil" do
let(:log) { create(:lettings_log, uprn_known: 0, uprn_confirmed: nil) } let(:log) { build(:lettings_log, uprn_known: 0, uprn_confirmed: nil) }
it "returns true" do it "returns true" do
expect(question.hidden_in_check_answers?(log)).to eq(true) expect(question.hidden_in_check_answers?(log)).to eq(true)
@ -72,7 +72,7 @@ RSpec.describe Form::Lettings::Questions::UprnConfirmation, type: :model do
end end
context "when uprn_known == 1 && uprn_confirmed == nil" do context "when uprn_known == 1 && uprn_confirmed == nil" do
let(:log) { create(:lettings_log, :completed, uprn_known: 1, uprn: 1, uprn_confirmed: nil) } let(:log) { build(:lettings_log, :completed, uprn_known: 1, uprn: 1, uprn_confirmed: nil) }
it "returns false" do it "returns false" do
expect(question.hidden_in_check_answers?(log)).to eq(false) expect(question.hidden_in_check_answers?(log)).to eq(false)
@ -80,7 +80,7 @@ RSpec.describe Form::Lettings::Questions::UprnConfirmation, type: :model do
end end
context "when uprn_known != 1 && uprn_confirmed == 1" do context "when uprn_known != 1 && uprn_confirmed == 1" do
let(:log) { create(:lettings_log) } let(:log) { build(:lettings_log) }
it "returns true" do it "returns true" do
log.uprn_known = 1 log.uprn_known = 1

2
spec/models/form/sales/pages/address_matcher_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Sales::Pages::AddressMatcher, type: :model do
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:log) { create(:sales_log) } let(:log) { build(:sales_log) }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)

6
spec/models/form/sales/pages/uprn_confirmation_spec.rb

@ -33,7 +33,7 @@ RSpec.describe Form::Sales::Pages::UprnConfirmation, type: :model do
describe "has correct routed_to?" do describe "has correct routed_to?" do
context "when uprn present && uprn_known == 1 " do context "when uprn present && uprn_known == 1 " do
let(:log) { create(:sales_log) } let(:log) { build(:sales_log) }
it "returns true" do it "returns true" do
log.uprn_known = 1 log.uprn_known = 1
@ -43,7 +43,7 @@ RSpec.describe Form::Sales::Pages::UprnConfirmation, type: :model do
end end
context "when uprn = nil" do context "when uprn = nil" do
let(:log) { create(:sales_log, uprn_known: 1, uprn: nil) } let(:log) { build(:sales_log, uprn_known: 1, uprn: nil) }
it "returns false" do it "returns false" do
expect(page.routed_to?(log)).to eq(false) expect(page.routed_to?(log)).to eq(false)
@ -51,7 +51,7 @@ RSpec.describe Form::Sales::Pages::UprnConfirmation, type: :model do
end end
context "when uprn_known == 0" do context "when uprn_known == 0" do
let(:log) { create(:sales_log, uprn_known: 0, uprn: "123456789") } let(:log) { build(:sales_log, uprn_known: 0, uprn: "123456789") }
it "returns false" do it "returns false" do
expect(page.routed_to?(log)).to eq(false) expect(page.routed_to?(log)).to eq(false)

2
spec/models/form/sales/pages/uprn_selection_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Sales::Pages::UprnSelection, type: :model do
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:log) { create(:sales_log) } let(:log) { build(:sales_log) }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)

2
spec/models/form/sales/pages/uprn_spec.rb

@ -45,7 +45,7 @@ RSpec.describe Form::Sales::Pages::Uprn, type: :model do
end end
context "when log is present" do context "when log is present" do
let(:log) { create(:sales_log) } let(:log) { build(:sales_log) }
context "with 2023/24 form" do context "with 2023/24 form" do
it "points to address page" do it "points to address page" do

2
spec/models/form/sales/questions/address_line1_for_address_matcher_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Sales::Questions::AddressLine1ForAddressMatcher, type: :mod
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:log) { create(:sales_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } let(:log) { build(:sales_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)

2
spec/models/form/sales/questions/buyer1_mortgage_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Sales::Questions::Buyer1Mortgage, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) }
let(:log) { create(:sales_log) } let(:log) { build(:sales_log) }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)

2
spec/models/form/sales/questions/buyer2_mortgage_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Sales::Questions::Buyer2Mortgage, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) }
let(:log) { create(:sales_log) } let(:log) { build(:sales_log) }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)

2
spec/models/form/sales/questions/buyers_organisations_spec.rb

@ -48,7 +48,7 @@ RSpec.describe Form::Sales::Questions::BuyersOrganisations, type: :model do
end end
it "has the correct displayed answer_options" do it "has the correct displayed answer_options" do
expect(question.displayed_answer_options(FactoryBot.create(:sales_log))).to eq( expect(question.displayed_answer_options(FactoryBot.build(:sales_log))).to eq(
{ {
"pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" }, "pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" },
"pregother" => { "value" => "Other private registered provider (PRP) - housing association" }, "pregother" => { "value" => "Other private registered provider (PRP) - housing association" },

88
spec/models/form/sales/questions/deposit_amount_spec.rb

@ -1,34 +1,15 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::DepositAmount, type: :model do RSpec.describe Form::Sales::Questions::DepositAmount, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1, optional: false) } subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1, optional:) }
let(:optional) { false }
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("deposit")
end
it "has the correct header" do
expect(question.header).to eq("How much cash deposit was paid on the property?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Cash deposit")
end
it "has the correct type" do
expect(question.type).to eq("numeric")
end
context "when the ownership type is shared" do context "when the ownership type is shared" do
let(:log) { create(:sales_log, :completed, ownershipsch: 1, mortgageused: 2) } let(:log) { build(:sales_log, :completed, ownershipsch: 1, mortgageused: 2) }
it "is not marked as derived" do it "is not marked as derived" do
expect(question.derived?(log)).to be false expect(question.derived?(log)).to be false
@ -36,7 +17,7 @@ RSpec.describe Form::Sales::Questions::DepositAmount, type: :model do
end end
context "when the ownership type is discounted for 2023" do context "when the ownership type is discounted for 2023" do
let(:log) { create(:sales_log, :completed, ownershipsch: 2, mortgageused: 2, saledate: Time.zone.local(2024, 3, 1)) } let(:log) { build(:sales_log, :completed, ownershipsch: 2, mortgageused: 2, saledate: Time.zone.local(2024, 3, 1)) }
it "is not marked as derived" do it "is not marked as derived" do
expect(question.derived?(log)).to be false expect(question.derived?(log)).to be false
@ -44,49 +25,48 @@ RSpec.describe Form::Sales::Questions::DepositAmount, type: :model do
end end
context "when the ownership type is outright" do context "when the ownership type is outright" do
let(:log) { create(:sales_log, :completed, ownershipsch: 3, mortgageused: 2) } let(:log) { build(:sales_log, :outright_sale_setup_complete, mortgageused:) }
it "is not marked as derived when a mortgage is used" do context "when a mortgage is used" do
log.mortgageused = 1 let(:mortgageused) { 1 }
expect(question.derived?(log)).to be false
end
it "is marked as derived when a mortgage is not used" do it "is not marked as derived " do
log.mortgageused = 2 expect(question.derived?(log)).to be false
expect(question.derived?(log)).to be true end
end end
it "is marked as derived when the mortgage use is unknown" do context "when a mortgage is not used" do
log.mortgageused = 3 let(:mortgageused) { 2 }
expect(question.derived?(log)).to be true
end
end
it "has the correct hint" do it "is marked as derived " do
expect(question.hint_text).to eq("Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. This excludes any grant or loan") expect(question.derived?(log)).to be true
end end
end
it "has correct width" do context "when the mortgage use is unknown" do
expect(question.width).to eq(5) let(:mortgageused) { 3 }
end
it "has correct prefix" do it "is marked as derived " do
expect(question.prefix).to eq("£") expect(question.derived?(log)).to be true
end
end
end end
it "has correct min" do describe "hint text" do
expect(question.min).to eq(0) context "when optional is false" do
end let(:optional) { false }
it "has correct max" do it "has the correct hint" do
expect(question.max).to eq(999_999) expect(question.hint_text).to eq("Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. This excludes any grant or loan")
end end
end
context "when optional iis true" do context "when optional is true" do
subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1, optional: true) } let(:optional) { true }
it "has a correct hint_text" do it "has the correct hint" do
expect(question.hint_text).to eq("Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. This excludes any grant or loan. As this is a fully staircased sale this question is optional. If you do not have the information available click save and continue") expect(question.hint_text).to eq("Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. This excludes any grant or loan. As this is a fully staircased sale this question is optional. If you do not have the information available click save and continue")
end
end end
end end
end end

2
spec/models/form/sales/questions/postcode_for_address_matcher_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Sales::Questions::PostcodeForAddressMatcher, type: :model d
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:log) { create(:sales_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } let(:log) { build(:sales_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)

8
spec/models/form/sales/questions/uprn_confirmation_spec.rb

@ -42,7 +42,7 @@ RSpec.describe Form::Sales::Questions::UprnConfirmation, type: :model do
describe "notification_banner" do describe "notification_banner" do
context "when address is not present" do context "when address is not present" do
it "returns nil" do it "returns nil" do
log = create(:sales_log) log = build(:sales_log)
expect(question.notification_banner(log)).to be_nil expect(question.notification_banner(log)).to be_nil
end end
@ -64,7 +64,7 @@ RSpec.describe Form::Sales::Questions::UprnConfirmation, type: :model do
describe "has the correct hidden_in_check_answers" do describe "has the correct hidden_in_check_answers" do
context "when uprn_known != 1 && uprn_confirmed == nil" do context "when uprn_known != 1 && uprn_confirmed == nil" do
let(:log) { create(:sales_log, uprn_known: 0, uprn_confirmed: nil) } let(:log) { build(:sales_log, uprn_known: 0, uprn_confirmed: nil) }
it "returns true" do it "returns true" do
expect(question.hidden_in_check_answers?(log)).to eq(true) expect(question.hidden_in_check_answers?(log)).to eq(true)
@ -72,7 +72,7 @@ RSpec.describe Form::Sales::Questions::UprnConfirmation, type: :model do
end end
context "when uprn_known == 1 && uprn_confirmed == nil" do context "when uprn_known == 1 && uprn_confirmed == nil" do
let(:log) { create(:sales_log) } let(:log) { build(:sales_log) }
it "returns false" do it "returns false" do
log.uprn_known = 1 log.uprn_known = 1
@ -83,7 +83,7 @@ RSpec.describe Form::Sales::Questions::UprnConfirmation, type: :model do
end end
context "when uprn_known != 1 && uprn_confirmed == 1" do context "when uprn_known != 1 && uprn_confirmed == 1" do
let(:log) { create(:sales_log, uprn_known: 1, uprn: "12345", uprn_confirmed: 1) } let(:log) { build(:sales_log, uprn_known: 1, uprn: "12345", uprn_confirmed: 1) }
it "returns true" do it "returns true" do
expect(question.hidden_in_check_answers?(log)).to eq(true) expect(question.hidden_in_check_answers?(log)).to eq(true)

2
spec/models/form/sales/questions/uprn_selection_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Form::Sales::Questions::UprnSelection, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, skip_href: "skip_href") } let(:page) { instance_double(Form::Page, skip_href: "skip_href") }
let(:log) { create(:sales_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } let(:log) { build(:sales_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") }
let(:address_client_instance) { AddressClient.new(log.address_string) } let(:address_client_instance) { AddressClient.new(log.address_string) }
before do before do

2
spec/models/form/sales/questions/uprn_spec.rb

@ -45,7 +45,7 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do
describe "get_extra_check_answer_value" do describe "get_extra_check_answer_value" do
context "when address is not present" do context "when address is not present" do
let(:log) { create(:sales_log) } let(:log) { build(:sales_log) }
it "returns nil" do it "returns nil" do
expect(question.get_extra_check_answer_value(log)).to be_nil expect(question.get_extra_check_answer_value(log)).to be_nil

4
spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb

@ -67,7 +67,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
end end
context "when it is a discounted ownership scheme" do context "when it is a discounted ownership scheme" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 2) } let(:log) { FactoryBot.build(:sales_log, ownershipsch: 2) }
it "is displayed in tasklist" do it "is displayed in tasklist" do
expect(discounted_ownership_scheme.displayed_in_tasklist?(log)).to eq(true) expect(discounted_ownership_scheme.displayed_in_tasklist?(log)).to eq(true)
@ -75,7 +75,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
end end
context "when it is not a discounted ownership scheme" do context "when it is not a discounted ownership scheme" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 1) } let(:log) { FactoryBot.build(:sales_log, ownershipsch: 1) }
it "is displayed in tasklist" do it "is displayed in tasklist" do
expect(discounted_ownership_scheme.displayed_in_tasklist?(log)).to eq(false) expect(discounted_ownership_scheme.displayed_in_tasklist?(log)).to eq(false)

4
spec/models/form/sales/subsections/household_characteristics_spec.rb

@ -378,7 +378,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
end end
context "when the sale is to a company buyer" do context "when the sale is to a company buyer" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 3, companybuy: 1) } let(:log) { FactoryBot.build(:sales_log, ownershipsch: 3, companybuy: 1) }
it "is not displayed in tasklist" do it "is not displayed in tasklist" do
expect(household_characteristics.displayed_in_tasklist?(log)).to eq(false) expect(household_characteristics.displayed_in_tasklist?(log)).to eq(false)
@ -386,7 +386,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
end end
context "when the sale is not to a company buyer" do context "when the sale is not to a company buyer" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 3, companybuy: 2) } let(:log) { FactoryBot.build(:sales_log, ownershipsch: 3, companybuy: 2) }
it "is displayed in tasklist" do it "is displayed in tasklist" do
expect(household_characteristics.displayed_in_tasklist?(log)).to eq(true) expect(household_characteristics.displayed_in_tasklist?(log)).to eq(true)

4
spec/models/form/sales/subsections/outright_sale_spec.rb

@ -122,7 +122,7 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
end end
context "when it is a outright sale" do context "when it is a outright sale" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 3) } let(:log) { FactoryBot.build(:sales_log, ownershipsch: 3) }
it "is displayed in tasklist" do it "is displayed in tasklist" do
expect(outright_sale.displayed_in_tasklist?(log)).to eq(true) expect(outright_sale.displayed_in_tasklist?(log)).to eq(true)
@ -130,7 +130,7 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
end end
context "when it is not a outright sale" do context "when it is not a outright sale" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 2) } let(:log) { FactoryBot.build(:sales_log, ownershipsch: 2) }
it "is displayed in tasklist" do it "is displayed in tasklist" do
expect(outright_sale.displayed_in_tasklist?(log)).to eq(false) expect(outright_sale.displayed_in_tasklist?(log)).to eq(false)

4
spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb

@ -77,7 +77,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
end end
context "when it is a shared ownership scheme" do context "when it is a shared ownership scheme" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 1) } let(:log) { FactoryBot.build(:sales_log, ownershipsch: 1) }
it "is displayed in tasklist" do it "is displayed in tasklist" do
expect(shared_ownership_scheme.displayed_in_tasklist?(log)).to eq(true) expect(shared_ownership_scheme.displayed_in_tasklist?(log)).to eq(true)
@ -85,7 +85,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
end end
context "when it is not a shared ownership scheme" do context "when it is not a shared ownership scheme" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 2) } let(:log) { FactoryBot.build(:sales_log, ownershipsch: 2) }
it "is displayed in tasklist" do it "is displayed in tasklist" do
expect(shared_ownership_scheme.displayed_in_tasklist?(log)).to eq(false) expect(shared_ownership_scheme.displayed_in_tasklist?(log)).to eq(false)

4
spec/models/scheme_spec.rb

@ -305,7 +305,7 @@ RSpec.describe Scheme, type: :model do
end end
context "when scheme has discarded_at value" do context "when scheme has discarded_at value" do
let(:scheme) { FactoryBot.create(:scheme, discarded_at: Time.zone.now) } let(:scheme) { FactoryBot.build(:scheme, discarded_at: Time.zone.now) }
it "returns deleted" do it "returns deleted" do
expect(scheme.status).to eq(:deleted) expect(scheme.status).to eq(:deleted)
@ -368,7 +368,7 @@ RSpec.describe Scheme, type: :model do
describe "owning organisation" do describe "owning organisation" do
let(:stock_owning_org) { FactoryBot.create(:organisation, holds_own_stock: true) } let(:stock_owning_org) { FactoryBot.create(:organisation, holds_own_stock: true) }
let(:non_stock_owning_org) { FactoryBot.create(:organisation, holds_own_stock: false) } let(:non_stock_owning_org) { FactoryBot.create(:organisation, holds_own_stock: false) }
let(:scheme) { FactoryBot.create(:scheme, owning_organisation_id: stock_owning_org.id) } let(:scheme) { FactoryBot.build(:scheme, owning_organisation_id: stock_owning_org.id) }
context "when the owning organisation is set as a non-stock-owning organisation" do context "when the owning organisation is set as a non-stock-owning organisation" do
it "throws the correct validation error" do it "throws the correct validation error" do

1
spec/models/user_spec.rb

@ -114,6 +114,7 @@ RSpec.describe User, type: :model do
end end
it "can have one or more legacy users" do it "can have one or more legacy users" do
FactoryBot.create(:legacy_user, old_user_id: user.old_user_id, user:)
expect(user.legacy_users.size).to eq(1) expect(user.legacy_users.size).to eq(1)
end end

2
spec/models/validations/date_validations_spec.rb

@ -4,7 +4,7 @@ RSpec.describe Validations::DateValidations do
subject(:date_validator) { validator_class.new } subject(:date_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::DateValidations } } let(:validator_class) { Class.new { include Validations::DateValidations } }
let(:record) { create(:lettings_log) } let(:record) { build(:lettings_log) }
let(:scheme) { create(:scheme, end_date: Time.zone.today - 5.days) } let(:scheme) { create(:scheme, end_date: Time.zone.today - 5.days) }
let(:scheme_no_end_date) { create(:scheme, end_date: nil) } let(:scheme_no_end_date) { create(:scheme, end_date: nil) }

2
spec/models/validations/local_authority_validations_spec.rb

@ -4,7 +4,7 @@ RSpec.describe Validations::LocalAuthorityValidations do
subject(:local_auth_validator) { validator_class.new } subject(:local_auth_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::LocalAuthorityValidations } } let(:validator_class) { Class.new { include Validations::LocalAuthorityValidations } }
let(:log) { create(:lettings_log) } let(:log) { build(:lettings_log) }
describe "#validate_previous_accommodation_postcode" do describe "#validate_previous_accommodation_postcode" do
it "does not add an error if the log ppostcode_full is missing" do it "does not add an error if the log ppostcode_full is missing" do

2
spec/models/validations/sales/soft_validations_spec.rb

@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
RSpec.describe Validations::Sales::SoftValidations do RSpec.describe Validations::Sales::SoftValidations do
let(:record) { create(:sales_log) } let(:record) { build(:sales_log) }
describe "income1 min validations" do describe "income1 min validations" do
context "when validating soft min" do context "when validating soft min" do

4
spec/models/validations/setup_validations_spec.rb

@ -4,7 +4,7 @@ RSpec.describe Validations::SetupValidations do
subject(:setup_validator) { setup_validator_class.new } subject(:setup_validator) { setup_validator_class.new }
let(:setup_validator_class) { Class.new { include Validations::SetupValidations } } let(:setup_validator_class) { Class.new { include Validations::SetupValidations } }
let(:record) { create(:lettings_log) } let(:record) { build(:lettings_log) }
describe "tenancy start date" do describe "tenancy start date" do
context "when in 22/23 collection" do context "when in 22/23 collection" do
@ -853,7 +853,7 @@ RSpec.describe Validations::SetupValidations do
end end
context "when updating" do context "when updating" do
let(:log) { create(:lettings_log, :in_progress) } let(:log) { build(:lettings_log, :in_progress) }
let(:org_with_dpc) { create(:organisation) } let(:org_with_dpc) { create(:organisation) }
let(:org_without_dpc) { create(:organisation, :without_dpc) } let(:org_without_dpc) { create(:organisation, :without_dpc) }

6
spec/models/validations/tenancy_validations_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Validations::TenancyValidations do
let(:validator_class) { Class.new { include Validations::TenancyValidations } } let(:validator_class) { Class.new { include Validations::TenancyValidations } }
describe "tenancy length validations" do describe "tenancy length validations" do
let(:record) { FactoryBot.create(:lettings_log, :setup_completed) } let(:record) { FactoryBot.build(:lettings_log, :setup_completed) }
shared_examples "adds expected errors based on the tenancy length" do |tenancy_type_case, error_fields, min_tenancy_length| shared_examples "adds expected errors based on the tenancy length" do |tenancy_type_case, error_fields, min_tenancy_length|
context "and tenancy type is #{tenancy_type_case[:name]}" do context "and tenancy type is #{tenancy_type_case[:name]}" do
@ -276,7 +276,7 @@ RSpec.describe Validations::TenancyValidations do
end end
describe "tenancy type validations" do describe "tenancy type validations" do
let(:record) { FactoryBot.create(:lettings_log, :setup_completed) } let(:record) { FactoryBot.build(:lettings_log, :setup_completed) }
let(:field) { "validations.other_field_missing" } let(:field) { "validations.other_field_missing" }
let(:main_field_label) { "tenancy type" } let(:main_field_label) { "tenancy type" }
let(:other_field) { "tenancyother" } let(:other_field) { "tenancyother" }
@ -320,7 +320,7 @@ RSpec.describe Validations::TenancyValidations do
describe "joint tenancy validation" do describe "joint tenancy validation" do
context "when the data inputter has said that there is only one member in the household" do context "when the data inputter has said that there is only one member in the household" do
let(:record) { FactoryBot.create(:lettings_log, :setup_completed, hhmemb: 1) } let(:record) { FactoryBot.build(:lettings_log, :setup_completed, hhmemb: 1) }
let(:expected_error) { I18n.t("validations.tenancy.not_joint") } let(:expected_error) { I18n.t("validations.tenancy.not_joint") }
let(:hhmemb_expected_error) { I18n.t("validations.tenancy.joint_more_than_one_member") } let(:hhmemb_expected_error) { I18n.t("validations.tenancy.joint_more_than_one_member") }

2
spec/policies/user_policy_spec.rb

@ -201,7 +201,7 @@ RSpec.describe UserPolicy do
end end
context "and user is the DPO that hasn't signed the agreement" do context "and user is the DPO that hasn't signed the agreement" do
let(:user) { create(:user, active: false, is_dpo: true) } let(:user) { create(:user, active: false, is_dpo: true, with_dsa: false) }
it "does not allow deleting a user as a provider" do it "does not allow deleting a user as a provider" do
expect(policy).not_to permit(data_provider, user) expect(policy).not_to permit(data_provider, user)

2
spec/requests/bulk_upload_lettings_logs_controller_spec.rb

@ -13,7 +13,7 @@ RSpec.describe BulkUploadLettingsLogsController, type: :request do
describe "GET /lettings-logs/bulk-upload-logs/start" do describe "GET /lettings-logs/bulk-upload-logs/start" do
context "when data protection confirmation not signed" do context "when data protection confirmation not signed" do
let(:organisation) { create(:organisation, :without_dpc) } let(:organisation) { create(:organisation, :without_dpc) }
let(:user) { create(:user, organisation:) } let(:user) { create(:user, organisation:, with_dsa: false) }
it "redirects to lettings index page" do it "redirects to lettings index page" do
get "/lettings-logs/bulk-upload-logs/start", params: {} get "/lettings-logs/bulk-upload-logs/start", params: {}

2
spec/requests/bulk_upload_sales_logs_controller_spec.rb

@ -13,7 +13,7 @@ RSpec.describe BulkUploadSalesLogsController, type: :request do
describe "GET /sales-logs/bulk-upload-logs/start" do describe "GET /sales-logs/bulk-upload-logs/start" do
context "when data protection confirmation not signed" do context "when data protection confirmation not signed" do
let(:organisation) { create(:organisation, :without_dpc) } let(:organisation) { create(:organisation, :without_dpc) }
let(:user) { create(:user, organisation:) } let(:user) { create(:user, organisation:, with_dsa: false) }
it "redirects to sales index page" do it "redirects to sales index page" do
get "/sales-logs/bulk-upload-logs/start", params: {} get "/sales-logs/bulk-upload-logs/start", params: {}

3
spec/requests/organisations_controller_spec.rb

@ -1648,6 +1648,7 @@ RSpec.describe OrganisationsController, type: :request do
allow(notify_client).to receive(:send_email).and_return(true) allow(notify_client).to receive(:send_email).and_return(true)
user_to_reactivate = create(:user, :data_coordinator, organisation:, active: false, reactivate_with_organisation: true) user_to_reactivate = create(:user, :data_coordinator, organisation:, active: false, reactivate_with_organisation: true)
FactoryBot.create(:legacy_user, old_user_id: user_to_reactivate.old_user_id, user: user_to_reactivate)
user_not_to_reactivate = create(:user, :data_coordinator, organisation:, active: false, reactivate_with_organisation: false) user_not_to_reactivate = create(:user, :data_coordinator, organisation:, active: false, reactivate_with_organisation: false)
patch "/organisations/#{organisation.id}", headers:, params: patch "/organisations/#{organisation.id}", headers:, params:
end end
@ -2144,7 +2145,7 @@ RSpec.describe OrganisationsController, type: :request do
Timecop.unfreeze Timecop.unfreeze
end end
let(:user) { create(:user, is_dpo: true, organisation:) } let(:user) { create(:user, is_dpo: true, organisation:, with_dsa: false) }
it "returns redirects to details page" do it "returns redirects to details page" do
post "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers post "/organisations/#{organisation.id}/data-sharing-agreement", headers: headers

10
spec/requests/start_controller_spec.rb

@ -203,7 +203,7 @@ RSpec.describe StartController, type: :request do
it "shows the correct counts of logs created by them" do it "shows the correct counts of logs created by them" do
last_year_in_progress_count = 2 last_year_in_progress_count = 2
this_year_in_progress_count = 3 this_year_in_progress_count = 3
create_list(:lettings_log, last_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today - 1.year) create_list(:lettings_log, last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year)
create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today) create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today)
get root_path get root_path
@ -217,7 +217,7 @@ RSpec.describe StartController, type: :request do
end end
it "does not include logs created by other users in the count, whether in their organisation or not" do it "does not include logs created by other users in the count, whether in their organisation or not" do
create(:lettings_log, :in_progress, assigned_to: coordinator, startdate: Time.zone.today - 1.year) create(:lettings_log, :in_progress, :ignore_validation_errors, assigned_to: coordinator, startdate: Time.zone.today - 1.year)
create(:lettings_log, :in_progress, assigned_to: provider_2, startdate: Time.zone.today) create(:lettings_log, :in_progress, assigned_to: provider_2, startdate: Time.zone.today)
get root_path get root_path
@ -237,7 +237,7 @@ RSpec.describe StartController, type: :request do
it "shows the correct counts of logs created by all users in their organisation" do it "shows the correct counts of logs created by all users in their organisation" do
last_year_in_progress_count = 2 last_year_in_progress_count = 2
this_year_in_progress_count = 3 this_year_in_progress_count = 3
create_list(:lettings_log, last_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today - 1.year) create_list(:lettings_log, last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year)
create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today) create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today)
get root_path get root_path
@ -288,9 +288,9 @@ RSpec.describe StartController, type: :request do
coordinator_lettings_this_year_in_progress_count = 3 coordinator_lettings_this_year_in_progress_count = 3
provider_2_lettings_last_year_in_progress_count = 2 provider_2_lettings_last_year_in_progress_count = 2
provider_2_sales_this_year_in_progress_count = 3 provider_2_sales_this_year_in_progress_count = 3
create_list(:lettings_log, provider_1_lettings_last_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today - 1.year) create_list(:lettings_log, provider_1_lettings_last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year)
create_list(:lettings_log, coordinator_lettings_this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today) create_list(:lettings_log, coordinator_lettings_this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today)
create_list(:lettings_log, provider_2_lettings_last_year_in_progress_count, :in_progress, assigned_to: provider_2, startdate: Time.zone.today - 1.year) create_list(:lettings_log, provider_2_lettings_last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_2, startdate: Time.zone.today - 1.year)
create_list(:sales_log, provider_2_sales_this_year_in_progress_count, :in_progress, assigned_to: provider_2, saledate: Time.zone.today) create_list(:sales_log, provider_2_sales_this_year_in_progress_count, :in_progress, assigned_to: provider_2, saledate: Time.zone.today)
get root_path get root_path

6
spec/services/csv/sales_log_csv_service_spec.rb

@ -3,7 +3,7 @@ require "rails_helper"
RSpec.describe Csv::SalesLogCsvService do RSpec.describe Csv::SalesLogCsvService do
let(:form_handler_mock) { instance_double(FormHandler) } let(:form_handler_mock) { instance_double(FormHandler) }
let(:organisation) { create(:organisation) } let(:organisation) { create(:organisation) }
let(:fixed_time) { Time.zone.local(2023, 12, 8) } let(:fixed_time) { now }
let(:now) { Time.zone.now } let(:now) { Time.zone.now }
let(:user) { create(:user, :support, email: "billyboy@eyeKLAUD.com") } let(:user) { create(:user, :support, email: "billyboy@eyeKLAUD.com") }
let(:log) do let(:log) do
@ -134,6 +134,8 @@ RSpec.describe Csv::SalesLogCsvService do
context "when exporting with human readable labels" do context "when exporting with human readable labels" do
let(:year) { 2023 } let(:year) { 2023 }
let(:fixed_time) { Time.zone.local(2023, 12, 8) }
let(:now) { fixed_time }
it "gives answers to radio questions as their labels" do it "gives answers to radio questions as their labels" do
national_column_index = csv.first.index("NATIONAL") national_column_index = csv.first.index("NATIONAL")
@ -220,6 +222,8 @@ RSpec.describe Csv::SalesLogCsvService do
context "when exporting values as codes" do context "when exporting values as codes" do
let(:service) { described_class.new(user:, export_type: "codes", year:) } let(:service) { described_class.new(user:, export_type: "codes", year:) }
let(:year) { 2023 } let(:year) { 2023 }
let(:fixed_time) { Time.zone.local(2023, 12, 8) }
let(:now) { fixed_time }
it "gives answers to radio questions as their codes" do it "gives answers to radio questions as their codes" do
national_column_index = csv.first.index("NATIONAL") national_column_index = csv.first.index("NATIONAL")

2
spec/views/logs/_create_for_org_actions.html.erb_spec.rb

@ -20,7 +20,7 @@ RSpec.describe "logs/_create_for_org_actions.html.erb" do
end end
context "without data sharing agreement" do context "without data sharing agreement" do
let(:user) { create(:user, organisation: create(:organisation, :without_dpc)) } let(:user) { create(:user, organisation: create(:organisation, :without_dpc), with_dsa: false) }
it "does not include create log buttons" do it "does not include create log buttons" do
render render

2
spec/views/organisations/data_sharing_agreement.html.erb_spec.rb

@ -17,7 +17,7 @@ RSpec.describe "organisations/data_sharing_agreement.html.erb", :aggregate_failu
let(:data_protection_confirmation) { nil } let(:data_protection_confirmation) { nil }
context "when dpo" do context "when dpo" do
let(:user) { create(:user, is_dpo: true, organisation: create(:organisation, :without_dpc)) } let(:user) { create(:user, is_dpo: true, organisation: create(:organisation, :without_dpc), with_dsa: false) }
it "renders dynamic content" do it "renders dynamic content" do
render render

12
spec/views/organisations/show.html.erb_spec.rb

@ -11,7 +11,7 @@ RSpec.describe "organisations/show.html.erb" do
let(:organisation_with_dsa) { create(:organisation) } let(:organisation_with_dsa) { create(:organisation) }
context "when dpo" do context "when dpo" do
let(:user) { create(:user, is_dpo: true, organisation: organisation_without_dpc) } let(:user) { create(:user, is_dpo: true, organisation: organisation_without_dpc, with_dsa: false) }
it "includes data sharing agreement row" do it "includes data sharing agreement row" do
render render
@ -32,7 +32,7 @@ RSpec.describe "organisations/show.html.erb" do
end end
context "when accepted" do context "when accepted" do
let(:user) { create(:user, organisation: organisation_with_dsa) } let(:user) { create(:user, organisation: organisation_with_dsa, with_dsa: false) }
it "includes data sharing agreement row" do it "includes data sharing agreement row" do
render render
@ -55,7 +55,7 @@ RSpec.describe "organisations/show.html.erb" do
end end
context "when support user" do context "when support user" do
let(:user) { create(:user, :support, organisation: organisation_without_dpc) } let(:user) { create(:user, :support, organisation: organisation_without_dpc, with_dsa: false) }
it "includes data sharing agreement row" do it "includes data sharing agreement row" do
render render
@ -82,7 +82,7 @@ RSpec.describe "organisations/show.html.erb" do
end end
context "when accepted" do context "when accepted" do
let(:user) { create(:user, :support, organisation: organisation_with_dsa) } let(:user) { create(:user, :support, organisation: organisation_with_dsa, with_dsa: false) }
it "includes data sharing agreement row" do it "includes data sharing agreement row" do
render render
@ -125,7 +125,7 @@ RSpec.describe "organisations/show.html.erb" do
end end
context "when not dpo" do context "when not dpo" do
let(:user) { create(:user, organisation: organisation_without_dpc) } let(:user) { create(:user, organisation: organisation_without_dpc, with_dsa: false) }
it "includes data sharing agreement row" do it "includes data sharing agreement row" do
render render
@ -149,7 +149,7 @@ RSpec.describe "organisations/show.html.erb" do
end end
context "when accepted" do context "when accepted" do
let(:user) { create(:user, organisation: organisation_with_dsa) } let(:user) { create(:user, organisation: organisation_with_dsa, with_dsa: false) }
it "includes data sharing agreement row" do it "includes data sharing agreement row" do
render render

Loading…
Cancel
Save