data(backfill): Champs::SiretChamp.value_json [±1.4M occurences]

This commit is contained in:
mfo 2024-08-20 10:27:27 +02:00
parent 917f25dcfd
commit a66bd46082
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
2 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
module Maintenance
class PopulateSiretValueJSONTask < MaintenanceTasks::Task
def collection
Champs::SiretChamp.where.not(value: nil)
end
def process(champ)
return if champ.etablissement.blank?
champ.update!(value_json: APIGeoService.parse_etablissement_address(champ.etablissement))
end
def count
# not really interested in counting because it raises PG Statement timeout
end
end
end

View file

@ -0,0 +1,31 @@
# frozen_string_literal: true
require "rails_helper"
module Maintenance
RSpec.describe PopulateSiretValueJSONTask do
describe "#process" do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) }
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
let(:element) { dossier.champs.first }
subject(:process) { described_class.process(element) }
it 'updates value_json' do
expect { subject }.to change { element.reload.value_json }
.from(nil)
.to({
"city_code" => "92009",
"city_name" => "Bois-Colombes",
"postal_code" => "92270",
"region_code" => "11",
"region_name" => "Île-de-France",
"street_name" => "RAOUL NORDLING",
"street_number" => "6",
"street_address" => "6 RUE RAOUL NORDLING",
"departement_code" => "92",
"departement_name" => "Hauts-de-Seine"
})
end
end
end
end