From be965e4fdd0abb29d72fcb44f317e144019890c2 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 5 Sep 2022 15:52:06 +0200 Subject: [PATCH] fix(api_entreprise): don't fail with entreprise without date_creation --- app/lib/api_entreprise/entreprise_adapter.rb | 2 +- spec/lib/api_entreprise/entreprise_adapter_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/lib/api_entreprise/entreprise_adapter.rb b/app/lib/api_entreprise/entreprise_adapter.rb index 3677c7ce5..90176e21d 100644 --- a/app/lib/api_entreprise/entreprise_adapter.rb +++ b/app/lib/api_entreprise/entreprise_adapter.rb @@ -10,7 +10,7 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter params[:etat_administratif] = map_etat_administratif(data_source) if params.present? && valid_params?(params) - params[:date_creation] = Time.zone.at(params[:date_creation]).to_datetime + params[:date_creation] = Time.zone.at(params[:date_creation]).to_datetime if params[:date_creation].present? params.transform_keys { |k| :"entreprise_#{k}" } else {} diff --git a/spec/lib/api_entreprise/entreprise_adapter_spec.rb b/spec/lib/api_entreprise/entreprise_adapter_spec.rb index f2dd7bc2f..cbad7604f 100644 --- a/spec/lib/api_entreprise/entreprise_adapter_spec.rb +++ b/spec/lib/api_entreprise/entreprise_adapter_spec.rb @@ -72,6 +72,18 @@ describe APIEntreprise::EntrepriseAdapter do expect(subject[:entreprise_etat_administratif]).to eq('actif') end end + + context "when date_creation is empty" do + let(:body) do + hash = JSON.parse(super()) + hash["entreprise"]["date_creation"] = nil + JSON.generate(hash) + end + + it 'L\'entreprise ne contient pas de date_creation' do + expect(subject[:entreprise_date_creation]).to be_nil + end + end end context "when the SIRET is unknown" do