fix(champs.rnf): some foundations was removed from the registry. lucky us [or good archi ? :D], we kept api data
This commit is contained in:
parent
d8a0adc6ed
commit
e2ec5118f4
2 changed files with 47 additions and 20 deletions
|
@ -9,7 +9,7 @@ module Maintenance
|
|||
include Dry::Monads[:result]
|
||||
|
||||
def collection
|
||||
Champs::RNFChamp.where(value_json: nil)
|
||||
Champs::RNFChamp.where("external_id != null and data != null") # had been found
|
||||
# Collection to be iterated over
|
||||
# Must be Active Record Relation or Array
|
||||
end
|
||||
|
@ -23,8 +23,9 @@ module Maintenance
|
|||
rescue ActiveRecord::RecordInvalid
|
||||
# some champ might have dossier nil
|
||||
end
|
||||
else
|
||||
# not found
|
||||
else # fondation was removed, but we kept API data in data:, use it to restore stuff
|
||||
|
||||
champ.update_with_external_data!(data: champ.data.with_indifferent_access)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ module Maintenance
|
|||
|
||||
subject(:process) { described_class.process(element) }
|
||||
|
||||
context 'when api respond ok' do
|
||||
before do
|
||||
allow_any_instance_of(Champs::RNFChamp).to receive(:fetch_external_data).and_return(Success(data))
|
||||
end
|
||||
|
@ -67,5 +68,30 @@ module Maintenance
|
|||
})
|
||||
end
|
||||
end
|
||||
|
||||
context 'when api respond KO' do
|
||||
before do
|
||||
element.update(data:)
|
||||
allow_any_instance_of(Champs::RNFChamp).to receive(:fetch_external_data).and_return(Failure(code: 404, reason: :removed))
|
||||
end
|
||||
|
||||
it 'updates value_json' do
|
||||
expect { subject }.to change { element.reload.value_json }
|
||||
.from(nil)
|
||||
.to({
|
||||
"street_number" => "16",
|
||||
"street_name" => "Rue du Général de Boissieu",
|
||||
"street_address" => "16 Rue du Général de Boissieu",
|
||||
"postal_code" => "75015",
|
||||
"city_name" => "Paris 15e Arrondissement",
|
||||
"city_code" => "75115",
|
||||
"departement_code" => "75",
|
||||
"departement_name" => "Paris",
|
||||
"region_code" => "11",
|
||||
"region_name" => "Île-de-France"
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue