Browse Source

Update specs

pull/968/head
Jack S 4 years ago
parent
commit
2d610fb4d4
  1. 1
      app/models/form/lettings/questions/housing_provider.rb
  2. 1
      app/models/form/lettings/questions/managing_organisation.rb
  3. 8
      db/schema.rb
  4. 23
      spec/features/lettings_log_spec.rb
  5. 24
      spec/models/form/lettings/questions/housing_provider_spec.rb
  6. 24
      spec/models/form/lettings/questions/managing_organisation_spec.rb
  7. 8
      spec/models/form_handler_spec.rb
  8. 40
      spec/requests/form_controller_spec.rb

1
app/models/form/lettings/questions/housing_provider.rb

@ -46,6 +46,7 @@ class Form::Lettings::Questions::HousingProvider < ::Form::Question
@current_user = user @current_user = user
return false unless @current_user return false unless @current_user
return false if @current_user.support?
# Hide when less than 2 housing providers # Hide when less than 2 housing providers
housing_providers.count < 2 housing_providers.count < 2

1
app/models/form/lettings/questions/managing_organisation.rb

@ -52,6 +52,7 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
@current_user = user @current_user = user
return false unless @current_user return false unless @current_user
return false if @current_user.support?
# Hide when less than 2 managing_agents # Hide when less than 2 managing_agents
managing_organisations.count < 2 managing_organisations.count < 2

8
db/schema.rb

@ -360,16 +360,16 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_11_102656) do
t.integer "hholdcount" t.integer "hholdcount"
t.integer "age3" t.integer "age3"
t.integer "age3_known" t.integer "age3_known"
t.string "la"
t.integer "la_known"
t.integer "income1"
t.integer "income1nk"
t.integer "age4" t.integer "age4"
t.integer "age4_known" t.integer "age4_known"
t.integer "age5" t.integer "age5"
t.integer "age5_known" t.integer "age5_known"
t.integer "age6" t.integer "age6"
t.integer "age6_known" t.integer "age6_known"
t.string "la"
t.integer "la_known"
t.integer "income1"
t.integer "income1nk"
t.integer "details_known_2" t.integer "details_known_2"
t.integer "details_known_3" t.integer "details_known_3"
t.integer "details_known_4" t.integer "details_known_4"

23
spec/features/lettings_log_spec.rb

