Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 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
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,
representants_legaux: :representant_legal
}.freeze

EXPLODED_COLLECTIONS = {
Expand Down
12 changes: 6 additions & 6 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,7 +116,7 @@
"telephone": "0836656565",
"courriel": "whatever@gouv.fr"
}
},
],
"representants_legaux": [
{
"id": "234567",
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' }],
representants_legaux: [{ 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][:representants_legaux]).to eq(representant_legal: [{ nom: 'Martin' }])
end
end

Expand Down
Loading