diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index add670c59..08b296997 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -9,6 +9,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) inflect.acronym 'API' + inflect.acronym 'RNA' inflect.irregular 'piece_justificative', 'pieces_justificatives' inflect.irregular 'type_de_piece_justificative', 'types_de_piece_justificative' inflect.irregular 'type_de_champ', 'types_de_champ' diff --git a/lib/siade/api.rb b/lib/siade/api.rb index 2bb92c15a..be4b048af 100644 --- a/lib/siade/api.rb +++ b/lib/siade/api.rb @@ -21,6 +21,11 @@ class SIADE::API call(base_url + endpoint) end + def self.rna(siret) + endpoint = "/api/v1/associations/#{siret}" + call(base_url + endpoint) + end + def self.call(url, params = {}) params.merge!(token: SIADETOKEN) diff --git a/lib/siade/rna_adapter.rb b/lib/siade/rna_adapter.rb new file mode 100644 index 000000000..6de06896f --- /dev/null +++ b/lib/siade/rna_adapter.rb @@ -0,0 +1,28 @@ +class SIADE::RNAAdapter + def initialize(siren) + @siret = siren + end + + def data_source + @data_source ||= JSON.parse(SIADE::API.rna(@siren), symbolize_names: true) + end + + def to_params + params = {} + + data_source[:association].each do |k, v| + params[k] = v if attr_to_fetch.include?(k) + end + params + end + + def attr_to_fetch + [:id, + :titre, + :objet, + :date_creation, + :date_declaration, + :date_publication + ] + end +end diff --git a/spec/lib/siade/api_spec.rb b/spec/lib/siade/api_spec.rb index 052117230..800492b11 100644 --- a/spec/lib/siade/api_spec.rb +++ b/spec/lib/siade/api_spec.rb @@ -85,4 +85,33 @@ describe SIADE::API do end end end + + describe '.rna' do + before do + stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/api\/v1\/associations\/.*token=/) + .to_return(status: status, body: body) + end + + subject { described_class.rna(siren) } + + context 'when siren does not exist' do + let(:siren) { '111111111' } + let(:status) { 404 } + let(:body) { '' } + + it 'raises RestClient::ResourceNotFound' do + expect { subject }.to raise_error(RestClient::ResourceNotFound) + end + end + + context 'when siren exists' do + let(:siren) { '418166096' } + let(:status) { 200 } + let(:body) { File.read('spec/support/files/rna.json') } + + it 'raises RestClient::Unauthorized' do + expect(subject).to eq(body) + end + end + end end diff --git a/spec/lib/siade/rna_adapter_spec.rb b/spec/lib/siade/rna_adapter_spec.rb new file mode 100644 index 000000000..d46e040a8 --- /dev/null +++ b/spec/lib/siade/rna_adapter_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe SIADE::RNAAdapter do + let(:siren) { '418166096' } + subject { described_class.new(siren).to_params } + + before do + stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/api\/v1\/associations\/.*token=/) + .to_return(body: File.read('spec/support/files/rna.json', status: 200)) + end + + it '#to_params class est une Hash ?' do + expect(subject).to be_an_instance_of(Hash) + end + + context 'Attributs Associations' do + it 'L\'associations contient bien un id' do + expect(subject[:id]).to eq('W595001988') + end + + it 'L\'associations contient bien un titre' do + expect(subject[:titre]).to eq('UN SUR QUATRE') + end + + it 'L\'associations contient bien un objet' do + expect(subject[:objet]).to eq("valoriser, transmettre et partager auprès des publics les plus larges possibles, les bienfaits de l'immigration, la richesse de la diversité et la curiosité de l'autre autrement") + end + + it 'L\'associations contient bien une date de creation' do + expect(subject[:date_creation]).to eq('2014-01-23') + end + + it 'L\'associations contient bien une date de de declaration' do + expect(subject[:date_declaration]).to eq('2014-01-24') + end + + it 'L\'associations contient bien une date de publication' do + expect(subject[:date_publication]).to eq('2014-02-08') + end + end +end diff --git a/spec/support/files/logo_test_procedure.png b/spec/support/files/logo_test_procedure.png new file mode 100644 index 000000000..f69cbb86b Binary files /dev/null and b/spec/support/files/logo_test_procedure.png differ diff --git a/spec/support/files/rna.json b/spec/support/files/rna.json new file mode 100644 index 000000000..057af35c5 --- /dev/null +++ b/spec/support/files/rna.json @@ -0,0 +1,30 @@ +{ + "association": { + "id": "W595001988", + "titre": "UN SUR QUATRE", + "objet": "valoriser, transmettre et partager auprès des publics les plus larges possibles, les bienfaits de l'immigration, la richesse de la diversité et la curiosité de l'autre autrement", + "siret": null, + "date_creation": "2014-01-23", + "date_declaration": "2014-01-24", + "date_publication": "2014-02-08", + "date_dissolution": "0001-01-01", + "adresse_siege": { + "complement": "", + "numero_voie": "61", + "type_voie": "RUE", + "libelle_voie": "des Noyers", + "distribution": "_", + "code_insee": "93063", + "code_postal": "93230", + "commune": "Romainville" + }, + "code_civilite_dirigeant": "PM", + "civilite_dirigeant": "Monsieur le Président", + "code_etat": "A", + "etat": "Active", + "code_groupement": "S", + "groupement": "simple", + "mise_a_jour": 1392295833 + }, + "date_extraction_donnees": 1427210585 +} \ No newline at end of file diff --git a/spec/views/users/dossiers/new_html.haml_spec.rb b/spec/views/users/dossiers/new_html.haml_spec.rb index c48b0f034..04f228de6 100644 --- a/spec/views/users/dossiers/new_html.haml_spec.rb +++ b/spec/views/users/dossiers/new_html.haml_spec.rb @@ -37,7 +37,8 @@ describe 'users/dossiers/new.html.haml', type: :view do end context 'procedure have logo' do - let(:logo) { fixture_file_upload('app/assets/images/logo_FC_02.png', 'image/png') } + # let(:logo) { fixture_file_upload('spec/support/files/logo_test_procedure.png', 'image/png') } + let(:logo) { File.new(File.join(::Rails.root.to_s, "/spec/support/files", "logo_test_procedure.png")) } it 'Procedure logo is present' do p subject