Skip to content

Commit 4ced0da

Browse files
authored
Merge pull request #12272 from demarches-simplifiees/add_task_to_fetch_missing_etablissement
Tech: ajoute une tache pour récupérer des champs.etablissement manquants
2 parents 9ebb4d3 + fd304d7 commit 4ced0da

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
module Maintenance
4+
class T20251031backfillMissingEtablissementTask < MaintenanceTasks::Task
5+
# Cette tâche permet de re-fetch les établissements manquants
6+
7+
include RunnableOnDeployConcern
8+
include StatementsHelpersConcern
9+
10+
csv_collection
11+
12+
def process(row)
13+
champ = Champs::SiretChamp.find_by(id: row["champ_id"].to_i)
14+
15+
return if champ.nil?
16+
return if champ.external_id.nil?
17+
18+
champ.reset_external_data!
19+
champ.fetch_later! if champ.may_fetch_later?
20+
end
21+
end
22+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
module Maintenance
6+
RSpec.describe T20251031backfillMissingEtablissementTask do
7+
describe "#process" do
8+
subject(:process) { described_class.process(element) }
9+
10+
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) }
11+
let(:dossier) { create(:dossier, procedure:) }
12+
let(:champ) { dossier.project_champs_public.first }
13+
let(:element) { { "champ_id" => champ.id.to_s } }
14+
15+
context "when champ exists with external_id" do
16+
before do
17+
champ.update(external_id: "13002526500013")
18+
end
19+
20+
it "resets and fetches external data" do
21+
expect_any_instance_of(Champs::SiretChamp).to receive(:reset_external_data!)
22+
expect_any_instance_of(Champs::SiretChamp).to receive(:fetch_later!)
23+
process
24+
end
25+
end
26+
27+
context "when champ does not exist" do
28+
let(:element) { { "champ_id" => "999999" } }
29+
30+
it "does nothing" do
31+
expect { process }.not_to raise_error
32+
end
33+
end
34+
35+
context "when champ has no external_id" do
36+
before do
37+
champ.update(external_id: nil)
38+
end
39+
40+
it "does nothing" do
41+
expect { process }.not_to raise_error
42+
end
43+
end
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)