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,25 +46,51 @@ module Maintenance
subject(:process) { described_class.process(element) } subject(:process) { described_class.process(element) }
before do context 'when api respond ok' do
allow_any_instance_of(Champs::RNFChamp).to receive(:fetch_external_data).and_return(Success(data)) before do
allow_any_instance_of(Champs::RNFChamp).to receive(:fetch_external_data).and_return(Success(data))
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
it 'updates value_json' do context 'when api respond KO' do
expect { subject }.to change { element.reload.value_json } before do
.from(nil) element.update(data:)
.to({ allow_any_instance_of(Champs::RNFChamp).to receive(:fetch_external_data).and_return(Failure(code: 404, reason: :removed))
"street_number" => "16", end
"street_name" => "Rue du Général de Boissieu",
"street_address" => "16 Rue du Général de Boissieu", it 'updates value_json' do
"postal_code" => "75015", expect { subject }.to change { element.reload.value_json }
"city_name" => "Paris 15e Arrondissement", .from(nil)
"city_code" => "75115", .to({
"departement_code" => "75", "street_number" => "16",
"departement_name" => "Paris", "street_name" => "Rue du Général de Boissieu",
"region_code" => "11", "street_address" => "16 Rue du Général de Boissieu",
"region_name" => "Île-de-France" "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