Browse Source

feat: add tests (and add other missing ones to sales log controller spec)

pull/1768/head
natdeanlewissoftwire 3 years ago
parent
commit
571147aecd
  1. 26
      db/schema.rb
  2. 2
      db/seeds.rb
  3. 46
      spec/features/sales_log_spec.rb
  4. 6
      spec/requests/lettings_logs_controller_spec.rb
  5. 109
      spec/requests/sales_logs_controller_spec.rb

26
db/schema.rb

@ -186,14 +186,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_29_125541) do
t.integer "hb"
t.integer "hbrentshortfall"
t.integer "property_relet"
t.datetime "mrcdate", precision: nil
t.datetime "mrcdate"
t.integer "incref"
t.datetime "startdate", precision: nil
t.datetime "startdate"
t.integer "armedforces"
t.integer "first_time_property_let_as_social_housing"
t.integer "unitletas"
t.integer "builtype"
t.datetime "voiddate", precision: nil
t.datetime "voiddate"
t.bigint "owning_organisation_id"
t.bigint "managing_organisation_id"
t.integer "renttype"
@ -341,7 +341,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_29_125541) do
t.string "old_id"
t.string "old_visible_id"
t.string "mobility_type"
t.datetime "startdate", precision: nil
t.datetime "startdate"
t.string "location_admin_district"
t.boolean "confirmed"
t.index ["old_id"], name: "index_locations_on_old_id", unique: true
@ -512,7 +512,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_29_125541) do
t.integer "stairbought"
t.integer "stairowned"
t.decimal "mrent", precision: 10, scale: 2
t.datetime "exdate", precision: nil
t.datetime "exdate"
t.integer "exday"
t.integer "exmonth"
t.integer "exyear"
@ -548,7 +548,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_29_125541) do
t.integer "wchair"
t.integer "income2_value_check"
t.integer "armedforcesspouse"
t.datetime "hodate", precision: nil
t.datetime "hodate"
t.integer "hoday"
t.integer "homonth"
t.integer "hoyear"
@ -601,9 +601,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_29_125541) do
t.integer "discounted_sale_value_check"
t.integer "student_not_child_value_check"
t.integer "percentage_discount_value_check"
t.integer "combined_income_value_check"
t.integer "buyer_livein_value_check"
t.integer "status_cache", default: 0, null: false
t.integer "combined_income_value_check"
t.datetime "discarded_at"
t.integer "stairowned_value_check"
t.integer "creation_method", default: 1
@ -656,8 +656,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_29_125541) do
t.string "name"
t.bigint "organisation_id"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at", precision: nil
t.datetime "last_sign_in_at", precision: nil
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.integer "role"
@ -665,7 +665,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_29_125541) do
t.string "phone"
t.integer "failed_attempts", default: 0
t.string "unlock_token"
t.datetime "locked_at", precision: nil
t.datetime "locked_at"
t.boolean "is_dpo", default: false
t.boolean "is_key_contact", default: false
t.integer "second_factor_attempts_count", default: 0
@ -673,12 +673,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_29_125541) do
t.string "encrypted_otp_secret_key_iv"
t.string "encrypted_otp_secret_key_salt"
t.string "direct_otp"
t.datetime "direct_otp_sent_at", precision: nil
t.datetime "direct_otp_sent_at"
t.datetime "totp_timestamp", precision: nil
t.boolean "active", default: true
t.string "confirmation_token"
t.datetime "confirmed_at", precision: nil
t.datetime "confirmation_sent_at", precision: nil
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.boolean "initial_confirmation_sent"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true

2
db/seeds.rb

@ -169,7 +169,7 @@ unless Rails.env.test?
User.find_or_create_by!(
name: "Coordinator",
email: "coordinator@example.com",
email: "nat.dean-lewis@softwire.com",
organisation: org,
role: "data_coordinator",
) do |user|

46
spec/features/sales_log_spec.rb

