Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/teacher_invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 10 additions & 3 deletions lib/concepts/school_student/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,26 @@ 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
Role.student.create!(school:, user_id:)
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
Expand Down
22 changes: 18 additions & 4 deletions spec/concepts/school_student/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 16 additions & 3 deletions spec/concepts/school_teacher/invite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 15 additions & 4 deletions spec/models/teacher_invitation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down