From 7035f82bfb3362e93659db29863c635a1a43f9e4 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 15 Apr 2024 13:56:03 +0200 Subject: [PATCH] fix: flaky test --- .../api/v2/graphql_controller_spec.rb | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index 2a086ddb181..4f1aef2239f 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -457,7 +457,7 @@ def format_type_champ(type_champ) it "should be returned" do expect(gql_errors).to eq(nil) - expect(gql_data).to eq(dossier: { + expect(gql_data[:dossier]).to include( id: dossier.to_typed_id, number: dossier.id, state: 'en_construction', @@ -503,27 +503,32 @@ def format_type_champ(type_champ) civilite: 'M', dateDeNaissance: '1991-11-01' }, - messages: dossier.commentaires.map do |commentaire| - { - body: commentaire.body, - attachment: { - filename: commentaire.piece_jointe.filename.to_s, - contentType: commentaire.piece_jointe.content_type, - checksum: commentaire.piece_jointe.checksum, - byteSize: commentaire.piece_jointe.byte_size - }, - email: commentaire.email - } - end, - avis: [], - champs: dossier.champs_public.map do |champ| - { - id: champ.to_typed_id, - label: champ.libelle, - stringValue: champ.for_api_v2 - } - end - }) + avis: [] + ) + + expected_champs = dossier.champs_public.map do |champ| + { + id: champ.to_typed_id, + label: champ.libelle, + stringValue: champ.for_api_v2 + } + end + expect(gql_data[:dossier][:champs]).to match_array(expected_champs) + + expected_messages = dossier.commentaires.map do |commentaire| + { + body: commentaire.body, + attachment: { + filename: commentaire.piece_jointe.filename.to_s, + contentType: commentaire.piece_jointe.content_type, + checksum: commentaire.piece_jointe.checksum, + byteSize: commentaire.piece_jointe.byte_size + }, + email: commentaire.email + } + end + expect(gql_data[:dossier][:messages]).to match_array(expected_messages) + expect(gql_data[:dossier][:champs][0][:id]).to eq(dossier.champs_public[0].type_de_champ.to_typed_id) end end