From 3f889fc741cfaeb2ba17e52c091877afdd36e0fc Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 9 Oct 2024 15:12:04 +0100 Subject: [PATCH] Rebase changes --- app/services/storage/local_disk_service.rb | 6 ++++++ ...onfirm_mandatory_collection_resources_release.erb | 2 +- config/locales/en.yml | 9 ++++++++- spec/helpers/collection_resources_helper_spec.rb | 6 ++---- spec/request_helper.rb | 3 --- .../requests/collection_resources_controller_spec.rb | 12 ++++++++---- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/services/storage/local_disk_service.rb b/app/services/storage/local_disk_service.rb index c97e59c94..bb5825340 100644 --- a/app/services/storage/local_disk_service.rb +++ b/app/services/storage/local_disk_service.rb @@ -37,5 +37,11 @@ module Storage "content_type" => MiniMime.lookup_by_filename(path.to_s)&.content_type || "application/octet-stream", } end + + def file_exists?(filename) + path = Rails.root.join("tmp/storage", filename) + + File.exist?(path) + end end end diff --git a/app/views/collection_resources/confirm_mandatory_collection_resources_release.erb b/app/views/collection_resources/confirm_mandatory_collection_resources_release.erb index e5da8d58a..1218e1d0d 100644 --- a/app/views/collection_resources/confirm_mandatory_collection_resources_release.erb +++ b/app/views/collection_resources/confirm_mandatory_collection_resources_release.erb @@ -2,7 +2,7 @@ <% content_for :title, "Are you sure you want to release the #{text_year_range_format(@year)} collection resources?" %> <%= govuk_back_link(href: collection_resources_path) %> <% end %> -<% binding.pry %> +

diff --git a/config/locales/en.yml b/config/locales/en.yml index d7f27a54e..7aef84fea 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -207,7 +207,14 @@ en: blank_when_additional_page_set: "Enter the link text." page_content: blank_when_additional_page_set: "Enter the page content." - + collection_resource: + attributes: + file: + error_uploading: There was an error uploading this file. + blank: Select which file to upload. + above_100_mb: The file is above 100MB. + must_be_pdf: The paper form must be a PDF. + must_be_xlsx: The %{resource} must be a Microsoft Excel file. notification: logs_deleted: one: "%{count} log has been deleted." diff --git a/spec/helpers/collection_resources_helper_spec.rb b/spec/helpers/collection_resources_helper_spec.rb index 2bdde8cd2..859d14cd1 100644 --- a/spec/helpers/collection_resources_helper_spec.rb +++ b/spec/helpers/collection_resources_helper_spec.rb @@ -217,8 +217,7 @@ RSpec.describe CollectionResourcesHelper do context "when all the mandatory resources for next year are uploaded" do before do - WebMock.stub_request(:head, /https:\/\/core-test-collection-resources\.s3\.amazonaws\.com/) - .to_return(status: 200, body: "", headers: { "Content-Length" => 292_864, "Content-Type" => "application/pdf" }) + allow(storage_service).to receive(:file_exists?).and_return(true) end it "returns correct text" do @@ -228,8 +227,7 @@ RSpec.describe CollectionResourcesHelper do context "when some of the mandatory resources for next year are not uploaded" do before do - WebMock.stub_request(:head, /https:\/\/core-test-collection-resources\.s3\.amazonaws\.com/) - .to_return(status: 404, body: "", headers: { "Content-Length" => 292_864, "Content-Type" => "application/pdf" }) + allow(storage_service).to receive(:file_exists?).and_return(false) end it "returns correct text" do diff --git a/spec/request_helper.rb b/spec/request_helper.rb index e8a6726e9..f1f208ec6 100644 --- a/spec/request_helper.rb +++ b/spec/request_helper.rb @@ -103,9 +103,6 @@ module RequestHelper address = request.uri.query_values["query"].split(",") { status: 200, body: { results: [{ DPA: { MATCH: 0.9, BUILDING_NAME: "result #{address[0]}", POST_TOWN: "result town or city", POSTCODE: address[1], UPRN: "1" } }] }.to_json, headers: {} } end - - WebMock.stub_request(:head, /https:\/\/core-test-collection-resources\.s3\.amazonaws\.com/) - .to_return(status: 200, body: "", headers: { "Content-Type" => "application/pdf", "Content-Length" => 1000 }) end def self.real_http_requests diff --git a/spec/requests/collection_resources_controller_spec.rb b/spec/requests/collection_resources_controller_spec.rb index e79867e09..7c9bb0f05 100644 --- a/spec/requests/collection_resources_controller_spec.rb +++ b/spec/requests/collection_resources_controller_spec.rb @@ -111,7 +111,7 @@ RSpec.describe CollectionResourcesController, type: :request do it "displays next year banner" do expect(page).to have_content("The 2025 to 2026 collection resources are not yet available to users.") - expect(page).to have_link("Release the 2025 to 2026 collection resources to users", href: confirm_mandatory_collection_resources_release(year: 2025)) + expect(page).to have_link("Release the 2025 to 2026 collection resources to users", href: confirm_mandatory_collection_resources_release_path(year: 2025)) end end @@ -267,6 +267,10 @@ RSpec.describe CollectionResourcesController, type: :request do end context "and the file exists on S3" do + before do + allow(storage_service).to receive(:file_exists?).and_return(true) + end + it "displays update collection resources page content" do get edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template") @@ -282,8 +286,7 @@ RSpec.describe CollectionResourcesController, type: :request do context "and the file does not exist on S3" do before do - WebMock.stub_request(:head, /https:\/\/core-test-collection-resources\.s3\.amazonaws\.com/) - .to_return(status: 404, body: "", headers: {}) + allow(storage_service).to receive(:file_exists?).and_return(false) end it "displays upload collection resources page content" do @@ -404,9 +407,10 @@ RSpec.describe CollectionResourcesController, type: :request do describe "PATCH #release_mandatory_collection_resources_path" do let(:some_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) } + let(:collection_resource_service) { instance_double(CollectionResourcesService) } before do - allow(UploadCollectionResourcesService).to receive(:upload_collection_resource) + allow(CollectionResourcesService).to receive(:new).and_return(collection_resource_service) end context "when user is not signed in" do