Compare commits

...

9 commits

Author SHA1 Message Date
Colin Darie
b60066bb5d
Merge pull request #9026 from demarches-simplifiees/less_flacky
Corrige des tests instables
2023-05-15 10:44:17 +00:00
Colin Darie
c5b1ae50e2
Merge pull request #9035 from colinux/fork-fix-champ-pj-updated-at
Correctif: ETQ usager le champ PJ d'un dossier en construction ne doit pas être marqué "à déposer" sans raison
2023-05-15 10:33:10 +00:00
Colin Darie
3aeeb325cf
Merge pull request #9046 from tchak/graphql-remove-sentry-tiemout-log
ETQ Opérateur, je ne veux pas voir de log de timeout d'API dans les log Sentry
2023-05-15 10:32:44 +00:00
Paul Chavard
0b696049b2 chore(graphql): remove sentry log on timeout errors 2023-05-15 11:36:10 +02:00
Colin Darie
0d21450f8a
fix(fork): don't let active storage override our champ#updated_at after a transaction 2023-05-15 11:08:07 +02:00
Colin Darie
9b52f0902d
test(clone): move dossier#clone spec into appropriate concern 2023-05-15 11:08:06 +02:00
simon lehericey
0457251cb0 try something different 2023-05-11 16:56:56 +02:00
simon lehericey
35866cf860 fix graphql_stored_queries_spec 2023-05-11 16:56:56 +02:00
simon lehericey
4aee0e056d try to fix autosave spec 2023-05-11 11:52:30 +02:00
7 changed files with 187 additions and 158 deletions

View file

@ -134,7 +134,6 @@ class API::V2::Schema < GraphQL::Schema
class Timeout < GraphQL::Schema::Timeout
def handle_timeout(error, query)
error.extensions = { code: :timeout }
Sentry.capture_exception(error, extra: query.context.query_info)
end
end

View file

@ -108,12 +108,15 @@ module DossierCloneConcern
transaction do
cloned_dossier.save!
if fork
cloned_dossier.rebase!
end
end
if fork
cloned_champs.values.each do |(original, champ)|
champ.update_columns(created_at: original.created_at, updated_at: original.updated_at)
end
cloned_dossier.rebase!
end
end
cloned_dossier.reload

View file

@ -555,7 +555,7 @@ describe API::V2::GraphqlController do
expect(gql_errors).to be_nil
expect(gql_data[:groupeInstructeurCreer][:errors]).to be_nil
expect(gql_data[:groupeInstructeurCreer][:groupeInstructeur][:id]).not_to be_nil
expect(gql_data[:groupeInstructeurCreer][:groupeInstructeur][:instructeurs]).to eq([{ id: admin.instructeur.to_typed_id, email: admin.instructeur.email }, { id: Instructeur.last.to_typed_id, email: }])
expect(gql_data[:groupeInstructeurCreer][:groupeInstructeur][:instructeurs]).to match_array([{ id: admin.instructeur.to_typed_id, email: admin.instructeur.email }, { id: Instructeur.last.to_typed_id, email: }])
}
end
end
@ -573,7 +573,7 @@ describe API::V2::GraphqlController do
expect(gql_data[:groupeInstructeurAjouterInstructeurs][:warnings]).to eq([message: "yolo nest pas une adresse email valide"])
expect(gql_data[:groupeInstructeurAjouterInstructeurs][:groupeInstructeur][:id]).to eq(groupe_instructeur.to_typed_id)
expect(groupe_instructeur.instructeurs.count).to eq(2)
expect(gql_data[:groupeInstructeurAjouterInstructeurs][:groupeInstructeur][:instructeurs]).to eq([{ id: existing_instructeur.to_typed_id, email: existing_instructeur.email }, { id: Instructeur.last.to_typed_id, email: }])
expect(gql_data[:groupeInstructeurAjouterInstructeurs][:groupeInstructeur][:instructeurs]).to match_array([{ id: existing_instructeur.to_typed_id, email: existing_instructeur.email }, { id: Instructeur.last.to_typed_id, email: }])
}
end

View file

