Add lib RNA connect to apientreprise
This commit is contained in:
parent
d49e9fe75a
commit
704e491cd0
8 changed files with 136 additions and 1 deletions
|
@ -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'
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
28
lib/siade/rna_adapter.rb
Normal file
28
lib/siade/rna_adapter.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
41
spec/lib/siade/rna_adapter_spec.rb
Normal file
41
spec/lib/siade/rna_adapter_spec.rb
Normal file
|
@ -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
|
BIN
spec/support/files/logo_test_procedure.png
Normal file
BIN
spec/support/files/logo_test_procedure.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 53 KiB |
30
spec/support/files/rna.json
Normal file
30
spec/support/files/rna.json
Normal file
|
@ -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
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue