Merge pull request #6610 from betagouv/improve-graphql-specs

Amélioration de la vitesse d'exécution des tests GraphQL (#6610)
This commit is contained in:
Pierre de La Morinerie 2021-11-03 19:44:55 +01:00 committed by GitHub
commit 14d3956419
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 112 additions and 92 deletions

View file

@ -18,7 +18,7 @@ GIT
GEM
remote: https://rubygems.org/
specs:
aasm (5.1.1)
aasm (5.2.0)
concurrent-ruby (~> 1.0)
acsv (0.0.1)
actioncable (6.1.4.1)

View file

@ -76,4 +76,10 @@ Rails.application.configure do
debounce_delay: 500,
status_visible_duration: 500
}
# BCrypt is slow by design - but during tests we want to make it faster
# to compute hashes of passwords.
silence_warnings do
BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST
end
end

View file

@ -256,7 +256,7 @@ describe API::V1::DossiersController do
describe 'repetition' do
let(:procedure) { create(:procedure, :with_repetition, administrateur: admin) }
let(:dossier) { create(:dossier, :en_construction, :with_all_champs, procedure: procedure) }
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure: procedure) }
subject { super().first[:rows] }

View file

@ -1,21 +1,11 @@
describe API::V2::GraphqlController do
let(:admin) { create(:administrateur) }
let(:token) { admin.renew_api_token }
let(:procedure) { create(:procedure, :published, :for_individual, :with_service, :with_all_champs, :with_all_annotations, administrateurs: [admin]) }
let(:dossier) do
dossier = create(:dossier,
:en_construction,
:with_all_champs,
:with_all_annotations,
:with_individual,
procedure: procedure)
create(:commentaire, :with_file, dossier: dossier, email: 'test@test.com')
dossier
end
let(:procedure) { create(:procedure, :published, :for_individual, :with_service, administrateurs: [admin]) }
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
let(:dossier1) { create(:dossier, :en_construction, :with_individual, procedure: procedure, en_construction_at: 1.day.ago) }
let(:dossier2) { create(:dossier, :en_construction, :with_individual, :archived, procedure: procedure, en_construction_at: 3.days.ago) }
let(:dossier_brouillon) { create(:dossier, :with_individual, procedure: procedure) }
let(:dossiers) { [dossier2, dossier1, dossier] }
let(:dossiers) { [dossier] }
let(:instructeur) { create(:instructeur, followed_dossiers: dossiers) }
def compute_checksum_in_chunks(io)
@ -116,57 +106,63 @@ describe API::V2::GraphqlController do
request.env['HTTP_AUTHORIZATION'] = authorization_header
end
context "demarche" do
it "should be returned" do
expect(gql_errors).to eq(nil)
expect(gql_data).to eq(demarche: {
id: procedure.to_typed_id,
number: procedure.id,
title: procedure.libelle,
description: procedure.description,
state: 'publiee',
dateFermeture: nil,
dateCreation: procedure.created_at.iso8601,
dateDerniereModification: procedure.updated_at.iso8601,
groupeInstructeurs: [
{
instructeurs: [{ email: instructeur.email }],
label: "défaut"
}
],
revisions: procedure.revisions.map { |revision| { id: revision.to_typed_id } },
draftRevision: { id: procedure.draft_revision.to_typed_id },
publishedRevision: {
id: procedure.published_revision.to_typed_id,
champDescriptors: procedure.published_types_de_champ.map do |tdc|
describe "demarche" do
describe "query a demarche" do
let(:procedure) { create(:procedure, :published, :for_individual, :with_service, :with_all_champs, :with_all_annotations, administrateurs: [admin]) }
it "returns the demarche" do
expect(gql_errors).to eq(nil)
expect(gql_data).to eq(demarche: {
id: procedure.to_typed_id,
number: procedure.id,
title: procedure.libelle,
description: procedure.description,
state: 'publiee',
dateFermeture: nil,
dateCreation: procedure.created_at.iso8601,
dateDerniereModification: procedure.updated_at.iso8601,
groupeInstructeurs: [
{
type: tdc.type_champ
instructeurs: [{ email: instructeur.email }],
label: "défaut"
}
end
},
service: {
nom: procedure.service.nom,
typeOrganisme: procedure.service.type_organisme,
organisme: procedure.service.organisme
},
champDescriptors: procedure.types_de_champ.map do |tdc|
{
id: tdc.to_typed_id,
label: tdc.libelle,
type: tdc.type_champ,
description: tdc.description,
required: tdc.mandatory?,
champDescriptors: tdc.repetition? ? tdc.reload.types_de_champ.map { |tdc| { id: tdc.to_typed_id, type: tdc.type_champ } } : nil,
options: tdc.drop_down_list? ? tdc.drop_down_list_options.reject(&:empty?) : nil
],
revisions: procedure.revisions.map { |revision| { id: revision.to_typed_id } },
draftRevision: { id: procedure.draft_revision.to_typed_id },
publishedRevision: {
id: procedure.published_revision.to_typed_id,
champDescriptors: procedure.published_types_de_champ.map do |tdc|
{
type: tdc.type_champ
}
end
},
service: {
nom: procedure.service.nom,
typeOrganisme: procedure.service.type_organisme,
organisme: procedure.service.organisme
},
champDescriptors: procedure.types_de_champ.map do |tdc|
{
id: tdc.to_typed_id,
label: tdc.libelle,
type: tdc.type_champ,
description: tdc.description,
required: tdc.mandatory?,
champDescriptors: tdc.repetition? ? tdc.reload.types_de_champ.map { |tdc| { id: tdc.to_typed_id, type: tdc.type_champ } } : nil,
options: tdc.drop_down_list? ? tdc.drop_down_list_options.reject(&:empty?) : nil
}
end,
dossiers: {
nodes: dossiers.map { |dossier| { id: dossier.to_typed_id } }
}
end,
dossiers: {
nodes: dossiers.map { |dossier| { id: dossier.to_typed_id } }
}
})
})
end
end
context "filter dossiers" do
describe "filter dossiers" do
let(:dossiers) { [dossier, dossier1, dossier2] }
let(:query) do
"{
demarche(number: #{procedure.id}) {
@ -193,7 +189,8 @@ describe API::V2::GraphqlController do
end
end
context "filter archived dossiers" do
describe "filter archived dossiers" do
let(:dossiers) { [dossier, dossier1, dossier2] }
let(:query) do
"{
demarche(number: #{procedure.id}) {
@ -210,7 +207,8 @@ describe API::V2::GraphqlController do
context 'with archived=true' do
let(:archived_filter) { 'true' }
it "only archived dossiers should be returned" do
it 'returns only archived dossiers' do
expect(gql_errors).to eq(nil)
expect(gql_data).to eq(demarche: {
id: procedure.to_typed_id,
@ -224,7 +222,8 @@ describe API::V2::GraphqlController do
context 'with archived=false' do
let(:archived_filter) { 'false' }
it "only not archived dossiers should be returned" do
it 'returns only non-archived dossiers' do
expect(gql_errors).to eq(nil)
expect(gql_data).to eq(demarche: {
id: procedure.to_typed_id,
@ -237,7 +236,7 @@ describe API::V2::GraphqlController do
end
end
context "filter by minRevision" do
describe "filter by minRevision" do
let(:query) do
"{
demarche(number: #{procedure.id}) {
@ -266,7 +265,7 @@ describe API::V2::GraphqlController do
end
end
context "filter by maxRevision" do
describe "filter by maxRevision" do
let(:query) do
"{
demarche(number: #{procedure.id}) {
@ -296,8 +295,20 @@ describe API::V2::GraphqlController do
end
end
context "dossier" do
context "with individual" do
describe "dossier" do
let(:dossier) do
dossier = create(:dossier,
:en_construction,
:with_populated_champs,
:with_populated_annotations,
:with_individual,
procedure: procedure)
create(:commentaire, :with_file, dossier: dossier, email: 'test@test.com')
dossier
end
context "for individual" do
let(:procedure) { create(:procedure, :published, :for_individual, :with_service, :with_all_champs, :with_all_annotations, administrateurs: [admin]) }
let(:query) do
"{
dossier(number: #{dossier.id}) {
@ -449,7 +460,7 @@ describe API::V2::GraphqlController do
end
end
context "with entreprise" do
context "for entreprise" do
let(:procedure_for_entreprise) { create(:procedure, :published, administrateurs: [admin]) }
let(:dossier) { create(:dossier, :en_construction, :with_entreprise, procedure: procedure_for_entreprise) }
@ -661,7 +672,7 @@ describe API::V2::GraphqlController do
end
end
context "deletedDossiers" do
describe "deletedDossiers" do
let(:query) do
"{
demarche(number: #{procedure.id}) {
@ -699,7 +710,7 @@ describe API::V2::GraphqlController do
end
end
context "champ" do
describe "champ" do
let(:champ) { create(:champ_piece_justificative, dossier: dossier) }
let(:byte_size) { 2712286911 }
@ -722,7 +733,7 @@ describe API::V2::GraphqlController do
}
end
context "when file is really big" do
context "when the file is really big" do
before do
champ.piece_justificative_file.blob.update(byte_size: byte_size)
end
@ -766,7 +777,7 @@ describe API::V2::GraphqlController do
end
end
context "groupeInstructeur" do
describe "groupeInstructeur" do
let(:groupe_instructeur) { procedure.groupe_instructeurs.first }
let(:query) do
"{
@ -796,7 +807,7 @@ describe API::V2::GraphqlController do
end
end
context "mutations" do
describe "mutations" do
describe 'dossierEnvoyerMessage' do
context 'success' do
let(:query) do
@ -902,6 +913,7 @@ describe API::V2::GraphqlController do
end
describe 'dossierPasserEnInstruction' do
let(:dossiers) { [dossier2, dossier1, dossier] }
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
let(:instructeur_id) { instructeur.to_typed_id }
let(:disable_notification) { false }
@ -1322,6 +1334,8 @@ describe API::V2::GraphqlController do
end
describe 'dossierModifierAnnotation' do
let(:procedure) { create(:procedure, :published, :for_individual, :with_service, :with_all_annotations, administrateurs: [admin]) }
describe 'text' do
let(:query) do
"mutation {
@ -1563,7 +1577,7 @@ describe API::V2::GraphqlController do
expect(gql_errors).not_to eq(nil)
end
context "dossier" do
describe "dossier" do
let(:query) { "{ dossier(number: #{dossier.id}) { id number usager { email } } }" }
it "should return error" do
@ -1572,7 +1586,7 @@ describe API::V2::GraphqlController do
end
end
context "mutation" do
describe "mutation" do
let(:query) do
"mutation {
dossierEnvoyerMessage(input: {

View file

@ -560,8 +560,8 @@ describe Instructeurs::DossiersController, type: :controller do
let(:dossier) do
create(:dossier,
:accepte,
:with_all_champs,
:with_all_annotations,
:with_populated_champs,
:with_populated_annotations,
:with_motivation,
:with_entreprise,
:with_commentaires, procedure: procedure)
@ -593,7 +593,7 @@ describe Instructeurs::DossiersController, type: :controller do
build(:type_de_champ_repetition, :with_types_de_champ, position: 3)
], instructeurs: instructeurs)
end
let(:dossier) { create(:dossier, :en_construction, :with_all_annotations, procedure: procedure) }
let(:dossier) { create(:dossier, :en_construction, :with_populated_annotations, procedure: procedure) }
let(:another_instructeur) { create(:instructeur) }
let(:now) { Time.zone.parse('01/01/2100') }

View file

@ -1,10 +1,10 @@
describe RechercheController, type: :controller do
let(:dossier) { create(:dossier, :en_construction, :with_all_annotations) }
let(:dossier) { create(:dossier, :en_construction, :with_populated_annotations) }
let(:dossier2) { create(:dossier, :en_construction, procedure: dossier.procedure) }
let(:instructeur) { create(:instructeur) }
let(:dossier_with_expert) { avis.dossier }
let(:avis) { create(:avis, dossier: create(:dossier, :en_construction, :with_all_annotations)) }
let(:avis) { create(:avis, dossier: create(:dossier, :en_construction, :with_populated_annotations)) }
let(:user) { instructeur.user }

View file

@ -879,7 +879,7 @@ describe Users::DossiersController, type: :controller do
let(:dossier) do
create(:dossier,
:accepte,
:with_all_champs,
:with_populated_champs,
:with_motivation,
:with_commentaires,
procedure: procedure,

View file

@ -212,7 +212,7 @@ FactoryBot.define do
end
end
trait :with_all_champs do
trait :with_populated_champs do
after(:create) do |dossier, _evaluator|
dossier.champs = dossier.types_de_champ.map do |type_de_champ|
build(:"champ_#{type_de_champ.type_champ}", dossier: dossier, type_de_champ: type_de_champ)
@ -221,7 +221,7 @@ FactoryBot.define do
end
end
trait :with_all_annotations do
trait :with_populated_annotations do
after(:create) do |dossier, _evaluator|
dossier.champs_private = dossier.types_de_champ_private.map do |type_de_champ|
build(:"champ_#{type_de_champ.type_champ}", private: true, dossier: dossier, type_de_champ: type_de_champ)

View file

@ -32,7 +32,7 @@ describe ProcedureExportService do
end
describe 'Dossiers sheet' do
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
let!(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) }
let(:nominal_headers) do
[
@ -119,7 +119,7 @@ describe ProcedureExportService do
describe 'Etablissement sheet' do
let(:procedure) { create(:procedure, :published, :with_all_champs) }
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_entreprise, procedure: procedure) }
let!(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_entreprise, procedure: procedure) }
let(:dossier_etablissement) { etablissements_sheet.data[1] }
let(:champ_etablissement) { etablissements_sheet.data[0] }
@ -309,7 +309,7 @@ describe ProcedureExportService do
end
describe 'Avis sheet' do
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
let!(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) }
let!(:avis) { create(:avis, :with_answer, dossier: dossier) }
it 'should have headers' do
@ -332,8 +332,8 @@ describe ProcedureExportService do
describe 'Repetitions sheet' do
let!(:dossiers) do
[
create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure),
create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure)
create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure),
create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure)
]
end
let(:champ_repetition) { dossiers.first.champs.find { |champ| champ.type_champ == 'repetition' } }
@ -381,7 +381,7 @@ describe ProcedureExportService do
end
context 'with non unique labels' do
let(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
let(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) }
let(:champ_repetition) { dossier.champs.find { |champ| champ.type_champ == 'repetition' } }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, procedure: procedure, libelle: champ_repetition.libelle) }
let!(:another_champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) }

View file

@ -1,7 +1,7 @@
describe 'user access to the list of their dossiers' do
let(:user) { create(:user) }
let!(:dossier_brouillon) { create(:dossier, user: user) }
let!(:dossier_en_construction) { create(:dossier, :with_all_champs, :en_construction, user: user) }
let!(:dossier_en_construction) { create(:dossier, :with_populated_champs, :en_construction, user: user) }
let!(:dossier_en_instruction) { create(:dossier, :en_instruction, user: user) }
let!(:dossier_archived) { create(:dossier, :en_instruction, :archived, user: user) }
let(:dossiers_per_page) { 25 }
@ -121,7 +121,7 @@ describe 'user access to the list of their dossiers' do
end
context "when user search for something inside the dossier" do
let(:dossier_en_construction2) { create(:dossier, :with_all_champs, :en_construction, user: user) }
let(:dossier_en_construction2) { create(:dossier, :with_populated_champs, :en_construction, user: user) }
before do
page.find_by_id('q').set(dossier_en_construction.champs.first.value)
end