Skip to content

Commit 3134353

Browse files
committed
Add back in validate wrapped in feature flag, add tests
1 parent e07f43a commit 3134353

4 files changed

Lines changed: 60 additions & 5 deletions

File tree

app/models/teacher_invitation.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +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, unless: -> { FeatureFlags.immediate_school_onboarding? }
910
after_create_commit :send_invitation_email
1011
encrypts :email_address
1112

@@ -15,6 +16,12 @@ class TeacherInvitation < ApplicationRecord
1516

1617
private
1718

19+
def school_is_verified
20+
return if school.verified?
21+
22+
errors.add(:school, 'is not verified')
23+
end
24+
1825
def send_invitation_email
1926
InvitationMailer.with(invitation: self).invite_teacher.deliver_later
2027
end

lib/concepts/school_student/create.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +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(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(username:, password:, name:)
38+
def validate(username:, password:, name:, school: nil)
3439
raise ArgumentError, "username '#{username}' is invalid" if username.blank?
3540
raise ArgumentError, "password '#{password}' is invalid" if password.size < 8
3641
raise ArgumentError, "name '#{name}' is invalid" if name.blank?
42+
43+
return unless school
44+
raise ArgumentError, 'school must be verified' unless school.verified?
3745
end
3846
end
3947
end

spec/concepts/school_student/create_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@
7676
end
7777
end
7878

79+
context 'when the school is not verified' do
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
90+
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
99+
end
100+
end
101+
79102
context 'when the student cannot be created in profile api because of a 422 response' do
80103
let(:error) { { 'message' => "something's up with the username" } }
81104
let(:exception) { ProfileApiClient::Student422Error.new(error) }

spec/concepts/school_teacher/invite_spec.rb

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

56-
it 'does not return an error message in the operation response' do
57-
response = described_class.call(school:, school_teacher_params:, token:)
58-
expect(response[:error]).to be_blank
56+
context 'when immediate_school_onboarding is FALSE' do
57+
# before do
58+
# allow(FeatureFlags).to receive(:immediate_school_onboarding?).and_return(false)
59+
# end
60+
61+
it 'does return an error message in the operation response' do
62+
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'false') do
63+
response = described_class.call(school:, school_teacher_params:, token:)
64+
expect(response[:error]).to match(/is not verified/)
65+
end
66+
end
67+
end
68+
69+
context 'when immediate_school_onboarding is TRUE' do
70+
it 'does not return an error message in the operation response' do
71+
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'true') do
72+
response = described_class.call(school:, school_teacher_params:, token:)
73+
expect(response[:error]).to be_blank
74+
end
75+
end
5976
end
6077
end
6178
end

0 commit comments

Comments
 (0)