@ -3,10 +3,10 @@ require "rails_helper"
RSpec.describe "Lettings Log Features" do RSpec.describe "Lettings Log Features" do
context "when searching for specific logs" do context "when searching for specific logs" do
context "when I am signed in and there are logs in the database" do context "when I am signed in and there are logs in the database" do
let(:user) { FactoryBot.create(:user, last_sign_in_at: Time.zone.now) } let(:user) { create(:user, last_sign_in_at: Time.zone.now) }
let!(:log_to_search) { FactoryBot.create(:lettings_log, owning_organisation: user.organisation) } let!(:log_to_search) { create(:lettings_log, owning_organisation: user.organisation) }
let!(:same_organisation_log) { FactoryBot.create(:lettings_log, owning_organisation: user.organisation) } let!(:same_organisation_log) { create(:lettings_log, owning_organisation: user.organisation) }
let!(:another_organisation_log) { FactoryBot.create(:lettings_log) } let!(:another_organisation_log) { create(:lettings_log) }
before do before do
visit("/lettings-logs") visit("/lettings-logs")
@ -58,7 +58,7 @@ RSpec.describe "Lettings Log Features" do
end end
context "when the signed is user is a Support user" do context "when the signed is user is a Support user" do
let(:support_user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now) } let(:support_user) { create(:user, :support, last_sign_in_at: Time.zone.now) }
let(:devise_notify_mailer) { DeviseNotifyMailer.new } let(:devise_notify_mailer) { DeviseNotifyMailer.new }
let(:notify_client) { instance_double(Notifications::Client) } let(:notify_client) { instance_double(Notifications::Client) }
let(:mfa_template_id) { User::MFA_TEMPLATE_ID } let(:mfa_template_id) { User::MFA_TEMPLATE_ID }
@ -77,26 +77,29 @@ RSpec.describe "Lettings Log Features" do
click_button("Submit") click_button("Submit")
end end
context "when completing the setup lettings log section" do context "when completing the setup lettings log section", :aggregate_failure do
it "includes the organisation and created by questions" do it "includes the organisation and created by questions" do
visit("/lettings-logs") visit("/lettings-logs")
click_button("Create a new lettings log") click_button("Create a new lettings log")
click_link("Set up this lettings log") click_link("Set up this lettings log")
select(support_user.organisation.name, from: "lettings-log-owning-organisation-id-field") select(support_user.organisation.name, from: "lettings-log-owning-organisation-id-field")
click_button("Save and continue") click_button("Save and continue")
select("#{support_user.organisation.name} (Owning organisation)", from: "lettings-log-managing-organisation-id-field")
click_button("Save and continue")
select(support_user.name, from: "lettings-log-created-by-id-field") select(support_user.name, from: "lettings-log-created-by-id-field")
click_button("Save and continue") click_button("Save and continue")
log_id = page.current_path.scan(/\d/).join log_id = page.current_path.scan(/\d/).join
visit("lettings-logs/#{log_id}/setup/check-answers") visit("lettings-logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Owning organisation #{support_user.organisation.name}") expect(page).to have_content("Housing provider #{support_user.organisation.name}")
expect(page).to have_content("User #{support_user.name}") expect(page).to have_content("Managing agent #{support_user.organisation.name}")
expect(page).to have_content("You have answered 2 of 8 questions") expect(page).to have_content("Log owner #{support_user.name}")
expect(page).to have_content("You have answered 3 of 9 questions")
end end
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
let(:support_user) { FactoryBot.create(:user) } let(:support_user) { create(:user) }
let(:devise_notify_mailer) { DeviseNotifyMailer.new } let(:devise_notify_mailer) { DeviseNotifyMailer.new }
let(:notify_client) { instance_double(Notifications::Client) } let(:notify_client) { instance_double(Notifications::Client) }

24
spec/models/form/lettings/questions/housing_provider_spec.rb

@ -83,21 +83,33 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
end end
describe "#hidden_in_check_answers?" do describe "#hidden_in_check_answers?" do
let(:user) { create(:user) } context "when housing providers < 2" do
context "when not support user" do
let(:user) { create(:user) }
context "when housing providers >= 2" do it "is hidden in check answers" do
it "is shown in check answers" do expect(question.hidden_in_check_answers?(nil, user)).to be true
expect(question.hidden_in_check_answers?(nil, user)).to be true end
end
context "when support" do
let(:user) { create(:user, :support) }
it "is not hiddes in check answers" do
expect(question.hidden_in_check_answers?(nil, user)).to be false
end
end end
end end
context "when housing providers < 2" do context "when housing providers >= 2" do
let(:user) { create(:user) }
before do before do
create(:organisation_relationship, :owning, child_organisation: user.organisation) create(:organisation_relationship, :owning, child_organisation: user.organisation)
create(:organisation_relationship, :owning, child_organisation: user.organisation) create(:organisation_relationship, :owning, child_organisation: user.organisation)
end end
it "is not shown in check answers" do it "is not hidden in check answers" do
expect(question.hidden_in_check_answers?(nil, user)).to be false expect(question.hidden_in_check_answers?(nil, user)).to be false
end end
end end

24
spec/models/form/lettings/questions/managing_organisation_spec.rb

@ -121,21 +121,33 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end end
describe "#hidden_in_check_answers?" do describe "#hidden_in_check_answers?" do
let(:user) { create(:user) } context "when housing providers < 2" do
context "when not support user" do
let(:user) { create(:user) }
context "when managing agents >= 2" do it "is hidden in check answers" do
it "is shown in check answers" do expect(question.hidden_in_check_answers?(nil, user)).to be true
expect(question.hidden_in_check_answers?(nil, user)).to be true end
end
context "when support" do
let(:user) { create(:user, :support) }
it "is not hiddes in check answers" do
expect(question.hidden_in_check_answers?(nil, user)).to be false
end
end end
end end
context "when managing agents < 2" do context "when managing agents >= 2" do
let(:user) { create(:user) }
before do before do
create(:organisation_relationship, :managing, parent_organisation: user.organisation) create(:organisation_relationship, :managing, parent_organisation: user.organisation)
create(:organisation_relationship, :managing, parent_organisation: user.organisation) create(:organisation_relationship, :managing, parent_organisation: user.organisation)
end end
it "is not shown in check answers" do it "is not hidden in check answers" do
expect(question.hidden_in_check_answers?(nil, user)).to be false expect(question.hidden_in_check_answers?(nil, user)).to be false
end end
end end

