add spec
This commit is contained in:
@@ -11,7 +11,7 @@ describe GenerateContractsZipJob do
|
|||||||
dir = Rails.root.join("spec", "fixtures", "files")
|
dir = Rails.root.join("spec", "fixtures", "files")
|
||||||
files = ["contract.pdf", "AppearanceRelease.pdf"]
|
files = ["contract.pdf", "AppearanceRelease.pdf"]
|
||||||
# Attachments in the test environment do not persist to cloud storage
|
# 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(:open).and_return(StringIO.new("file data"))
|
||||||
allow_any_instance_of(ReleaseContractCollectionService).to receive(:build).and_yield(dir, files)
|
allow_any_instance_of(ReleaseContractCollectionService).to receive(:build).and_yield(dir, files)
|
||||||
end
|
end
|
||||||
@@ -47,13 +47,22 @@ describe GenerateContractsZipJob do
|
|||||||
csv_file_name = "#{project.name.parameterize}_#{lowercase_plural.gsub('_', '-')}.csv"
|
csv_file_name = "#{project.name.parameterize}_#{lowercase_plural.gsub('_', '-')}.csv"
|
||||||
Zip::InputStream.open(StringIO.new(generated_zip)) do |io|
|
Zip::InputStream.open(StringIO.new(generated_zip)) do |io|
|
||||||
while entry = io.get_next_entry
|
while entry = io.get_next_entry
|
||||||
if entry.name == csv_file_name
|
next unless entry.name == csv_file_name
|
||||||
csv_file = entry.get_input_stream.read
|
|
||||||
release_class = Object.const_get @release_type
|
csv_file = entry.get_input_stream.read
|
||||||
headers = release_class.csv_headers
|
|
||||||
puts headers
|
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
|
||||||
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
|
||||||
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(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")
|
allow_any_instance_of(ReleaseContractCollectionService).to receive(:build).and_raise(StandardError, "Contracts or contract templates not found")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "updates status to 'failure' and sends user a notification" do
|
it "updates status to 'failure' and sends user a notification" do
|
||||||
GenerateContractsZipJob.perform_now(project, download, "AppearanceRelease", project.appearance_releases.ids)
|
GenerateContractsZipJob.perform_now(project, download, "AppearanceRelease", project.appearance_releases.ids)
|
||||||
|
|
||||||
expect(download.status).to eq "failure"
|
expect(download.status).to eq "failure"
|
||||||
expect(ProjectsChannel).to have_received(:broadcast_download_generation_update).with(download, I18n.t("contract_downloads.download.failure"))
|
expect(ProjectsChannel).to have_received(:broadcast_download_generation_update).with(download, I18n.t("contract_downloads.download.failure"))
|
||||||
end
|
end
|
||||||
@@ -82,7 +91,9 @@ describe GenerateContractsZipJob do
|
|||||||
# Delete the file created in fixture.
|
# Delete the file created in fixture.
|
||||||
# Or the tests will fail on next run due to already existing files in existing zip.
|
# Or the tests will fail on next run due to already existing files in existing zip.
|
||||||
path = Rails.root.join("spec", "fixtures", "files")
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
Reference in New Issue
Block a user