From 20007824c9d5c0c2dcbf674f83cba0fae5778af8 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 25 Nov 2022 10:37:48 +0100 Subject: [PATCH] spec(graphql): add tests to ensure that stable ids are stable --- spec/graphql/demarche_spec.rb | 44 +++++++++++++++++++++++++++++++++++ spec/graphql/dossier_spec.rb | 7 ++++++ 2 files changed, 51 insertions(+) create mode 100644 spec/graphql/demarche_spec.rb diff --git a/spec/graphql/demarche_spec.rb b/spec/graphql/demarche_spec.rb new file mode 100644 index 000000000..29dc4de85 --- /dev/null +++ b/spec/graphql/demarche_spec.rb @@ -0,0 +1,44 @@ +RSpec.describe Types::DemarcheType, type: :graphql do + let(:query) { '' } + let(:context) { { internal_use: true } } + let(:variables) { {} } + + subject { API::V2::Schema.execute(query, variables: variables, context: context) } + + let(:data) { subject['data'].deep_symbolize_keys } + let(:errors) { subject['errors'].deep_symbolize_keys } + + describe 'demarche with clone' do + let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :yes_no }]) } + let(:procedure_clone) { procedure.clone(procedure.administrateurs.first, false) } + let(:query) { DEMARCHE_WITH_CHAMP_DESCRIPTORS_QUERY } + let(:variables) { { number: procedure_clone.id } } + let(:champ_descriptor_id) { procedure.draft_revision.types_de_champ_public.first.to_typed_id } + + it { + expect(data[:demarche][:champDescriptors]).to eq(data[:demarche][:draftRevision][:champDescriptors]) + expect(data[:demarche][:champDescriptors][0][:id]).to eq(champ_descriptor_id) + expect(data[:demarche][:draftRevision][:champDescriptors][0][:id]).to eq(champ_descriptor_id) + expect(procedure.draft_revision.types_de_champ_public.first.id).not_to eq(procedure_clone.draft_revision.types_de_champ_public.first.id) + expect(procedure.draft_revision.types_de_champ_public.first.stable_id).to eq(procedure_clone.draft_revision.types_de_champ_public.first.stable_id) + } + end + + DEMARCHE_WITH_CHAMP_DESCRIPTORS_QUERY = <<-GRAPHQL + query($number: Int!) { + demarche(number: $number) { + number + champDescriptors { + id + label + } + draftRevision { + champDescriptors { + id + label + } + } + } + } + GRAPHQL +end diff --git a/spec/graphql/dossier_spec.rb b/spec/graphql/dossier_spec.rb index fe919867f..2b51c09fd 100644 --- a/spec/graphql/dossier_spec.rb +++ b/spec/graphql/dossier_spec.rb @@ -54,6 +54,7 @@ RSpec.describe Types::DossierType, type: :graphql do it { expect(data[:dossier][:champs][0][:__typename]).to eq "CommuneChamp" } it { expect(data[:dossier][:champs][1][:__typename]).to eq "AddressChamp" } + it { expect(data[:dossier][:champs][0][:id]).to eq(data[:dossier][:revision][:champDescriptors][0][:id]) } end describe 'dossier with conditional champs' do @@ -223,6 +224,12 @@ RSpec.describe Types::DossierType, type: :graphql do dossier(number: $number) { id number + revision { + champDescriptors { + id + label + } + } champs { id label