fix(graphql): detect custom champs in fragment definitions

This commit is contained in:
Paul Chavard 2022-04-11 22:35:51 +02:00
parent ac6010da06
commit b6bb9552e6
2 changed files with 63 additions and 10 deletions

View file

@ -26,6 +26,16 @@ RSpec.describe Types::DossierType, type: :graphql do
end
end
describe 'dossier with champs' do
let(:procedure) { create(:procedure, :published, :with_commune, :with_address) }
let(:dossier) { create(:dossier, :accepte, :with_populated_champs, procedure: procedure) }
let(:query) { DOSSIER_WITH_CHAMPS_QUERY }
let(:variables) { { number: dossier.id } }
it { expect(data[:dossier][:champs][0][:__typename]).to eq "CommuneChamp" }
it { expect(data[:dossier][:champs][1][:__typename]).to eq "AddressChamp" }
end
DOSSIER_QUERY = <<-GRAPHQL
query($number: Int!) {
dossier(number: $number) {
@ -48,4 +58,35 @@ RSpec.describe Types::DossierType, type: :graphql do
}
}
GRAPHQL
DOSSIER_WITH_CHAMPS_QUERY = <<-GRAPHQL
query($number: Int!) {
dossier(number: $number) {
id
number
champs {
id
label
__typename
...CommuneChampFragment
... on AddressChamp {
address {
...AddressFragment
}
}
}
}
}
fragment CommuneChampFragment on CommuneChamp {
commune {
...CommuneFragment
}
}
fragment CommuneFragment on Commune {
code
}
fragment AddressFragment on Address {
cityName
}
GRAPHQL
end