fix(export): turbo poll when creating an export

This commit is contained in:
Colin Darie 2024-03-14 13:11:53 +01:00
parent f54caddcfe
commit 8fa6e04c53
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
3 changed files with 6 additions and 3 deletions

View file

@ -394,7 +394,7 @@ module Instructeurs
end end
def last_export_for(statut) def last_export_for(statut)
Export.where(instructeur_id: current_instructeur.id, statut: statut, updated_at: 1.hour.ago..).last Export.where(user_profile: current_instructeur, statut: statut, updated_at: 1.hour.ago..).last
end end
def cookies_export_key def cookies_export_key

View file

@ -777,15 +777,18 @@ describe Instructeurs::ProceduresController, type: :controller do
end end
context 'when the turbo_stream format is used' do context 'when the turbo_stream format is used' do
render_views
before do before do
post :download_export, post :download_export,
params: { export_format: :csv, procedure_id: procedure.id }, params: { export_format: :csv, procedure_id: procedure.id, statut: 'traites' },
format: :turbo_stream format: :turbo_stream
end end
it 'responds in the correct format' do it 'responds in the correct format' do
expect(response.media_type).to eq('text/vnd.turbo-stream.html') expect(response.media_type).to eq('text/vnd.turbo-stream.html')
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(response.body).to include(polling_last_export_instructeur_procedure_path(procedure))
end end
end end

View file

@ -7,7 +7,7 @@ FactoryBot.define do
after(:build) do |export, _evaluator| after(:build) do |export, _evaluator|
export.key = Export.generate_cache_key(export.groupe_instructeurs.map(&:id), export.procedure_presentation) export.key = Export.generate_cache_key(export.groupe_instructeurs.map(&:id), export.procedure_presentation)
export.instructeur = export.groupe_instructeurs.first&.instructeurs&.first export.user_profile = export.groupe_instructeurs.first&.instructeurs&.first if export.user_profile.nil?
export.dossiers_count = 10 if !export.pending? export.dossiers_count = 10 if !export.pending?
end end
end end