@ -12,6 +12,179 @@ RSpec.describe DossierCloneConcern do
before { procedure.publish! }
describe '#clone' do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:new_dossier) { dossier.clone }
context 'reset most attributes' do
it { expect(new_dossier.id).not_to eq(dossier.id) }
it { expect(new_dossier.api_entreprise_job_exceptions).to be_nil }
it { expect(new_dossier.archived).to be_falsey }
it { expect(new_dossier.brouillon_close_to_expiration_notice_sent_at).to be_nil }
it { expect(new_dossier.conservation_extension).to eq(0.seconds) }
it { expect(new_dossier.declarative_triggered_at).to be_nil }
it { expect(new_dossier.deleted_user_email_never_send).to be_nil }
it { expect(new_dossier.depose_at).to be_nil }
it { expect(new_dossier.en_construction_at).to be_nil }
it { expect(new_dossier.en_construction_close_to_expiration_notice_sent_at).to be_nil }
it { expect(new_dossier.en_instruction_at).to be_nil }
it { expect(new_dossier.for_procedure_preview).to be_falsey }
it { expect(new_dossier.groupe_instructeur_updated_at).to be_nil }
it { expect(new_dossier.hidden_at).to be_nil }
it { expect(new_dossier.hidden_by_administration_at).to be_nil }
it { expect(new_dossier.hidden_by_reason).to be_nil }
it { expect(new_dossier.hidden_by_user_at).to be_nil }
it { expect(new_dossier.identity_updated_at).to be_nil }
it { expect(new_dossier.last_avis_updated_at).to be_nil }
it { expect(new_dossier.last_champ_private_updated_at).to be_nil }
it { expect(new_dossier.last_champ_updated_at).to be_nil }
it { expect(new_dossier.last_commentaire_updated_at).to be_nil }
it { expect(new_dossier.motivation).to be_nil }
it { expect(new_dossier.private_search_terms).to eq("") }
it { expect(new_dossier.processed_at).to be_nil }
it { expect(new_dossier.search_terms).to match(dossier.user.email) }
it { expect(new_dossier.termine_close_to_expiration_notice_sent_at).to be_nil }
it { expect(new_dossier.dossier_transfer_id).to be_nil }
end
context 'copies some attributes' do
it { expect(new_dossier.groupe_instructeur).to eq(dossier.groupe_instructeur) }
it { expect(new_dossier.autorisation_donnees).to eq(dossier.autorisation_donnees) }
it { expect(new_dossier.revision_id).to eq(dossier.revision_id) }
it { expect(new_dossier.user_id).to eq(dossier.user_id) }
end
context 'forces some attributes' do
let(:dossier) { create(:dossier, :accepte) }
it { expect(new_dossier.brouillon?).to eq(true) }
it { expect(new_dossier.parent_dossier).to eq(dossier) }
context 'destroy parent' do
before { new_dossier }
it 'clean fk' do
expect { dossier.destroy }.to change { new_dossier.reload.parent_dossier_id }.from(dossier.id).to(nil)
end
end
end
context 'procedure with_individual' do
let(:procedure) { create(:procedure, :for_individual) }
it { expect(new_dossier.individual.slice(:nom, :prenom, :gender)).to eq(dossier.individual.slice(:nom, :prenom, :gender)) }
it { expect(new_dossier.individual.id).not_to eq(dossier.individual.id) }
end
context 'procedure with etablissement' do
let(:dossier) { create(:dossier, :with_entreprise) }
it { expect(new_dossier.etablissement.slice(:siret)).to eq(dossier.etablissement.slice(:siret)) }
it { expect(new_dossier.etablissement.id).not_to eq(dossier.etablissement.id) }
end
describe 'champs' do
it { expect(new_dossier.id).not_to eq(dossier.id) }
context 'public are duplicated' do
it { expect(new_dossier.champs_public.count).to eq(dossier.champs_public.count) }
it { expect(new_dossier.champs_public.ids).not_to eq(dossier.champs_public.ids) }
it 'keeps champs.values' do
original_first_champ = dossier.champs_public.first
original_first_champ.update!(value: 'kthxbye')
expect(new_dossier.champs_public.first.value).to eq(original_first_champ.value)
end
context 'for Champs::Repetition with rows, original_champ.repetition and rows are duped' do
let(:dossier) { create(:dossier) }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: dossier.procedure) }
let(:champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) }
before { dossier.champs_public << champ_repetition }
it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.count).to eq(4) }
it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.ids).not_to eq(champ_repetition.champs.ids) }
end
context 'for Champs::CarteChamp with geo areas, original_champ.geo_areas are duped' do
let(:dossier) { create(:dossier) }
let(:type_de_champ_carte) { create(:type_de_champ_carte, procedure: dossier.procedure) }
let(:geo_area) { create(:geo_area, :selection_utilisateur, :polygon) }
let(:champ_carte) { create(:champ_carte, type_de_champ: type_de_champ_carte, geo_areas: [geo_area]) }
before { dossier.champs_public << champ_carte }
it { expect(Champs::CarteChamp.where(dossier: new_dossier).first.geo_areas.count).to eq(1) }
it { expect(Champs::CarteChamp.where(dossier: new_dossier).first.geo_areas.ids).not_to eq(champ_carte.geo_areas.ids) }
end
context 'for Champs::SiretChamp, original_champ.etablissement is duped' do
let(:dossier) { create(:dossier) }
let(:type_de_champs_siret) { create(:type_de_champ_siret, procedure: dossier.procedure) }
let(:etablissement) { create(:etablissement) }
let(:champ_siret) { create(:champ_siret, type_de_champ: type_de_champs_siret, etablissement: create(:etablissement)) }
before { dossier.champs_public << champ_siret }
it { expect(Champs::SiretChamp.where(dossier: dossier).first.etablissement).not_to be_nil }
it { expect(Champs::SiretChamp.where(dossier: new_dossier).first.etablissement.id).not_to eq(champ_siret.etablissement.id) }
end
context 'for Champs::PieceJustificative, original_champ.piece_justificative_file is duped' do
let(:dossier) { create(:dossier) }
let(:champ_piece_justificative) { create(:champ_piece_justificative, dossier_id: dossier.id) }
before { dossier.champs_public << champ_piece_justificative }
it { expect(Champs::PieceJustificativeChamp.where(dossier: new_dossier).first.piece_justificative_file.first.blob).to eq(champ_piece_justificative.piece_justificative_file.first.blob) }
end
context 'for Champs::AddressChamp, original_champ.data is duped' do
let(:dossier) { create(:dossier) }
let(:type_de_champs_adress) { create(:type_de_champ_address, procedure: dossier.procedure) }
let(:etablissement) { create(:etablissement) }
let(:champ_address) { create(:champ_address, type_de_champ: type_de_champs_adress, external_id: 'Address', data: { city_code: '75019' }) }
before { dossier.champs_public << champ_address }
it { expect(Champs::AddressChamp.where(dossier: dossier).first.data).not_to be_nil }
it { expect(Champs::AddressChamp.where(dossier: dossier).first.external_id).not_to be_nil }
it { expect(Champs::AddressChamp.where(dossier: new_dossier).first.external_id).to eq(champ_address.external_id) }
it { expect(Champs::AddressChamp.where(dossier: new_dossier).first.data).to eq(champ_address.data) }
end
end
context 'private are renewd' do
it { expect(new_dossier.champs_private.count).to eq(dossier.champs_private.count) }
it { expect(new_dossier.champs_private.ids).not_to eq(dossier.champs_private.ids) }
it 'reset champs private values' do
original_first_champs_private = dossier.champs_private.first
original_first_champs_private.update!(value: 'kthxbye')
expect(new_dossier.champs_private.first.value).not_to eq(original_first_champs_private.value)
expect(new_dossier.champs_private.first.value).to eq(nil)
end
end
end
context "as a fork" do
let(:new_dossier) { dossier.clone(fork: true) }
it { expect(new_dossier.editing_fork_origin).to eq(dossier) }
it { expect(new_dossier.champs_public[0].id).not_to eq(dossier.champs_public[0].id) }
it { expect(new_dossier.champs_public[0].created_at).to eq(dossier.champs_public[0].created_at) }
it { expect(new_dossier.champs_public[0].updated_at).to eq(dossier.champs_public[0].updated_at) }
context "piece justificative champ" do
let(:champ_pj) { create(:champ_piece_justificative, dossier_id: dossier.id) }
before { dossier.champs_public << champ_pj }
it {
champ_pj_fork = Champs::PieceJustificativeChamp.where(dossier: new_dossier).first
expect(champ_pj_fork.piece_justificative_file.first.blob).to eq(champ_pj.piece_justificative_file.first.blob)
expect(champ_pj_fork.created_at).to eq(champ_pj.created_at)
expect(champ_pj_fork.updated_at).to eq(champ_pj.updated_at)
}
end
end
end
describe '#make_diff' do
subject { dossier.make_diff(forked_dossier) }

