Cast me
This commit is contained in:
@@ -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
|
||||
@@ -35,38 +35,6 @@ describe GenerateContractsZipJob do
|
||||
expect(download.file).to be_attached
|
||||
end
|
||||
|
||||
it "generates ZIP containing CSV file with all releases data for all release types" do
|
||||
release_types = %w[AcquiredMediaRelease AppearanceRelease LocationRelease MaterialRelease MedicalRelease MiscRelease MusicRelease TalentRelease]
|
||||
create_releases_for_all_types
|
||||
|
||||
release_types.each do |type|
|
||||
lowercase_plural = type.constantize.model_name.plural
|
||||
GenerateContractsZipJob.perform_now(project, download, type, project.public_send(lowercase_plural).ids)
|
||||
|
||||
generated_zip = download.file.blob.download
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
context "When there are errors" do
|
||||
let(:error) { StandardError.new("Contracts or contract templates not found.") }
|
||||
|
||||
@@ -74,10 +42,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
|
||||
@@ -88,21 +56,6 @@ 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")
|
||||
if File.exists? "#{path}/my-video-project_appearance-releases.zip"
|
||||
File.delete("#{path}/my-video-project_appearance-releases.zip")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_releases_for_all_types
|
||||
create(:acquired_media_release_with_contract_template, :native, project: project)
|
||||
create(:appearance_release_with_contract_template, :native, project: project, person_name: "John Doe")
|
||||
create(:location_release_with_contract_template, :native, project: project)
|
||||
create(:material_release_with_contract_template, :native, project: project)
|
||||
create(:medical_release_with_contract_template, :native, project: project)
|
||||
create(:misc_release_with_contract_template, :native, project: project)
|
||||
create(:music_release_with_contract_template, project: project)
|
||||
create(:talent_release_with_contract_template, :native, project: project)
|
||||
File.delete("#{path}/my-video-project_appearance-releases.zip") if File.exists? "#{path}/my-video-project_appearance-releases.zip"
|
||||
end
|
||||
end
|
||||
|
||||
60
spec/jobs/generate_interview_files_zip_job_spec.rb
Normal file
60
spec/jobs/generate_interview_files_zip_job_spec.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe GenerateInterviewFilesZipJob do
|
||||
let(:project) { create(:project) }
|
||||
let(:download) { create(:download, project: project, release_type: "CastingCallInterview", name: "my-title_john-doe") }
|
||||
let(:casting_call) { create(:casting_call, project: project, title: "My Title") }
|
||||
let(:casting_call_interview) { create(:casting_call_interview, casting_call: casting_call, performer_name: "John Doe") }
|
||||
|
||||
before 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
|
||||
allow_any_instance_of(InterviewFilesCollectionService).to receive(:open).and_return(StringIO.new("file data"))
|
||||
allow_any_instance_of(InterviewFilesCollectionService).to receive(:build).and_yield(dir, files)
|
||||
end
|
||||
|
||||
describe ".perform_later" do
|
||||
it "enqueues a background job for generating zip file" do
|
||||
expect {
|
||||
GenerateInterviewFilesZipJob.perform_later(project, download, casting_call_interview)
|
||||
}.to have_enqueued_job
|
||||
end
|
||||
end
|
||||
|
||||
describe ".perform_now" do
|
||||
it "updates a download record and creates attachment for it" do
|
||||
GenerateInterviewFilesZipJob.perform_now(project, download, casting_call_interview)
|
||||
|
||||
expect(download.project).to eq project
|
||||
expect(download.release_type).to eq "CastingCallInterview"
|
||||
expect(download.name).to eq "my-title_john-doe"
|
||||
expect(download.status).to eq "success"
|
||||
expect(download.file).to be_attached
|
||||
end
|
||||
|
||||
context "When there are errors" do
|
||||
let(:error) { StandardError.new("Casting Call Interview files not found.") }
|
||||
|
||||
before do
|
||||
allow(ProjectsChannel).to receive(:broadcast_download_generation_update).with(download, I18n.t("interview_downloads.download.failure"))
|
||||
allow_any_instance_of(InterviewFilesCollectionService).to receive(:build).and_raise(StandardError, "Casting Call Interview files not found.")
|
||||
end
|
||||
|
||||
it "updates status to 'failure' and sends user a notification" do
|
||||
GenerateInterviewFilesZipJob.perform_now(project, download, casting_call_interview)
|
||||
|
||||
expect(download.status).to eq "failure"
|
||||
expect(ProjectsChannel).to have_received(:broadcast_download_generation_update).with(download, I18n.t("interview_downloads.download.failure"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
after 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-title_john-doe.zip") if File.exists? "#{path}/my-title_john-doe.zip"
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@ RSpec.describe SubmitHubspotFormJob, type: :job do
|
||||
allow(Hubspot::Form).to receive(:new).and_return(form)
|
||||
allow(form).to receive(:submit).and_return(true)
|
||||
|
||||
SubmitHubspotFormJob.perform_now("John", "Doe", "email@test.com", "My Account")
|
||||
SubmitHubspotFormJob.perform_now(first_name: "John", last_name: "Doe", email: "email@test.com", company: "My Account", form_guid: ENV["HUBSPOT_FORM_GUID"])
|
||||
|
||||
expect(Hubspot::Form).to have_received(:new).with("guid" => "hubspot_form_guid")
|
||||
expect(form).to have_received(:submit).with(
|
||||
@@ -27,7 +27,7 @@ RSpec.describe SubmitHubspotFormJob, type: :job do
|
||||
allow(Hubspot::Form).to receive(:new).and_return(form)
|
||||
allow(form).to receive(:submit).and_return(true)
|
||||
|
||||
SubmitHubspotFormJob.perform_now("John", "Doe", "email@test.com", "My Account", additional_param_one: "Foo", additional_param_two: "Bar")
|
||||
SubmitHubspotFormJob.perform_now(first_name: "John", last_name: "Doe", email: "email@test.com", company: "My Account", form_guid: ENV["HUBSPOT_FORM_GUID"], additional_param_one: "Foo", additional_param_two: "Bar")
|
||||
|
||||
expect(form).to have_received(:submit).with(
|
||||
first_name: "John",
|
||||
@@ -35,7 +35,7 @@ RSpec.describe SubmitHubspotFormJob, type: :job do
|
||||
email: "email@test.com",
|
||||
company: "My Account",
|
||||
additional_param_one: "Foo",
|
||||
additional_param_two: "Bar",
|
||||
additional_param_two: "Bar"
|
||||
)
|
||||
end
|
||||
|
||||
@@ -46,7 +46,7 @@ RSpec.describe SubmitHubspotFormJob, type: :job do
|
||||
allow(Hubspot::Form).to receive(:new).and_return(form)
|
||||
allow(form).to receive(:submit)
|
||||
|
||||
SubmitHubspotFormJob.perform_now("John", "Doe", "email@test.com", "My Account")
|
||||
SubmitHubspotFormJob.perform_now(first_name: "John", last_name: "Doe", email: "email@test.com", company: "My Account", form_guid: ENV["HUBSPOT_FORM_GUID"])
|
||||
|
||||
expect(form).not_to have_received(:submit)
|
||||
end
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SubmitHubspotTaskRequestFormJob, type: :job do
|
||||
describe '#perform_now' do
|
||||
before do
|
||||
ENV["HUBSPOT_TASK_REQUEST_FORM_GUID"] = "hubspot_task_request_form_guid"
|
||||
end
|
||||
|
||||
it 'submits to the Hubspot API with the right params' do
|
||||
form = double(:form)
|
||||
allow(Hubspot::Form).to receive(:new).and_return(form)
|
||||
allow(form).to receive(:submit).and_return(true)
|
||||
|
||||
SubmitHubspotTaskRequestFormJob.perform_now("email@test.com", "https://example.com/admin/task_requests/1")
|
||||
|
||||
expect(Hubspot::Form).to have_received(:new).with("guid" => "hubspot_task_request_form_guid")
|
||||
expect(form).to have_received(:submit).with(
|
||||
email: "email@test.com",
|
||||
taskme_url: "https://example.com/admin/task_requests/1"
|
||||
)
|
||||
end
|
||||
|
||||
context 'when HUBSPOT_TASK_REQUEST_FORM_GUID is not available' do
|
||||
it 'does not submit to the API' do
|
||||
ENV["HUBSPOT_TASK_REQUEST_FORM_GUID"] = nil
|
||||
form = double(:form)
|
||||
allow(Hubspot::Form).to receive(:new).and_return(form)
|
||||
allow(form).to receive(:submit)
|
||||
|
||||
SubmitHubspotTaskRequestFormJob.perform_now("email@test.com", "https://example.com/admin/task_requests/1")
|
||||
|
||||
expect(form).not_to have_received(:submit)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user