Browse Source

Rebase changes

pull/2683/head
Kat 2 years ago
parent
commit
3f889fc741
  1. 6
      app/services/storage/local_disk_service.rb
  2. 2
      app/views/collection_resources/confirm_mandatory_collection_resources_release.erb
  3. 9
      config/locales/en.yml
  4. 6
      spec/helpers/collection_resources_helper_spec.rb
  5. 3
      spec/request_helper.rb
  6. 12
      spec/requests/collection_resources_controller_spec.rb

6
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", "content_type" => MiniMime.lookup_by_filename(path.to_s)&.content_type || "application/octet-stream",
} }
end end
def file_exists?(filename)
path = Rails.root.join("tmp/storage", filename)
File.exist?(path)
end
end end
end end

2
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?" %> <% 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) %> <%= govuk_back_link(href: collection_resources_path) %>
<% end %> <% end %>
<% binding.pry %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop"> <div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-xl"> <h1 class="govuk-heading-xl">

9
config/locales/en.yml

@ -207,7 +207,14 @@ en:
blank_when_additional_page_set: "Enter the link text." blank_when_additional_page_set: "Enter the link text."
page_content: page_content:
blank_when_additional_page_set: "Enter the 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: notification:
logs_deleted: logs_deleted:
one: "%{count} log has been deleted." one: "%{count} log has been deleted."

6
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 context "when all the mandatory resources for next year are uploaded" do
before do before do
WebMock.stub_request(:head, /https:\/\/core-test-collection-resources\.s3\.amazonaws\.com/) allow(storage_service).to receive(:file_exists?).and_return(true)
.to_return(status: 200, body: "", headers: { "Content-Length" => 292_864, "Content-Type" => "application/pdf" })
end end
it "returns correct text" do 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 context "when some of the mandatory resources for next year are not uploaded" do
before do before do
WebMock.stub_request(:head, /https:\/\/core-test-collection-resources\.s3\.amazonaws\.com/) allow(storage_service).to receive(:file_exists?).and_return(false)
.to_return(status: 404, body: "", headers: { "Content-Length" => 292_864, "Content-Type" => "application/pdf" })
end end
it "returns correct text" do it "returns correct text" do

3
spec/request_helper.rb

@ -103,9 +103,6 @@ module RequestHelper
address = request.uri.query_values["query"].split(",") 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: {} } { 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 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 end
def self.real_http_requests def self.real_http_requests

12
spec/requests/collection_resources_controller_spec.rb

@ -111,7 +111,7 @@ RSpec.describe CollectionResourcesController, type: :request do
it "displays next year banner" 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_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
end end
@ -267,6 +267,10 @@ RSpec.describe CollectionResourcesController, type: :request do
end end
context "and the file exists on S3" do 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 it "displays update collection resources page content" do
get edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template") 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 context "and the file does not exist on S3" do
before do before do
WebMock.stub_request(:head, /https:\/\/core-test-collection-resources\.s3\.amazonaws\.com/) allow(storage_service).to receive(:file_exists?).and_return(false)
.to_return(status: 404, body: "", headers: {})
end end
it "displays upload collection resources page content" do 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 describe "PATCH #release_mandatory_collection_resources_path" do
let(:some_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) } let(:some_file) { File.open(file_fixture("blank_bulk_upload_sales.csv")) }
let(:collection_resource_service) { instance_double(CollectionResourcesService) }
before do before do
allow(UploadCollectionResourcesService).to receive(:upload_collection_resource) allow(CollectionResourcesService).to receive(:new).and_return(collection_resource_service)
end end
context "when user is not signed in" do context "when user is not signed in" do

Loading…
Cancel
Save