From e89d5d61022bee2b21615247ca208839968fdc14 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 17 Mar 2023 12:35:27 +0000 Subject: [PATCH] feat: uncomment out bulk tests --- .../bulk_upload_lettings_logs_spec.rb | 242 ++++++++--------- spec/features/bulk_upload_sales_logs_spec.rb | 170 ++++++------ spec/requests/bulk_upload_controller_spec.rb | 252 +++++++++--------- ...lk_upload_lettings_logs_controller_spec.rb | 116 ++++---- .../bulk_upload_sales_logs_controller_spec.rb | 116 ++++---- 5 files changed, 448 insertions(+), 448 deletions(-) diff --git a/spec/features/bulk_upload_lettings_logs_spec.rb b/spec/features/bulk_upload_lettings_logs_spec.rb index a7edc6ff5..939518ac9 100644 --- a/spec/features/bulk_upload_lettings_logs_spec.rb +++ b/spec/features/bulk_upload_lettings_logs_spec.rb @@ -1,121 +1,121 @@ -# require "rails_helper" -# -# RSpec.describe "Bulk upload lettings log" do -# let(:user) { create(:user) } -# -# let(:stub_file_upload) do -# vcap_services = { "aws-s3-bucket" => {} } -# mock_storage_service = instance_double("S3Service") -# -# allow(ENV).to receive(:[]) -# allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services.to_json) -# -# allow(Storage::S3Service).to receive(:new).and_return(mock_storage_service) -# allow(mock_storage_service).to receive(:write_file) -# end -# -# before do -# stub_file_upload -# sign_in user -# end -# -# # rubocop:disable RSpec/AnyInstance -# context "when during crossover period" do -# it "shows journey with year option" do -# Timecop.freeze(2022, 6, 1) do -# visit("/lettings-logs") -# expect(page).to have_link("Upload lettings logs in bulk") -# click_link("Upload lettings logs in bulk") -# -# expect(page).to have_content("Which year") -# click_button("Continue") -# -# expect(page).to have_content("You must select a collection period to upload for") -# choose("2022/2023") -# click_button("Continue") -# -# click_link("Back") -# -# expect(page.find_field("form-year-2022-field")).to be_checked -# click_button("Continue") -# -# expect(page).to have_content("Upload lettings logs in bulk (2022/23)") -# click_button("Continue") -# -# expect(page).to have_content("What is the needs type?") -# click_button("Continue") -# -# expect(page).to have_content("You must answer needs type") -# choose("General needs") -# click_button("Continue") -# -# click_link("Back") -# -# expect(page.find_field("form-needstype-1-field")).to be_checked -# click_button("Continue") -# -# expect(page).to have_content("Upload lettings logs in bulk (2022/23)") -# expect(page).to have_content("Upload your file") -# click_button("Upload") -# -# allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("not a csv") -# -# expect(page).to have_content("Select which file to upload") -# attach_file "file", file_fixture("2021_22_lettings_bulk_upload.xlsx") -# click_button("Upload") -# -# allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("text/csv") -# -# expect(page).to have_content("Your file must be in CSV format") -# attach_file "file", file_fixture("blank_bulk_upload_sales.csv") -# expect { -# click_button("Upload") -# }.to change(BulkUpload, :count).by(1) -# -# expect(page).to have_content("Once this is done") -# click_link("Back") -# -# expect(page).to have_content("Upload lettings logs in bulk") -# end -# end -# end -# # rubocop:enable RSpec/AnyInstance -# -# context "when not it crossover period" do -# it "shows journey with year option" do -# Timecop.freeze(2023, 10, 1) do -# visit("/lettings-logs") -# expect(page).to have_link("Upload lettings logs in bulk") -# click_link("Upload lettings logs in bulk") -# -# expect(page).to have_content("Upload lettings logs in bulk (2023/24)") -# click_button("Continue") -# -# expect(page).to have_content("Upload your file") -# end -# end -# end -# -# context "when the collection year isn't 22/23" do -# it "shows journey without the needstype" do -# Timecop.freeze(2023, 10, 1) do -# visit("/lettings-logs") -# expect(page).to have_link("Upload lettings logs in bulk") -# click_link("Upload lettings logs in bulk") -# -# expect(page).to have_content("Prepare your file") -# click_button("Continue") -# -# click_link("Back") -# -# expect(page).to have_content("Prepare your file") -# click_button("Continue") -# -# expect(page).to have_content("Upload lettings logs in bulk (2023/24)") -# -# expect(page).to have_content("Upload your file") -# click_button("Upload") -# end -# end -# end -# end +require "rails_helper" + +RSpec.describe "Bulk upload lettings log" do + let(:user) { create(:user) } + + let(:stub_file_upload) do + vcap_services = { "aws-s3-bucket" => {} } + mock_storage_service = instance_double("S3Service") + + allow(ENV).to receive(:[]) + allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services.to_json) + + allow(Storage::S3Service).to receive(:new).and_return(mock_storage_service) + allow(mock_storage_service).to receive(:write_file) + end + + before do + stub_file_upload + sign_in user + end + + # rubocop:disable RSpec/AnyInstance + context "when during crossover period" do + it "shows journey with year option" do + Timecop.freeze(2022, 6, 1) do + visit("/lettings-logs") + expect(page).to have_link("Upload lettings logs in bulk") + click_link("Upload lettings logs in bulk") + + expect(page).to have_content("Which year") + click_button("Continue") + + expect(page).to have_content("You must select a collection period to upload for") + choose("2022/2023") + click_button("Continue") + + click_link("Back") + + expect(page.find_field("form-year-2022-field")).to be_checked + click_button("Continue") + + expect(page).to have_content("Upload lettings logs in bulk (2022/23)") + click_button("Continue") + + expect(page).to have_content("What is the needs type?") + click_button("Continue") + + expect(page).to have_content("You must answer needs type") + choose("General needs") + click_button("Continue") + + click_link("Back") + + expect(page.find_field("form-needstype-1-field")).to be_checked + click_button("Continue") + + expect(page).to have_content("Upload lettings logs in bulk (2022/23)") + expect(page).to have_content("Upload your file") + click_button("Upload") + + allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("not a csv") + + expect(page).to have_content("Select which file to upload") + attach_file "file", file_fixture("2021_22_lettings_bulk_upload.xlsx") + click_button("Upload") + + allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("text/csv") + + expect(page).to have_content("Your file must be in CSV format") + attach_file "file", file_fixture("blank_bulk_upload_sales.csv") + expect { + click_button("Upload") + }.to change(BulkUpload, :count).by(1) + + expect(page).to have_content("Once this is done") + click_link("Back") + + expect(page).to have_content("Upload lettings logs in bulk") + end + end + end + # rubocop:enable RSpec/AnyInstance + + context "when not it crossover period" do + it "shows journey with year option" do + Timecop.freeze(2023, 10, 1) do + visit("/lettings-logs") + expect(page).to have_link("Upload lettings logs in bulk") + click_link("Upload lettings logs in bulk") + + expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + click_button("Continue") + + expect(page).to have_content("Upload your file") + end + end + end + + context "when the collection year isn't 22/23" do + it "shows journey without the needstype" do + Timecop.freeze(2023, 10, 1) do + visit("/lettings-logs") + expect(page).to have_link("Upload lettings logs in bulk") + click_link("Upload lettings logs in bulk") + + expect(page).to have_content("Prepare your file") + click_button("Continue") + + click_link("Back") + + expect(page).to have_content("Prepare your file") + click_button("Continue") + + expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + + expect(page).to have_content("Upload your file") + click_button("Upload") + end + end + end +end diff --git a/spec/features/bulk_upload_sales_logs_spec.rb b/spec/features/bulk_upload_sales_logs_spec.rb index 0d5f35564..e92b98a68 100644 --- a/spec/features/bulk_upload_sales_logs_spec.rb +++ b/spec/features/bulk_upload_sales_logs_spec.rb @@ -1,85 +1,85 @@ -# require "rails_helper" -# -# RSpec.describe "Bulk upload sales log" do -# let(:user) { create(:user) } -# -# let(:stub_file_upload) do -# vcap_services = { "aws-s3-bucket" => {} } -# mock_storage_service = instance_double("S3Service") -# -# allow(ENV).to receive(:[]) -# allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services.to_json) -# -# allow(Storage::S3Service).to receive(:new).and_return(mock_storage_service) -# allow(mock_storage_service).to receive(:write_file) -# end -# -# before do -# stub_file_upload -# sign_in user -# end -# -# # rubocop:disable RSpec/AnyInstance -# context "when during crossover period" do -# it "shows journey with year option" do -# Timecop.freeze(2023, 5, 1) do -# visit("/sales-logs") -# expect(page).to have_link("Upload sales logs in bulk") -# click_link("Upload sales logs in bulk") -# -# expect(page).to have_content("Which year") -# click_button("Continue") -# -# expect(page).to have_content("You must select a collection period to upload for") -# choose("2022/2023") -# click_button("Continue") -# -# click_link("Back") -# -# expect(page.find_field("form-year-2022-field")).to be_checked -# click_button("Continue") -# -# expect(page).to have_content("Upload sales logs in bulk (2022/23)") -# click_button("Continue") -# -# expect(page).to have_content("Upload your file") -# click_button("Upload") -# -# allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("not a csv") -# -# expect(page).to have_content("Select which file to upload") -# attach_file "file", file_fixture("2021_22_lettings_bulk_upload.xlsx") -# click_button("Upload") -# -# allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("text/csv") -# -# expect(page).to have_content("Your file must be in CSV format") -# attach_file "file", file_fixture("blank_bulk_upload_sales.csv") -# expect { -# click_button("Upload") -# }.to change(BulkUpload, :count).by(1) -# -# expect(page).to have_content("Once this is done") -# click_link("Back") -# -# expect(page).to have_content("Upload sales logs in bulk") -# end -# end -# end -# # rubocop:enable RSpec/AnyInstance -# -# context "when not it crossover period" do -# it "shows journey with year option" do -# Timecop.freeze(2023, 10, 1) do -# visit("/sales-logs") -# expect(page).to have_link("Upload sales logs in bulk") -# click_link("Upload sales logs in bulk") -# -# expect(page).to have_content("Upload sales logs in bulk (2023/24)") -# click_button("Continue") -# -# expect(page).to have_content("Upload your file") -# end -# end -# end -# end +require "rails_helper" + +RSpec.describe "Bulk upload sales log" do + let(:user) { create(:user) } + + let(:stub_file_upload) do + vcap_services = { "aws-s3-bucket" => {} } + mock_storage_service = instance_double("S3Service") + + allow(ENV).to receive(:[]) + allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services.to_json) + + allow(Storage::S3Service).to receive(:new).and_return(mock_storage_service) + allow(mock_storage_service).to receive(:write_file) + end + + before do + stub_file_upload + sign_in user + end + + # rubocop:disable RSpec/AnyInstance + context "when during crossover period" do + it "shows journey with year option" do + Timecop.freeze(2023, 5, 1) do + visit("/sales-logs") + expect(page).to have_link("Upload sales logs in bulk") + click_link("Upload sales logs in bulk") + + expect(page).to have_content("Which year") + click_button("Continue") + + expect(page).to have_content("You must select a collection period to upload for") + choose("2022/2023") + click_button("Continue") + + click_link("Back") + + expect(page.find_field("form-year-2022-field")).to be_checked + click_button("Continue") + + expect(page).to have_content("Upload sales logs in bulk (2022/23)") + click_button("Continue") + + expect(page).to have_content("Upload your file") + click_button("Upload") + + allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("not a csv") + + expect(page).to have_content("Select which file to upload") + attach_file "file", file_fixture("2021_22_lettings_bulk_upload.xlsx") + click_button("Upload") + + allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("text/csv") + + expect(page).to have_content("Your file must be in CSV format") + attach_file "file", file_fixture("blank_bulk_upload_sales.csv") + expect { + click_button("Upload") + }.to change(BulkUpload, :count).by(1) + + expect(page).to have_content("Once this is done") + click_link("Back") + + expect(page).to have_content("Upload sales logs in bulk") + end + end + end + # rubocop:enable RSpec/AnyInstance + + context "when not it crossover period" do + it "shows journey with year option" do + Timecop.freeze(2023, 10, 1) do + visit("/sales-logs") + expect(page).to have_link("Upload sales logs in bulk") + click_link("Upload sales logs in bulk") + + expect(page).to have_content("Upload sales logs in bulk (2023/24)") + click_button("Continue") + + expect(page).to have_content("Upload your file") + end + end + end +end diff --git a/spec/requests/bulk_upload_controller_spec.rb b/spec/requests/bulk_upload_controller_spec.rb index ad52eaca1..7aa0d16e0 100644 --- a/spec/requests/bulk_upload_controller_spec.rb +++ b/spec/requests/bulk_upload_controller_spec.rb @@ -1,126 +1,126 @@ -# require "rails_helper" -# -# RSpec.describe BulkUploadController, type: :request do -# let(:url) { "/lettings-logs/bulk-upload" } -# let(:user) { FactoryBot.create(:user) } -# let(:organisation) { user.organisation } -# let(:valid_file) { fixture_file_upload("2021_22_lettings_bulk_upload.xlsx", "application/vnd.ms-excel") } -# let(:invalid_file) { fixture_file_upload("random.txt", "text/plain") } -# let(:empty_file) { fixture_file_upload("2021_22_lettings_bulk_upload_empty.xlsx", "application/vnd.ms-excel") } -# -# before do -# allow(Organisation).to receive(:find).with(107_242).and_return(organisation) -# end -# -# context "when a user is not signed in" do -# describe "GET #start" do -# before { get start_bulk_upload_lettings_logs_path, headers:, params: {} } -# -# it "does not let you see the bulk upload page" do -# expect(response).to redirect_to("/account/sign-in") -# end -# end -# -# describe "GET #show" do -# before { get url, headers:, params: {} } -# -# it "does not let you see the bulk upload page" do -# expect(response).to redirect_to("/account/sign-in") -# end -# end -# -# describe "POST #bulk upload" do -# before { post url, params: { bulk_upload: { lettings_log_bulk_upload: valid_file } } } -# -# it "does not let you submit bulk uploads" do -# expect(response).to redirect_to("/account/sign-in") -# end -# end -# end -# -# context "when a user is signed in" do -# before do -# sign_in user -# end -# -# describe "GET #show" do -# before do -# get url, params: {} -# end -# -# it "returns a success response" do -# expect(response).to be_successful -# end -# -# it "returns a page with a file upload form" do -# expect(response.body).to match(/