Browse Source

Move some tests to feature tests

pull/2678/head
Kat 2 years ago
parent
commit
5882ba249a
  1. 23
      spec/features/collection_resources_spec.rb
  2. 40
      spec/requests/collection_resources_controller_spec.rb

23
spec/features/collection_resources_spec.rb

@ -4,6 +4,7 @@ RSpec.describe "Collection resources" do
let(:user) { create(:user, :support) } let(:user) { create(:user, :support) }
before do before do
allow(UploadCollectionResourcesService).to receive(:upload_collection_resource)
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
end end
@ -28,6 +29,8 @@ RSpec.describe "Collection resources" do
click_button("Save changes") click_button("Save changes")
expect(page).not_to have_content("The paper form must be a PDF.") expect(page).not_to have_content("The paper form must be a PDF.")
expect(UploadCollectionResourcesService).to have_received(:upload_collection_resource).with("2024_25_lettings_paper_form.pdf", anything)
expect(page).to have_content("The lettings 2024 to 2025 paper form has been updated")
end end
it "only allows pdf files for sales" do it "only allows pdf files for sales" do
@ -49,6 +52,8 @@ RSpec.describe "Collection resources" do
click_button("Save changes") click_button("Save changes")
expect(page).not_to have_content("The paper form must be a PDF.") expect(page).not_to have_content("The paper form must be a PDF.")
expect(UploadCollectionResourcesService).to have_received(:upload_collection_resource).with("2024_25_sales_paper_form.pdf", anything)
expect(page).to have_content("The sales 2024 to 2025 paper form has been updated")
end end
end end
@ -72,6 +77,8 @@ RSpec.describe "Collection resources" do
click_button("Save changes") click_button("Save changes")
expect(page).not_to have_content("The bulk upload template must be a Microsoft Excel file.") expect(page).not_to have_content("The bulk upload template must be a Microsoft Excel file.")
expect(UploadCollectionResourcesService).to have_received(:upload_collection_resource).with("bulk-upload-lettings-template-2024-25.xlsx", anything)
expect(page).to have_content("The lettings 2024 to 2025 bulk upload template has been updated")
end end
it "only allows excel files for sales" do it "only allows excel files for sales" do
@ -93,6 +100,8 @@ RSpec.describe "Collection resources" do
click_button("Save changes") click_button("Save changes")
expect(page).not_to have_content("The bulk upload template must be a Microsoft Excel file.") expect(page).not_to have_content("The bulk upload template must be a Microsoft Excel file.")
expect(UploadCollectionResourcesService).to have_received(:upload_collection_resource).with("bulk-upload-sales-template-2024-25.xlsx", anything)
expect(page).to have_content("The sales 2024 to 2025 bulk upload template has been updated")
end end
end end
@ -116,6 +125,8 @@ RSpec.describe "Collection resources" do
click_button("Save changes") click_button("Save changes")
expect(page).not_to have_content("The bulk upload specification must be a Microsoft Excel file.") expect(page).not_to have_content("The bulk upload specification must be a Microsoft Excel file.")
expect(UploadCollectionResourcesService).to have_received(:upload_collection_resource).with("bulk-upload-lettings-specification-2024-25.xlsx", anything)
expect(page).to have_content("The lettings 2024 to 2025 bulk upload specification has been updated")
end end
it "only allows excel files for sales" do it "only allows excel files for sales" do
@ -137,6 +148,18 @@ RSpec.describe "Collection resources" do
click_button("Save changes") click_button("Save changes")
expect(page).not_to have_content("The bulk upload specification must be a Microsoft Excel file.") expect(page).not_to have_content("The bulk upload specification must be a Microsoft Excel file.")
expect(UploadCollectionResourcesService).to have_received(:upload_collection_resource).with("bulk-upload-sales-specification-2024-25.xlsx", anything)
expect(page).to have_content("The sales 2024 to 2025 bulk upload specification has been updated")
end
it "displays error message if the upload fails" do
allow(UploadCollectionResourcesService).to receive(:upload_collection_resource).and_raise(StandardError)
visit("/collection-resources/sales/2024/bulk_upload_specification/edit")
attach_file "file", file_fixture("excel_file.xlsx")
click_button("Save changes")
expect(page).to have_content("There was an error uploading this file.")
end end
end end
end end

40
spec/requests/collection_resources_controller_spec.rb

@ -293,45 +293,5 @@ RSpec.describe CollectionResourcesController, type: :request do
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end end
end end
context "when user is signed in as a support user" do
let(:user) { create(:user, :support) }
before do
allow(Time.zone).to receive(:today).and_return(Time.zone.local(2025, 1, 8))
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of(CollectionResourcesHelper).to receive(:editable_collection_resource_years).and_return([2024, 2025])
# rubocop:enable RSpec/AnyInstance
sign_in user
end
it "correcty updates a sales file" do
params = { collection_resource: { year: 2024, log_type: "sales", resource_type: "bulk_upload_template", file: some_file } }
patch update_mandatory_collection_resource_path, params: params
expect(response).to redirect_to(collection_resources_path)
expect(UploadCollectionResourcesService).to have_received(:upload_collection_resource).with("bulk-upload-sales-template-2024-25.xlsx", anything)
expect(flash[:notice]).to eq("The sales 2024 to 2025 bulk upload template has been updated")
end
it "correcty updates a lettings file" do
params = { collection_resource: { year: 2025, log_type: "lettings", resource_type: "paper_form", file: some_file } }
patch update_mandatory_collection_resource_path, params: params
expect(response).to redirect_to(collection_resources_path)
expect(UploadCollectionResourcesService).to have_received(:upload_collection_resource).with("2025_26_lettings_paper_form.pdf", anything)
expect(flash[:notice]).to eq("The lettings 2025 to 2026 paper form has been updated")
end
it "displays error message if the upload fails" do
allow(UploadCollectionResourcesService).to receive(:upload_collection_resource).and_raise(StandardError)
params = { collection_resource: { year: 2025, log_type: "lettings", resource_type: "paper_form", file: some_file } }
patch update_mandatory_collection_resource_path, params: params
expect(page).to have_content("There was an error uploading this file.")
end
end
end end
end end

Loading…
Cancel
Save