This commit is contained in:
Bilal
2020-07-09 23:25:21 +02:00
parent ebc13242de
commit e0cf5ba875

View File

@@ -11,7 +11,7 @@ describe GenerateContractsZipJob do
dir = Rails.root.join("spec", "fixtures", "files")
files = ["contract.pdf", "AppearanceRelease.pdf"]
# Attachments in the test environment do not persist to cloud storage
# Therefore we want to stub calls to `open` with a cloud storage URL
# Therefore we want to stub calls to `open` with a cloud storage URL
allow_any_instance_of(ReleaseContractCollectionService).to receive(:open).and_return(StringIO.new("file data"))
allow_any_instance_of(ReleaseContractCollectionService).to receive(:build).and_yield(dir, files)
end
@@ -47,13 +47,22 @@ describe GenerateContractsZipJob do
csv_file_name = "#{project.name.parameterize}_#{lowercase_plural.gsub('_', '-')}.csv"
Zip::InputStream.open(StringIO.new(generated_zip)) do |io|
while entry = io.get_next_entry
if entry.name == csv_file_name
csv_file = entry.get_input_stream.read
release_class = Object.const_get @release_type
headers = release_class.csv_headers
puts headers
next unless entry.name == csv_file_name
csv_file = entry.get_input_stream.read
release_class = Object.const_get type
release_headers = release_class.csv_headers
release_headers.each do |header|
expect(csv_file).to match header
end
end
dummy_zip_file_name = "#{project.name.parameterize}_#{lowercase_plural.gsub('_', '-')}.zip"
if File.exist?(file_fixture(dummy_zip_file_name))
File.delete(file_fixture(dummy_zip_file_name))
end
end
end
@@ -68,10 +77,10 @@ describe GenerateContractsZipJob do
allow(ProjectsChannel).to receive(:broadcast_download_generation_update).with(download, I18n.t("contract_downloads.download.failure"))
allow_any_instance_of(ReleaseContractCollectionService).to receive(:build).and_raise(StandardError, "Contracts or contract templates not found")
end
it "updates status to 'failure' and sends user a notification" do
GenerateContractsZipJob.perform_now(project, download, "AppearanceRelease", project.appearance_releases.ids)
expect(download.status).to eq "failure"
expect(ProjectsChannel).to have_received(:broadcast_download_generation_update).with(download, I18n.t("contract_downloads.download.failure"))
end
@@ -82,7 +91,9 @@ describe GenerateContractsZipJob do
# Delete the file created in fixture.
# Or the tests will fail on next run due to already existing files in existing zip.
path = Rails.root.join("spec", "fixtures", "files")
File.delete("#{path}/my-video-project_appearance-releases.zip") if File.exists? "#{path}/my-video-project_appearance-releases.zip"
if File.exists? "#{path}/my-video-project_appearance-releases.zip"
File.delete("#{path}/my-video-project_appearance-releases.zip")
end
end
private