diff --git a/app/models/teacher_invitation.rb b/app/models/teacher_invitation.rb index bb058c570..68576b5b7 100644 --- a/app/models/teacher_invitation.rb +++ b/app/models/teacher_invitation.rb @@ -6,7 +6,7 @@ class TeacherInvitation < ApplicationRecord belongs_to :school validates :email_address, format: { with: EmailValidator.regexp, message: I18n.t('validations.invitation.email_address') } - validate :school_is_verified + validate :school_is_verified, unless: -> { FeatureFlags.immediate_school_onboarding? } after_create_commit :send_invitation_email encrypts :email_address diff --git a/lib/concepts/school_student/create.rb b/lib/concepts/school_student/create.rb index 0d4d3925c..1c0745d00 100644 --- a/lib/concepts/school_student/create.rb +++ b/lib/concepts/school_student/create.rb @@ -22,7 +22,12 @@ def create_student(school, school_student_params, token) password = DecryptionHelpers.decrypt_password(encrypted_password) name = school_student_params.fetch(:name) - validate(school:, username:, password:, name:) + validate( + username:, + password:, + name:, + school: (FeatureFlags.immediate_school_onboarding? ? nil : school) + ) response = ProfileApiClient.create_school_student(token:, username:, password:, name:, school_id:) user_id = response[:created].first @@ -30,11 +35,13 @@ def create_student(school, school_student_params, token) user_id end - def validate(school:, username:, password:, name:) - raise ArgumentError, 'school is not verified' unless school.verified? + def validate(username:, password:, name:, school: nil) raise ArgumentError, "username '#{username}' is invalid" if username.blank? raise ArgumentError, "password '#{password}' is invalid" if password.size < 8 raise ArgumentError, "name '#{name}' is invalid" if name.blank? + + return unless school + raise ArgumentError, 'school must be verified' unless school.verified? end end end diff --git a/spec/concepts/school_student/create_spec.rb b/spec/concepts/school_student/create_spec.rb index 4d2d87c5a..1981f0a00 100644 --- a/spec/concepts/school_student/create_spec.rb +++ b/spec/concepts/school_student/create_spec.rb @@ -77,11 +77,25 @@ end context 'when the school is not verified' do - let(:school) { create(:school) } + let(:school) { create(:school) } # not verified by default + + context 'when immediate_school_onboarding is FALSE' do + it 'returns the error message in the operation response' do + ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'false') do + response = described_class.call(school:, school_student_params:, token:) + expect(response[:error]).to match(/school must be verified/) + end + end + end - it 'returns the error message in the operation response' do - response = described_class.call(school:, school_student_params:, token:) - expect(response[:error]).to match(/school is not verified/) + context 'when immediate_school_onboarding is TRUE' do + it 'does not error due to school verification' do + ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'true') do + response = described_class.call(school:, school_student_params:, token:) + + expect(response[:error]).to be_nil + end + end end end diff --git a/spec/concepts/school_teacher/invite_spec.rb b/spec/concepts/school_teacher/invite_spec.rb index 43439010b..231d8cbda 100644 --- a/spec/concepts/school_teacher/invite_spec.rb +++ b/spec/concepts/school_teacher/invite_spec.rb @@ -53,9 +53,22 @@ context 'when the school is not verified' do let(:school) { create(:school) } - it 'returns the error message in the operation response' do - response = described_class.call(school:, school_teacher_params:, token:) - expect(response[:error]).to match(/School is not verified/) + context 'when immediate_school_onboarding is FALSE' do + it 'does return an error message in the operation response' do + ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'false') do + response = described_class.call(school:, school_teacher_params:, token:) + expect(response[:error]).to match(/is not verified/) + end + end + end + + context 'when immediate_school_onboarding is TRUE' do + it 'does not return an error message in the operation response' do + ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'true') do + response = described_class.call(school:, school_teacher_params:, token:) + expect(response[:error]).to be_blank + end + end end end end diff --git a/spec/models/teacher_invitation_spec.rb b/spec/models/teacher_invitation_spec.rb index d77a33762..d1706e08e 100644 --- a/spec/models/teacher_invitation_spec.rb +++ b/spec/models/teacher_invitation_spec.rb @@ -18,11 +18,22 @@ expect(invitation).not_to be_valid end - it 'is invalid with an unverified school' do - school = build(:school, verified_at: nil) - invitation = build(:teacher_invitation, school:) + it 'is valid with an unverified school and immediate_school_onboarding is TRUE' do + ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'true') do + school = build(:school, verified_at: nil) + invitation = build(:teacher_invitation, school:) - expect(invitation).not_to be_valid + expect(invitation).to be_valid + end + end + + it 'is invalid with an unverified school and immediate_school_onboarding is FALSE' do + ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'false') do + school = build(:school, verified_at: nil) + invitation = build(:teacher_invitation, school:) + + expect(invitation).not_to be_valid + end end it 'sends an invitation email after create' do