@ -94,6 +94,52 @@ RSpec.describe "Sales Log Features" do
end
end
context "when filtering logs" do
let(:user) { create(:user, last_sign_in_at: Time.zone.now) }
context "when I am signed in" do
before do
visit("/sales-logs")
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: user.password)
click_button("Sign in")
end
context "when no filters are selected" do
it "displays the filters component with no clear button" do
expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear")
end
end
context "when I have selected filters" do
before do
check("Not started")
check("In progress")
choose("Yours")
click_button("Apply filters")
end
it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("3 filters applied")
expect(page).to have_content("Clear")
end
context "when clearing the filters" do
before do
click_link("Clear")
end
it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied")
expect(page).not_to have_content("Clear")
end
end
end
end
end
context "when signed in as a support user" do
let(:devise_notify_mailer) { DeviseNotifyMailer.new }
let(:notify_client) { instance_double(Notifications::Client) }

6
spec/requests/lettings_logs_controller_spec.rb

@ -498,6 +498,12 @@ RSpec.describe LettingsLogsController, type: :request do
expect(page).not_to have_content("Status")
end
it "has correct filter count and clear button" do
get "/lettings-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).to have_content("1 filter applied")
expect(page).to have_content("Clear")
end
it "hides button to create a new log" do
get "/lettings-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).not_to have_content("Create a new lettings log")

109
spec/requests/sales_logs_controller_spec.rb

@ -350,6 +350,115 @@ RSpec.describe SalesLogsController, type: :request do
expect(page).to have_link(sales_log_2023.id.to_s)
end
end
context "with bulk_upload_id filter" do
context "with bulk upload that belongs to current user" do
let(:organisation) { create(:organisation) }
let(:user) { create(:user, organisation:) }
let(:bulk_upload) { create(:bulk_upload, :sales, user:) }
let!(:included_log) { create(:sales_log, :in_progress, bulk_upload:, owning_organisation: organisation) }
let!(:excluded_log) { create(:sales_log, :in_progress, owning_organisation: organisation) }
it "returns logs only associated with the bulk upload" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).to have_content(included_log.id)
expect(page).not_to have_content(excluded_log.id)
end
it "dislays how many logs remaining to fix" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).to have_content("You need to fix 1 log")
end
it "displays filter" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).to have_content("With logs from bulk upload")
end
it "hides collection year filter" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).not_to have_content("Collection year")
end
it "hides status filter" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).not_to have_content("Status")
end
it "has correct filter count and clear button" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).to have_content("1 filter applied")
expect(page).to have_content("Clear")
end
it "hides button to create a new log" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).not_to have_content("Create a new sales log")
end
it "displays card with help info" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).to have_content("The following logs are from your recent bulk upload")
end
it "displays meta info about the bulk upload" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).to have_content(bulk_upload.filename)
expect(page).to have_content(bulk_upload.created_at.to_fs(:govuk_date_and_time))
end
end
context "with bulk upload that belongs to another user" do
let(:organisation) { create(:organisation) }
let(:user) { create(:user, organisation:) }
let(:other_user) { create(:user, organisation:) }
let(:bulk_upload) { create(:bulk_upload, :sales, user: other_user) }
let!(:excluded_log) { create(:sales_log, bulk_upload:, owning_organisation: organisation) }
let!(:also_excluded_log) { create(:sales_log, owning_organisation: organisation) }
it "does not return any logs" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(page).not_to have_content(excluded_log.id)
expect(page).not_to have_content(also_excluded_log.id)
end
end
context "when bulk upload has been resolved" do
let(:organisation) { create(:organisation) }
let(:user) { create(:user, organisation:) }
let(:bulk_upload) { create(:bulk_upload, :sales, user:) }
it "redirects to resume the bulk upload" do
get "/sales-logs?bulk_upload_id[]=#{bulk_upload.id}"
expect(response).to redirect_to(resume_bulk_upload_sales_result_path(bulk_upload))
end
end
end
context "without bulk_upload_id" do
it "does not display filter" do
get "/sales-logs"
expect(page).not_to have_content("With logs from bulk upload")
end
it "displays button to create a new log" do
get "/sales-logs"
expect(page).to have_content("Create a new sales log")
end
it "does not display card with help info" do
get "/sales-logs"
expect(page).not_to have_content("The following logs are from your recent bulk upload")
end
end
end
end

Loading…
Cancel
Save