Merge pull request #10802 from mfo/US/fix-rnf-with-removed-fondation

Correctif: ETQ usager/instructeur, je souhaite pouvoir visualiser les dossiers ayant un champ fondation dont celle ci a ete supprimé du registre
This commit is contained in:
mfo 2024-09-16 13:48:05 +00:00 committed by GitHub
commit 4bd518f85e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 20 deletions

View file

@ -9,7 +9,7 @@ module Maintenance
include Dry::Monads[:result] include Dry::Monads[:result]
def collection 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 # Collection to be iterated over
# Must be Active Record Relation or Array # Must be Active Record Relation or Array
end end
@ -23,8 +23,9 @@ module Maintenance
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid
# some champ might have dossier nil # some champ might have dossier nil
end end
else else # fondation was removed, but we kept API data in data:, use it to restore stuff
# not found
champ.update_with_external_data!(data: champ.data.with_indifferent_access)
end end
end end

View file

@ -46,6 +46,7 @@ module Maintenance
subject(:process) { described_class.process(element) } subject(:process) { described_class.process(element) }
context 'when api respond ok' do
before do before do
allow_any_instance_of(Champs::RNFChamp).to receive(:fetch_external_data).and_return(Success(data)) allow_any_instance_of(Champs::RNFChamp).to receive(:fetch_external_data).and_return(Success(data))
end end
@ -67,5 +68,30 @@ module Maintenance
}) })
end end
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
end end