spec(graphql): add tests to ensure that stable ids are stable

This commit is contained in:
Paul Chavard 2022-11-25 10:37:48 +01:00
parent 9a16ab4112
commit 20007824c9
2 changed files with 51 additions and 0 deletions

View file

@ -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

View file

@ -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