Skip to content

Commit ea4c433

Browse files
committed
Fetch location positions on creation
When creating new locations, either via onboarding a new team or by explicitly creating a new clinic, we should fetch the position of the location so that it's up to date. I've intentionally not done this after the GIAS import as we have a job that runs overnight which collects any locations that have an address and no location so these will eventually be up to date. Jira-Issue: MAV-6379
1 parent 83edff4 commit ea4c433

4 files changed

Lines changed: 31 additions & 9 deletions

File tree

app/lib/mavis_cli/clinics/create.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ def call(
2626
)
2727
MavisCLI.load_rails
2828

29-
Location.create!(
30-
type: :community_clinic,
31-
name:,
32-
address_line_1:,
33-
address_town:,
34-
address_postcode:,
35-
ods_code:
36-
)
29+
location =
30+
Location.create!(
31+
type: :community_clinic,
32+
name:,
33+
address_line_1:,
34+
address_town:,
35+
address_postcode:,
36+
ods_code:
37+
)
38+
39+
LocationPositionUpdaterJob.perform_async(location.id)
3740
end
3841
end
3942
end

app/models/onboarding.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ def save!(include_previous_academic_year: false)
249249
end
250250

251251
PatientTeamUpdater.call(team_scope: Team.where(id: team.id))
252+
253+
location_ids =
254+
schools.map(&:id) + clinics.keys.filter(&:has_address?).map(&:id)
255+
LocationPositionUpdaterJob.perform_bulk(location_ids.zip)
252256
end
253257
end
254258

@@ -311,7 +315,7 @@ def location
311315
@location ||= Location.gias_school.find_by_urn_and_site(urn)
312316
end
313317

314-
delegate :status, to: :location, allow_nil: true
318+
delegate :id, :status, to: :location, allow_nil: true
315319
delegate :team, to: :subteam
316320

317321
def save!
@@ -347,6 +351,8 @@ class NewSchoolSite
347351
validates :name, presence: true
348352
validates :site, presence: true
349353

354+
delegate :id, to: :location
355+
350356
def original_location
351357
@original_location ||= Location.gias_school.find_by_urn_and_site(urn)
352358
end

spec/features/cli_clinics_create_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
it "runs successfully" do
88
when_i_run_the_command
99
then_the_clinic_is_created
10+
and_a_location_position_updater_job_is_enqueued
1011
end
1112
end
1213

@@ -29,4 +30,10 @@ def then_the_clinic_is_created
2930
expect(clinic.address_town).to eq("Town")
3031
expect(clinic.address_postcode).to eq("SW1A 1AA")
3132
end
33+
34+
def and_a_location_position_updater_job_is_enqueued
35+
expect(LocationPositionUpdaterJob).to have_enqueued_sidekiq_job(
36+
Location.last.id
37+
)
38+
end
3239
end

spec/models/onboarding_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,16 @@
7171
clinic1 = subteam1.community_clinics.find_by!(ods_code: nil)
7272
expect(clinic1.name).to eq("10 Downing Street")
7373
expect(clinic1.address_postcode).to eq("SW1A 1AA")
74+
expect(LocationPositionUpdaterJob).to have_enqueued_sidekiq_job(
75+
clinic1.id
76+
)
7477

7578
clinic2 = subteam2.community_clinics.find_by!(ods_code: "SW1A11")
7679
expect(clinic2.name).to eq("11 Downing Street")
7780
expect(clinic2.address_postcode).to eq("SW1A 1AA")
81+
expect(LocationPositionUpdaterJob).to have_enqueued_sidekiq_job(
82+
clinic2.id
83+
)
7884
end
7985
end
8086

0 commit comments

Comments
 (0)