8
spec/models/form_handler_spec.rb

@ -27,13 +27,13 @@ RSpec.describe FormHandler do
it "is able to load a current lettings form" do it "is able to load a current lettings form" do
form = form_handler.get_form("current_lettings") form = form_handler.get_form("current_lettings")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(45) expect(form.pages.count).to eq(46)
end end
it "is able to load a next lettings form" do it "is able to load a next lettings form" do
form = form_handler.get_form("next_lettings") form = form_handler.get_form("next_lettings")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(12) expect(form.pages.count).to eq(13)
end end
end end
@ -49,13 +49,13 @@ RSpec.describe FormHandler do
it "is able to load a current lettings form" do it "is able to load a current lettings form" do
form = form_handler.get_form("current_lettings") form = form_handler.get_form("current_lettings")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(12) expect(form.pages.count).to eq(13)
end end
it "is able to load a previous lettings form" do it "is able to load a previous lettings form" do
form = form_handler.get_form("previous_lettings") form = form_handler.get_form("previous_lettings")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(45) expect(form.pages.count).to eq(46)
end end
it "is able to load a current sales form" do it "is able to load a current sales form" do

40
spec/requests/form_controller_spec.rb

@ -2,18 +2,18 @@ require "rails_helper"
RSpec.describe FormController, type: :request do RSpec.describe FormController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
let(:user) { FactoryBot.create(:user) } let(:user) { create(:user) }
let(:organisation) { user.organisation } let(:organisation) { user.organisation }
let(:other_organisation) { FactoryBot.create(:organisation) } let(:other_organisation) { create(:organisation) }
let!(:unauthorized_lettings_log) do let!(:unauthorized_lettings_log) do
FactoryBot.create( create(
:lettings_log, :lettings_log,
owning_organisation: other_organisation, owning_organisation: other_organisation,
managing_organisation: other_organisation, managing_organisation: other_organisation,
) )
end end
let(:setup_complete_lettings_log) do let(:setup_complete_lettings_log) do
FactoryBot.create( create(
:lettings_log, :lettings_log,
:about_completed, :about_completed,
status: 1, status: 1,
@ -23,7 +23,7 @@ RSpec.describe FormController, type: :request do
) )
end end
let(:completed_lettings_log) do let(:completed_lettings_log) do
FactoryBot.create( create(
:lettings_log, :lettings_log,
:completed, :completed,
owning_organisation: organisation, owning_organisation: organisation,
@ -39,7 +39,7 @@ RSpec.describe FormController, type: :request do
context "when a user is not signed in" do context "when a user is not signed in" do
let!(:lettings_log) do let!(:lettings_log) do
FactoryBot.create( create(
:lettings_log, :lettings_log,
owning_organisation: organisation, owning_organisation: organisation,
managing_organisation: organisation, managing_organisation: organisation,
@ -68,7 +68,7 @@ RSpec.describe FormController, type: :request do
context "when a user is signed in" do context "when a user is signed in" do
let!(:lettings_log) do let!(:lettings_log) do
FactoryBot.create( create(
:lettings_log, :lettings_log,
owning_organisation: organisation, owning_organisation: organisation,
managing_organisation: organisation, managing_organisation: organisation,
@ -83,8 +83,8 @@ RSpec.describe FormController, type: :request do
describe "GET" do describe "GET" do
context "with form pages" do context "with form pages" do
context "when forms exist for multiple years" do context "when forms exist for multiple years" do
let(:lettings_log_year_1) { FactoryBot.create(:lettings_log, startdate: Time.zone.local(2021, 5, 1), owning_organisation: organisation, created_by: user) } let(:lettings_log_year_1) { create(:lettings_log, startdate: Time.zone.local(2021, 5, 1), owning_organisation: organisation, created_by: user) }
let(:lettings_log_year_2) { FactoryBot.create(:lettings_log, :about_completed, startdate: Time.zone.local(2022, 5, 1), owning_organisation: organisation, created_by: user) } let(:lettings_log_year_2) { create(:lettings_log, :about_completed, startdate: Time.zone.local(2022, 5, 1), owning_organisation: organisation, created_by: user) }
it "displays the correct question details for each lettings log based on form year" do it "displays the correct question details for each lettings log based on form year" do
get "/lettings-logs/#{lettings_log_year_1.id}/tenant-code-test", headers: headers, params: {} get "/lettings-logs/#{lettings_log_year_1.id}/tenant-code-test", headers: headers, params: {}
@ -110,11 +110,11 @@ RSpec.describe FormController, type: :request do
context "when viewing the setup section schemes page" do context "when viewing the setup section schemes page" do
context "when the user is support" do context "when the user is support" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { create(:user, :support) }
context "when organisation and user have not been selected yet" do context "when organisation and user have not been selected yet" do
let(:lettings_log) do let(:lettings_log) do
FactoryBot.create( create(
:lettings_log, :lettings_log,
owning_organisation: nil, owning_organisation: nil,
managing_organisation: nil, managing_organisation: nil,
@ -124,7 +124,7 @@ RSpec.describe FormController, type: :request do
end end
before do before do
locations = FactoryBot.create_list(:location, 5) locations = create_list(:location, 5)
locations.each { |location| location.scheme.update!(arrangement_type: "The same organisation that owns the housing stock", managing_organisation_id: location.scheme.owning_organisation_id) } locations.each { |location| location.scheme.update!(arrangement_type: "The same organisation that owns the housing stock", managing_organisation_id: location.scheme.owning_organisation_id) }
end end
@ -147,7 +147,7 @@ RSpec.describe FormController, type: :request do
context "when no other sections are enabled" do context "when no other sections are enabled" do
let(:lettings_log_2022) do let(:lettings_log_2022) do
FactoryBot.create( create(
:lettings_log, :lettings_log,
startdate: Time.zone.local(2022, 12, 1), startdate: Time.zone.local(2022, 12, 1),
owning_organisation: organisation, owning_organisation: organisation,
@ -194,17 +194,17 @@ RSpec.describe FormController, type: :request do
context "when viewing a user dependent page" do context "when viewing a user dependent page" do
context "when the dependency is met" do context "when the dependency is met" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { create(:user, :support) }
it "routes to the page" do it "routes to the page" do
get "/lettings-logs/#{lettings_log.id}/organisation" get "/lettings-logs/#{lettings_log.id}/created-by"
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
end end
end end
context "when the dependency is not met" do context "when the dependency is not met" do
it "redirects to the tasklist page" do it "redirects to the tasklist page" do
get "/lettings-logs/#{lettings_log.id}/organisation" get "/lettings-logs/#{lettings_log.id}/created-by"
expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}") expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}")
end end
end end
@ -213,10 +213,10 @@ RSpec.describe FormController, type: :request do
describe "Submit Form" do describe "Submit Form" do
context "with a form page" do context "with a form page" do
let(:user) { FactoryBot.create(:user) } let(:user) { create(:user) }
let(:organisation) { user.organisation } let(:organisation) { user.organisation }
let(:lettings_log) do let(:lettings_log) do
FactoryBot.create( create(
:lettings_log, :lettings_log,
owning_organisation: organisation, owning_organisation: organisation,
managing_organisation: organisation, managing_organisation: organisation,
@ -527,9 +527,9 @@ RSpec.describe FormController, type: :request do
context "with lettings logs that are not owned or managed by your organisation" do context "with lettings logs that are not owned or managed by your organisation" do
let(:answer) { 25 } let(:answer) { 25 }
let(:other_organisation) { FactoryBot.create(:organisation) } let(:other_organisation) { create(:organisation) }
let(:unauthorized_lettings_log) do let(:unauthorized_lettings_log) do
FactoryBot.create( create(
:lettings_log, :lettings_log,
owning_organisation: other_organisation, owning_organisation: other_organisation,
managing_organisation: other_organisation, managing_organisation: other_organisation,

Loading…
Cancel
Save