Skip to content

Commit 5b48fa2

Browse files
committed
Ensure only open schools are onboarded
This adds validation to the onboarding process to ensure that only schools with a status of open or opening are added to the onboarding files, helping to ensure that we don't onboard a location that isn't open.
1 parent 15ebfb4 commit 5b48fa2

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

app/models/onboarding.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,14 @@ class ExistingSchool
133133
validates :existing_team, absence: true
134134
validates :location, presence: true
135135
validates :team, presence: true
136+
validates :status, inclusion: %w[open opening]
136137

137138
def location
138139
@location ||= Location.school.find_by(urn:)
139140
end
140141

142+
delegate :status, to: :location, allow_nil: true
143+
141144
def existing_team
142145
location&.team
143146
end

spec/fixtures/files/onboarding/invalid.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ teams:
77

88
schools:
99
unknown_team: [123456, 234567]
10+
team_1: [567890]

spec/models/onboarding_spec.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
let!(:programme) { create(:programme, :hpv) }
99
# rubocop:disable RSpec/IndexedLet
10-
let!(:school1) { create(:school, :secondary, urn: "123456") }
11-
let!(:school2) { create(:school, :secondary, urn: "234567") }
12-
let!(:school3) { create(:school, :secondary, urn: "345678") }
13-
let!(:school4) { create(:school, :secondary, urn: "456789") }
10+
let!(:school1) { create(:school, :secondary, :open, urn: "123456") }
11+
let!(:school2) { create(:school, :secondary, :open, urn: "234567") }
12+
let!(:school3) { create(:school, :secondary, :open, urn: "345678") }
13+
let!(:school4) { create(:school, :secondary, :open, urn: "456789") }
1414
# rubocop:enable RSpec/IndexedLet
1515

16+
before { create(:school, :secondary, :closed, urn: "567890") }
17+
1618
context "with a valid configuration file" do
1719
let(:filename) { "onboarding/valid.yaml" }
1820

@@ -71,6 +73,7 @@
7173
"organisation.privacy_policy_url": ["can't be blank"],
7274
"school.0.team": ["can't be blank"],
7375
"school.1.team": ["can't be blank"],
76+
"school.2.status": ["is not included in the list"],
7477
"team.email": ["can't be blank"],
7578
"team.name": ["can't be blank"],
7679
clinics: ["can't be blank"],

0 commit comments

Comments
 (0)