2020-07-15 11:57:21 +02:00
require " rails_helper "
2020-07-17 04:50:04 +02:00
RSpec . describe CastingSubmissionDownloadsController , type : :controller do
2020-07-15 11:57:21 +02:00
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 " ) }
2020-07-17 04:50:04 +02:00
let ( :casting_submission ) { create ( :casting_submission , casting_call : casting_call , performer_name : " John Doe " ) }
2020-07-15 11:57:21 +02:00
before do
sign_in current_user
end
describe " # create " do
it " enqueues zip file generation job " do
expect {
2020-07-17 04:50:04 +02:00
post :create , params : { project_id : project . id , casting_submission_id : casting_submission . id } , format : :js
} . to have_enqueued_job ( GenerateCastingSubmissionFilesZipJob )
2020-07-15 11:57:21 +02:00
end
it " creates a download record with 'not_started' status " do
expect {
2020-07-17 04:50:04 +02:00
post :create , params : { project_id : project . id , casting_submission_id : casting_submission . id } , format : :js
2020-07-15 11:57:21 +02:00
} . 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
2020-07-17 04:50:04 +02:00
allow ( ProjectsChannel ) . to receive ( :broadcast_download_generation_update ) . with ( be_kind_of ( Download ) , I18n . t ( " casting_submission_downloads.download.pending " , release_type : " CastingSubmission " ) )
2020-07-15 11:57:21 +02:00
2020-07-17 04:50:04 +02:00
post :create , params : { project_id : project . id , casting_submission_id : casting_submission . id } , format : :js
2020-07-15 11:57:21 +02:00
2020-07-17 04:50:04 +02:00
expect ( ProjectsChannel ) . to have_received ( :broadcast_download_generation_update ) . with ( be_kind_of ( Download ) , I18n . t ( " casting_submission_downloads.download.pending " , release_type : " CastingSubmission " ) )
2020-07-15 11:57:21 +02:00
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
2020-07-17 04:50:04 +02:00
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 "
2020-07-15 11:57:21 +02:00
2020-07-17 04:50:04 +02:00
post :create , params : { project_id : project . id , casting_submission_id : casting_submission . id } , format : :js
2020-07-15 11:57:21 +02:00
expect ( ProjectsChannel ) . to have_received ( :broadcast_download_generation_update ) . with ( be_kind_of ( Download ) , broadcast_message )
end
end
end
end