Skip to content

Commit 793ba0b

Browse files
Immediate Onboarding API fixes (#678)
## Status - Closes RaspberryPiFoundation/digital-editor-issues#1155 ## What's changed? - Verified school validation is skipped when Immediate Onboarding flag is enabled. --------- Co-authored-by: mwtrew <9936426+mwtrew@users.noreply.github.com> Co-authored-by: Matthew Trew <matthew.trew@raspberrypi.org>
1 parent b0fe355 commit 793ba0b

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

app/models/teacher_invitation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class TeacherInvitation < ApplicationRecord
66
belongs_to :school
77
validates :email_address,
88
format: { with: EmailValidator.regexp, message: I18n.t('validations.invitation.email_address') }
9-
validate :school_is_verified
9+
validate :school_is_verified, unless: -> { FeatureFlags.immediate_school_onboarding? }
1010
after_create_commit :send_invitation_email
1111
encrypts :email_address
1212

lib/concepts/school_student/create.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,26 @@ def create_student(school, school_student_params, token)
2222
password = DecryptionHelpers.decrypt_password(encrypted_password)
2323
name = school_student_params.fetch(:name)
2424

25-
validate(school:, username:, password:, name:)
25+
validate(
26+
username:,
27+
password:,
28+
name:,
29+
school: (FeatureFlags.immediate_school_onboarding? ? nil : school)
30+
)
2631

2732
response = ProfileApiClient.create_school_student(token:, username:, password:, name:, school_id:)
2833
user_id = response[:created].first
2934
Role.student.create!(school:, user_id:)
3035
user_id
3136
end
3237

33-
def validate(school:, username:, password:, name:)
34-
raise ArgumentError, 'school is not verified' unless school.verified?
38+
def validate(username:, password:, name:, school: nil)
3539
raise ArgumentError, "username '#{username}' is invalid" if username.blank?
3640
raise ArgumentError, "password '#{password}' is invalid" if password.size < 8
3741
raise ArgumentError, "name '#{name}' is invalid" if name.blank?
42+
43+
return unless school
44+
raise ArgumentError, 'school must be verified' unless school.verified?
3845
end
3946
end
4047
end

spec/concepts/school_student/create_spec.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,25 @@
7777
end
7878

7979
context 'when the school is not verified' do
80-
let(:school) { create(:school) }
80+
let(:school) { create(:school) } # not verified by default
81+
82+
context 'when immediate_school_onboarding is FALSE' do
83+
it 'returns the error message in the operation response' do
84+
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'false') do
85+
response = described_class.call(school:, school_student_params:, token:)
86+
expect(response[:error]).to match(/school must be verified/)
87+
end
88+
end
89+
end
8190

82-
it 'returns the error message in the operation response' do
83-
response = described_class.call(school:, school_student_params:, token:)
84-
expect(response[:error]).to match(/school is not verified/)
91+
context 'when immediate_school_onboarding is TRUE' do
92+
it 'does not error due to school verification' do
93+
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'true') do
94+
response = described_class.call(school:, school_student_params:, token:)
95+
96+
expect(response[:error]).to be_nil
97+
end
98+
end
8599
end
86100
end
87101

spec/concepts/school_teacher/invite_spec.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,22 @@
5353
context 'when the school is not verified' do
5454
let(:school) { create(:school) }
5555

56-
it 'returns the error message in the operation response' do
57-
response = described_class.call(school:, school_teacher_params:, token:)
58-
expect(response[:error]).to match(/School is not verified/)
56+
context 'when immediate_school_onboarding is FALSE' do
57+
it 'does return an error message in the operation response' do
58+
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'false') do
59+
response = described_class.call(school:, school_teacher_params:, token:)
60+
expect(response[:error]).to match(/is not verified/)
61+
end
62+
end
63+
end
64+
65+
context 'when immediate_school_onboarding is TRUE' do
66+
it 'does not return an error message in the operation response' do
67+
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'true') do
68+
response = described_class.call(school:, school_teacher_params:, token:)
69+
expect(response[:error]).to be_blank
70+
end
71+
end
5972
end
6073
end
6174
end

spec/models/teacher_invitation_spec.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@
1818
expect(invitation).not_to be_valid
1919
end
2020

21-
it 'is invalid with an unverified school' do
22-
school = build(:school, verified_at: nil)
23-
invitation = build(:teacher_invitation, school:)
21+
it 'is valid with an unverified school and immediate_school_onboarding is TRUE' do
22+
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'true') do
23+
school = build(:school, verified_at: nil)
24+
invitation = build(:teacher_invitation, school:)
2425

25-
expect(invitation).not_to be_valid
26+
expect(invitation).to be_valid
27+
end
28+
end
29+
30+
it 'is invalid with an unverified school and immediate_school_onboarding is FALSE' do
31+
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'false') do
32+
school = build(:school, verified_at: nil)
33+
invitation = build(:teacher_invitation, school:)
34+
35+
expect(invitation).not_to be_valid
36+
end
2637
end
2738

2839
it 'sends an invitation email after create' do

0 commit comments

Comments
 (0)