View file

@ -1750,158 +1750,6 @@ describe Dossier do
it { expect(dossier.spreadsheet_columns(types_de_champ: [])).to include(["État du dossier", "Brouillon"]) }
end
describe '#clone' do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:new_dossier) { dossier.clone }
context 'reset most attributes' do
it { expect(new_dossier.id).not_to eq(dossier.id) }
it { expect(new_dossier.api_entreprise_job_exceptions).to be_nil }
it { expect(new_dossier.archived).to be_falsey }
it { expect(new_dossier.brouillon_close_to_expiration_notice_sent_at).to be_nil }
it { expect(new_dossier.conservation_extension).to eq(0.seconds) }
it { expect(new_dossier.declarative_triggered_at).to be_nil }
it { expect(new_dossier.deleted_user_email_never_send).to be_nil }
it { expect(new_dossier.depose_at).to be_nil }
it { expect(new_dossier.en_construction_at).to be_nil }
it { expect(new_dossier.en_construction_close_to_expiration_notice_sent_at).to be_nil }
it { expect(new_dossier.en_instruction_at).to be_nil }
it { expect(new_dossier.for_procedure_preview).to be_falsey }
it { expect(new_dossier.groupe_instructeur_updated_at).to be_nil }
it { expect(new_dossier.hidden_at).to be_nil }
it { expect(new_dossier.hidden_by_administration_at).to be_nil }
it { expect(new_dossier.hidden_by_reason).to be_nil }
it { expect(new_dossier.hidden_by_user_at).to be_nil }
it { expect(new_dossier.identity_updated_at).to be_nil }
it { expect(new_dossier.last_avis_updated_at).to be_nil }
it { expect(new_dossier.last_champ_private_updated_at).to be_nil }
it { expect(new_dossier.last_champ_updated_at).to be_nil }
it { expect(new_dossier.last_commentaire_updated_at).to be_nil }
it { expect(new_dossier.motivation).to be_nil }
it { expect(new_dossier.private_search_terms).to eq("") }
it { expect(new_dossier.processed_at).to be_nil }
it { expect(new_dossier.search_terms).to match(dossier.user.email) }
it { expect(new_dossier.termine_close_to_expiration_notice_sent_at).to be_nil }
it { expect(new_dossier.dossier_transfer_id).to be_nil }
end
context 'copies some attributes' do
it { expect(new_dossier.groupe_instructeur).to eq(dossier.groupe_instructeur) }
it { expect(new_dossier.autorisation_donnees).to eq(dossier.autorisation_donnees) }
it { expect(new_dossier.revision_id).to eq(dossier.revision_id) }
it { expect(new_dossier.user_id).to eq(dossier.user_id) }
end
context 'forces some attributes' do
let(:dossier) { create(:dossier, :accepte) }
it { expect(new_dossier.brouillon?).to eq(true) }
it { expect(new_dossier.parent_dossier).to eq(dossier) }
context 'destroy parent' do
before { new_dossier }
it 'clean fk' do
expect { dossier.destroy }.to change { new_dossier.reload.parent_dossier_id }.from(dossier.id).to(nil)
end
end
end
context 'procedure with_individual' do
let(:procedure) { create(:procedure, :for_individual) }
it { expect(new_dossier.individual.slice(:nom, :prenom, :gender)).to eq(dossier.individual.slice(:nom, :prenom, :gender)) }
it { expect(new_dossier.individual.id).not_to eq(dossier.individual.id) }
end
context 'procedure with etablissement' do
let(:dossier) { create(:dossier, :with_entreprise) }
it { expect(new_dossier.etablissement.slice(:siret)).to eq(dossier.etablissement.slice(:siret)) }
it { expect(new_dossier.etablissement.id).not_to eq(dossier.etablissement.id) }
end
describe 'champs' do
it { expect(new_dossier.id).not_to eq(dossier.id) }
context 'public are duplicated' do
it { expect(new_dossier.champs_public.count).to eq(dossier.champs_public.count) }
it { expect(new_dossier.champs_public.ids).not_to eq(dossier.champs_public.ids) }
it 'keeps champs.values' do
original_first_champ = dossier.champs_public.first
original_first_champ.update!(value: 'kthxbye')
expect(new_dossier.champs_public.first.value).to eq(original_first_champ.value)
end
context 'for Champs::Repetition with rows, original_champ.repetition and rows are duped' do
let(:dossier) { create(:dossier) }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: dossier.procedure) }
let(:champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) }
before { dossier.champs_public << champ_repetition }
it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.count).to eq(4) }
it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.ids).not_to eq(champ_repetition.champs.ids) }
end
context 'for Champs::CarteChamp with geo areas, original_champ.geo_areas are duped' do
let(:dossier) { create(:dossier) }
let(:type_de_champ_carte) { create(:type_de_champ_carte, procedure: dossier.procedure) }
let(:geo_area) { create(:geo_area, :selection_utilisateur, :polygon) }
let(:champ_carte) { create(:champ_carte, type_de_champ: type_de_champ_carte, geo_areas: [geo_area]) }
before { dossier.champs_public << champ_carte }
it { expect(Champs::CarteChamp.where(dossier: new_dossier).first.geo_areas.count).to eq(1) }
it { expect(Champs::CarteChamp.where(dossier: new_dossier).first.geo_areas.ids).not_to eq(champ_carte.geo_areas.ids) }
end
context 'for Champs::SiretChamp, original_champ.etablissement is duped' do
let(:dossier) { create(:dossier) }
let(:type_de_champs_siret) { create(:type_de_champ_siret, procedure: dossier.procedure) }
let(:etablissement) { create(:etablissement) }
let(:champ_siret) { create(:champ_siret, type_de_champ: type_de_champs_siret, etablissement: create(:etablissement)) }
before { dossier.champs_public << champ_siret }
it { expect(Champs::SiretChamp.where(dossier: dossier).first.etablissement).not_to be_nil }
it { expect(Champs::SiretChamp.where(dossier: new_dossier).first.etablissement.id).not_to eq(champ_siret.etablissement.id) }
end
context 'for Champs::PieceJustificative, original_champ.piece_justificative_file is duped' do
let(:dossier) { create(:dossier) }
let(:champ_piece_justificative) { create(:champ_piece_justificative, dossier_id: dossier.id) }
before { dossier.champs_public << champ_piece_justificative }
it { expect(Champs::PieceJustificativeChamp.where(dossier: new_dossier).first.piece_justificative_file.first.blob).to eq(champ_piece_justificative.piece_justificative_file.first.blob) }
end
context 'for Champs::AddressChamp, original_champ.data is duped' do
let(:dossier) { create(:dossier) }
let(:type_de_champs_adress) { create(:type_de_champ_address, procedure: dossier.procedure) }
let(:etablissement) { create(:etablissement) }
let(:champ_address) { create(:champ_address, type_de_champ: type_de_champs_adress, external_id: 'Address', data: { city_code: '75019' }) }
before { dossier.champs_public << champ_address }
it { expect(Champs::AddressChamp.where(dossier: dossier).first.data).not_to be_nil }
it { expect(Champs::AddressChamp.where(dossier: dossier).first.external_id).not_to be_nil }
it { expect(Champs::AddressChamp.where(dossier: new_dossier).first.external_id).to eq(champ_address.external_id) }
it { expect(Champs::AddressChamp.where(dossier: new_dossier).first.data).to eq(champ_address.data) }
end
end
context 'private are renewd' do
it { expect(new_dossier.champs_private.count).to eq(dossier.champs_private.count) }
it { expect(new_dossier.champs_private.ids).not_to eq(dossier.champs_private.ids) }
it 'reset champs private values' do
original_first_champs_private = dossier.champs_private.first
original_first_champs_private.update!(value: 'kthxbye')
expect(new_dossier.champs_private.first.value).not_to eq(original_first_champs_private.value)
expect(new_dossier.champs_private.first.value).to eq(nil)
end
end
end
end
describe '#processed_in_month' do
include ActiveSupport::Testing::TimeHelpers

