Extend RNA adapter while keeping depreciated version

This commit is contained in:
Damien Le Thiec 2022-10-04 19:59:39 +02:00
parent fa1f0fc240
commit ecd54de854
3 changed files with 212 additions and 2 deletions

View file

@ -14,7 +14,8 @@ class APIEntreprise::RNAAdapter < APIEntreprise::Adapter
end
def process_params
params = data_source[:association]&.slice(*attr_to_fetch)
params = data_source[:association]
params = params&.slice(*attr_to_fetch) if @depreciated
params[:rna] = data_source.dig(:association, :id)
if params[:rna].present? && valid_params?(params)
params = params.transform_keys { |k| :"association_#{k}" }.deep_stringify_keys

View file

@ -24,10 +24,209 @@
"association_date_publication": {
"type": "string",
"format": "date"
},
"association_date_dissolution": {
"anyOf": [
{
"type": "string",
"format": "date"
},
{
"type": "null"
}
]
},
"association_mise_a_jour": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
]
},
"association_id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"association_siret": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"association_siret_siege_social": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"association_code_civilite_dirigeant": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"association_civilite_dirigeant": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"association_code_etat": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"association_etat": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"association_code_groupement": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"association_groupement": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"association_address_siege": {
"type": "object",
"properties": {
"complement": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"numero_voie": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"type_voie": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"libelle_voie": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"distribution": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"code_insee": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"code_postal": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"commune": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
}
}
},
"required": [
"association_titre",
"association_rna"
"association_rna",
"association_date_creation",
"association_date_declaration",
"association_date_publication"
]
}

View file

@ -43,4 +43,14 @@ describe APIEntreprise::RNAAdapter do
expect { subject }.to raise_exception(APIEntreprise::RNAAdapter::InvalidSchemaError)
end
end
context "when depreciated adapter is used" do
let(:adapter) { described_class.new(siret, procedure_id, true) }
let(:body) { File.read('spec/fixtures/files/api_entreprise/associations.json') }
let(:status) { 200 }
it '#to_params filter the keys' do
expect(subject.keys).to eq(["association_titre", "association_objet", "association_date_creation", "association_date_declaration", "association_date_publication", "association_rna"])
end
end
end