Merge pull request #7151 from tchak/fix-graphql-addresse

fix(graphql): fix AddressTypeType
This commit is contained in:
Paul Chavard 2022-04-12 19:20:22 +02:00 committed by GitHub
commit e3a9c28b6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 5 deletions

View file

@ -1,10 +1,10 @@
module Types module Types
class AddressType < Types::BaseObject class AddressType < Types::BaseObject
class AddressTypeType < Types::BaseEnum class AddressTypeType < Types::BaseEnum
value(:housenumber, "numéro « à la plaque »", value: :housenumber) value(:housenumber, "numéro « à la plaque »", value: "housenumber")
value(:street, "position « à la voie », placé approximativement au centre de celle-ci", value: :street) value(:street, "position « à la voie », placé approximativement au centre de celle-ci", value: "street")
value(:municipality, "numéro « à la commune »", value: :municipality) value(:municipality, "numéro « à la commune »", value: "municipality")
value(:locality, "lieu-dit", value: :locality) value(:locality, "lieu-dit", value: "locality")
end end
field :label, String, "libellé complet de ladresse", null: false field :label, String, "libellé complet de ladresse", null: false

View file

@ -104,7 +104,7 @@ module Types
def address def address
{ {
label: object.adresse, label: object.adresse,
type: :housenumber, type: "housenumber",
street_number: object.numero_voie, street_number: object.numero_voie,
street_name: object.nom_voie, street_name: object.nom_voie,
street_address: object.nom_voie.present? ? [object.numero_voie, object.type_voie, object.nom_voie].compact.join(' ') : nil, street_address: object.nom_voie.present? ? [object.numero_voie, object.type_voie, object.nom_voie].compact.join(' ') : nil,

View file

@ -31,6 +31,26 @@ RSpec.describe Types::DossierType, type: :graphql do
let(:dossier) { create(:dossier, :accepte, :with_populated_champs, procedure: procedure) } let(:dossier) { create(:dossier, :accepte, :with_populated_champs, procedure: procedure) }
let(:query) { DOSSIER_WITH_CHAMPS_QUERY } let(:query) { DOSSIER_WITH_CHAMPS_QUERY }
let(:variables) { { number: dossier.id } } let(:variables) { { number: dossier.id } }
let(:address) do
{
"type" => "housenumber",
"label" => "33 Rue Rébeval 75019 Paris",
"city_code" => "75119",
"city_name" => "Paris",
"postal_code" => "75019",
"region_code" => "11",
"region_name" => "Île-de-France",
"street_name" => "Rue Rébeval",
"street_number" => "33",
"street_address" => "33 Rue Rébeval",
"department_code" => "75",
"department_name" => "Paris"
}
end
before do
dossier.champs.second.update(data: address)
end
it { expect(data[:dossier][:champs][0][:__typename]).to eq "CommuneChamp" } 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][1][:__typename]).to eq "AddressChamp" }
@ -86,7 +106,12 @@ RSpec.describe Types::DossierType, type: :graphql do
code code
} }
fragment AddressFragment on Address { fragment AddressFragment on Address {
type
label
cityName cityName
cityCode
streetName
streetNumber
} }
GRAPHQL GRAPHQL
end end