Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions siade/app/interactors/mi/associations/build_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def activites
end

def reseaux_affiliation
return [] if association[:reseaux_affiliation].blank?
return [] if association[:affiliations].blank?

Array.wrap(association[:reseaux_affiliation][:reseau_affiliation]).map do |reseau_affiliation|
Array.wrap(association[:affiliations][:affiliation]).map do |reseau_affiliation|
{
nom: reseau_affiliation[:nom],
numero: reseau_affiliation[:numero],
Expand All @@ -122,9 +122,9 @@ def reseaux_affiliation
end

def composition_reseau
return [] if association[:composition_reseau].blank?
return [] if association[:compositions].blank?

Array.wrap(association[:composition_reseau][:membre]).map do |membre_reseau|
Array.wrap(association[:compositions][:membre]).map do |membre_reseau|
{
rna: membre_reseau[:id_rna],
siret: membre_reseau[:id_siret],
Expand Down Expand Up @@ -214,9 +214,9 @@ def extract_representants_legaux(siret)
end

def extract_representants_legaux_for(siret)
return [] if association[:representants_legaux].blank?
return [] if association[:dirigeants].blank?

Array.wrap(association[:representants_legaux][:representant_legal]).select do |representant_legal|
Array.wrap(association[:dirigeants][:representant_legal]).select do |representant_legal|
representant_legal[:id_siret] == siret &&
representant_legal[:deleted] == 'false' &&
(representant_legal[:est_representant_legal] == 'true' || representant_legal[:est_representant_legal].nil?)
Expand Down
6 changes: 4 additions & 2 deletions siade/app/interactors/mi/associations/payload_parser.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class MI::Associations::PayloadParser
SINGLE_ELEMENT_COLLECTIONS = {
etablissements: :etablissement,
representants_legaux: :representant_legal,
agrements: :agrement
agrements: :agrement,
affiliations: :affiliation,
compositions: :membre,
dirigeants: :representant_legal
}.freeze

EXPLODED_COLLECTIONS = {
Expand Down
14 changes: 7 additions & 7 deletions siade/spec/fixtures/payloads/mi/association-77567227238579.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"note": "Association reconnue d'utilité publique"
},
"specificites": "{\"passsport\": {\"activites\": \"!Multi activités physiques ou sportives\", \"est_volontaire\": \"true\"}}",
"reseaux_affiliation": {
"reseau_affiliation": {
"affiliations": [
{
"id_correspondance": "1234567",
"nom": "CROIX ROUGE FRANCAISE",
"id_rna": "W751004076",
Expand All @@ -97,9 +97,9 @@
"nb_licencies_f": "1",
"numero": "37050001"
}
},
"composition_reseau": {
"membre": {
],
"compositions": [
{
"id_correspondance": "123456",
"nom": "ARTS ET CULTURES EN FOLIE",
"id_rna": "W532003071",
Expand All @@ -116,8 +116,8 @@
"telephone": "0836656565",
"courriel": "whatever@gouv.fr"
}
},
"representants_legaux": [
],
"dirigeants": [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est la même chose ? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonne question, effectivement non : ce n'était pas la même chose. representants_legaux existe toujours tel quel en v2.0 (le doc a raison), les payloads que j'avais testés étaient juste des associations sans représentants légaux déclarés. dirigeants est un concept distinct, sans rapport avec ce renommage.

Corrigé dans 6772b28 : representants_legaux repasse sur sa clé d'origine, inchangée. Seuls reseaux_affiliationaffiliations et composition_reseaucompositions sont de vrais renommages, vérifiés sur plusieurs payloads réels.

{
"id": "234567",
"civilite": "Monsieur",
Expand Down
36 changes: 36 additions & 0 deletions siade/spec/interactors/mi/associations/build_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,42 @@
expect(document_url).to eq("#{Siade.credentials[:mi_domain]}/apim/api-asso/documents/00000000-0000-0000-0000-000000000001")
end
end

describe 'reseaux_affiliation' do
let(:reseau) { resource.reseaux_affiliation.first }

it 'maps the provider fields' do
expect(reseau).to include(
nom: 'CROIX ROUGE FRANCAISE',
numero: '37050001',
rna: 'W751004076',
siret: '77567227221138',
nombre_licencies: { hommes: 1, femmes: 1, total: 2 }
)
end
end

describe 'composition_reseau' do
let(:membre) { resource.composition_reseau.first }

it 'maps the provider fields' do
expect(membre).to include(
nom: 'ARTS ET CULTURES EN FOLIE',
rna: 'W532003071',
siret: '81412456600013'
)
end
end

describe 'representants_legaux' do
let(:representants_legaux) { resource.etablissements.first[:representants_legaux] }

it 'maps the provider fields' do
expect(representants_legaux).to contain_exactly(
hash_including(nom: 'MARTIN', prenom: 'Jean', fonction: 'Directeur général')
)
end
end
end

describe 'when payload has only one dac document (non-regression test)' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@
let(:body) do
{
etablissements: [{ id_siret: '111' }, { id_siret: '222' }],
agrements: [{ numero: '1' }]
agrements: [{ numero: '1' }],
affiliations: [{ nom: 'FEDERATION' }],
compositions: [{ nom: 'MEMBRE' }],
dirigeants: [{ nom: 'Martin' }]
}.to_json
end

it 'wraps each collection with its singular element key' do
expect(parsed[:asso][:etablissements]).to eq(etablissement: [{ id_siret: '111' }, { id_siret: '222' }])
expect(parsed[:asso][:agrements]).to eq(agrement: [{ numero: '1' }])
expect(parsed[:asso][:affiliations]).to eq(affiliation: [{ nom: 'FEDERATION' }])
expect(parsed[:asso][:compositions]).to eq(membre: [{ nom: 'MEMBRE' }])
expect(parsed[:asso][:dirigeants]).to eq(representant_legal: [{ nom: 'Martin' }])
end
end

Expand Down
Loading