Files
old-holivud2/spec/controllers/casting_submission_downloads_controller_spec.rb
2020-07-17 04:50:04 +02:00

59 lines
3.0 KiB
Ruby

require "rails_helper"
RSpec.describe CastingSubmissionDownloadsController, type: :controller do
render_views
let(:current_user) { create(:user) }
let(:project) { create(:project, :discovery_client, account: current_user.primary_account) }
let(:casting_call) { create(:casting_call, project: project, title: "My Title") }
let(:casting_submission) { create(:casting_submission, casting_call: casting_call, performer_name: "John Doe") }
before do
sign_in current_user
end
describe "#create" do
it "enqueues zip file generation job" do
expect {
post :create, params: { project_id: project.id, casting_submission_id: casting_submission.id }, format: :js
}.to have_enqueued_job(GenerateCastingSubmissionFilesZipJob)
end
it "creates a download record with 'not_started' status" do
expect {
post :create, params: { project_id: project.id, casting_submission_id: casting_submission.id }, format: :js
}.to change(Download, :count).by(1)
expect(Download.last.status).to eq('not_started')
end
context "When there is no existing job" do
it "shows a notification to user" do
allow(ProjectsChannel).to receive(:broadcast_download_generation_update).with(be_kind_of(Download), I18n.t("casting_submission_downloads.download.pending", release_type: "CastingSubmission"))
post :create, params: { project_id: project.id, casting_submission_id: casting_submission.id }, format: :js
expect(ProjectsChannel).to have_received(:broadcast_download_generation_update).with(be_kind_of(Download), I18n.t("casting_submission_downloads.download.pending", release_type: "CastingSubmission"))
end
end
context "When there are existing jobs" do
let(:appearance_release_download) { create(:download, project_id: project.id, name: "#{project.name.parameterize}_appearance-releases") }
let(:acquired_media_release_download) { create(:download, project_id: project.id, name: "#{project.name.parameterize}_acquired-media-releases", release_type: "AcquiredMediaRelease") }
before do
allow(Download).to receive_message_chain(:unfinished_desc_order, :offset).and_return([acquired_media_release_download, appearance_release_download])
allow(ProjectsChannel).to receive(:broadcast_download_generation_update)
end
it "shows names of other contracts in the notification, which are in progress" do
broadcast_message = "<p>Your Casting Submission files are being prepared for download. You will be notified when it's ready.\n</p>\n<p class=\"mt-3\">The following downloads are also in progress:</p> \n<ul>\n <li>Acquired Media Release contracts (as of less than a minute ago)\n </li>\n <li>Appearance Release contracts (as of less than a minute ago)\n </li>\n</ul>\n"
post :create, params: { project_id: project.id, casting_submission_id: casting_submission.id }, format: :js
expect(ProjectsChannel).to have_received(:broadcast_download_generation_update).with(be_kind_of(Download), broadcast_message)
end
end
end
end