View file

@ -292,6 +292,7 @@ describe 'fetch API Particulier Data', js: true do
end
expect(page).to have_current_path(merci_dossier_path(Dossier.last))
perform_enqueued_jobs
wait_until { cnaf_champ.reload.data.present? }
visit demande_dossier_path(dossier)
@ -349,6 +350,7 @@ describe 'fetch API Particulier Data', js: true do
end
expect(page).to have_current_path(merci_dossier_path(Dossier.last))
perform_enqueued_jobs
wait_until { pole_emploi_champ.reload.data.present? }
visit demande_dossier_path(dossier)
@ -421,6 +423,7 @@ describe 'fetch API Particulier Data', js: true do
end
expect(page).to have_current_path(merci_dossier_path(Dossier.last))
perform_enqueued_jobs
wait_until { mesri_champ.reload.data.present? }
visit demande_dossier_path(dossier)
@ -486,6 +489,7 @@ describe 'fetch API Particulier Data', js: true do
end
expect(page).to have_current_path(merci_dossier_path(Dossier.last))
perform_enqueued_jobs
wait_until { dgfip_champ.reload.data.present? }
visit demande_dossier_path(dossier)

View file

@ -473,6 +473,7 @@ describe 'The user' do
fill_in('texte obligatoire', with: 'a valid user input')
wait_for_autosave
wait_until { champ_value_for('texte obligatoire') == 'a valid user input' }
visit current_path
expect(page).to have_field('texte obligatoire', with: 'a valid user input')
@ -492,6 +493,7 @@ describe 'The user' do
allow_any_instance_of(Users::DossiersController).to receive(:update).and_call_original
click_on 'Réessayer'
wait_for_autosave
wait_until { champ_value_for('texte obligatoire') == 'a valid user input' }
visit current_path
expect(page).to have_field('texte obligatoire', with: 'a valid user input')