diff --git a/ruby/lib/jam_ruby/app/mailers/user_mailer.rb b/ruby/lib/jam_ruby/app/mailers/user_mailer.rb index 78a8ae357..6bccf6e58 100644 --- a/ruby/lib/jam_ruby/app/mailers/user_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/user_mailer.rb @@ -672,7 +672,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [lesson_booking.teacher.id]) + sendgrid_substitute('@USERID', lesson_booking.school_over_teacher_ids) mail(:to => email, :subject => subject) do |format| format.text @@ -729,7 +729,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [lesson_session.teacher.id]) + sendgrid_substitute('@USERID', lesson_session.school_and_teacher_ids) mail(:to => email, :subject => @subject) do |format| format.text @@ -786,7 +786,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [lesson_session.teacher.id]) + sendgrid_substitute('@USERID', lesson_session.school_and_teacher_ids) mail(:to => email, :subject => subject) do |format| format.text @@ -885,7 +885,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID', lesson_session.school_over_teacher_ids) mail(:to => email, :subject => subject) do |format| format.text @@ -915,7 +915,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID', lesson_session.school_and_teacher_ids) mail(:to => email, :subject => subject) do |format| format.text @@ -967,7 +967,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID', lesson_session.school_and_teacher_ids) mail(:to => email, :subject => subject) do |format| format.text @@ -1068,7 +1068,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID', lesson_session.school_and_teacher_ids) mail(:to => email, :subject => subject) do |format| format.text @@ -1117,7 +1117,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID', lesson_session.school_over_teacher_ids) mail(:to => email, :subject => subject) do |format| format.text @@ -1234,7 +1234,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID', lesson_booking.school_over_teacher_ids) mail(:to => email, :subject => @subject) do |format| format.text @@ -1294,7 +1294,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID', lesson_booking.school_over_teacher_ids) mail(:to => email, :subject => @subject) do |format| format.text @@ -1341,7 +1341,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID',@distribution.target.lesson_booking.school_over_teacher_ids ) mail(:to => email, :subject => @subject) do |format| format.text @@ -1393,7 +1393,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@payable_teacher.id]) + sendgrid_substitute('@USERID', @distribution.target.lesson_booking.school_over_teacher_ids) mail(:to => email, :subject => @subject) do |format| format.text @@ -1552,7 +1552,7 @@ module JamRuby sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID', @lesson_booking.school_and_teacher_ids) mail(:to => email, :subject => @subject) do |format| format.text @@ -1601,7 +1601,7 @@ module JamRuby sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID', @lesson_booking.school_and_teacher_ids) mail(:to => email, :subject => @subject) do |format| format.text @@ -1658,14 +1658,14 @@ module JamRuby @session_description = @lesson_session.music_session.description @session_date = @lesson_session.slot.pretty_scheduled_start(true) - email = @target.email + email = @lesson_session.school_over_teacher @subject = "#{@sender.name} has sent you a message about a lesson" unique_args = {:type => "lesson_chat"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] - sendgrid_recipients([email]) - sendgrid_substitute('@USERID', [@target.id]) + sendgrid_recipients(email) + sendgrid_substitute('@USERID', @lesson_session.school_over_teacher_ids) mail(:to => email, :subject => @subject) do |format| format.text @@ -1713,7 +1713,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients(email) - sendgrid_substitute('@USERID', [@teacher.id]) + sendgrid_substitute('@USERID', lesson_session.school_over_teacher_ids) mail(:to => email, :subject => @subject) do |format| format.text diff --git a/ruby/lib/jam_ruby/models/chat_message.rb b/ruby/lib/jam_ruby/models/chat_message.rb index bcd75fb5a..d30a3181e 100644 --- a/ruby/lib/jam_ruby/models/chat_message.rb +++ b/ruby/lib/jam_ruby/models/chat_message.rb @@ -24,8 +24,13 @@ module JamRuby validates :message, length: {minimum: 1, maximum: 255}, no_profanity: true, unless: :ignore_message_checks def self.create(user, music_session, message, channel, client_id, target_user = nil, lesson_session = nil, purpose = nil, music_notation = nil, recording = nil) + source_user = user + # we hide the real source user; always make it from the teacher + if lesson_session && user.id != lesson_session.student_id + source_user = lesson_session.teacher + end chat_msg = ChatMessage.new - chat_msg.user_id = user.id + chat_msg.user_id = source_user.id chat_msg.music_session_id = music_session.id if music_session chat_msg.message = message chat_msg.channel = channel @@ -39,7 +44,7 @@ module JamRuby if lesson_session chat_msg.ignore_message_checks = true - if user.id == lesson_session.student.id + if source_user.id == lesson_session.student.id lesson_session.teacher_unread_messages = true target = lesson_session.teacher Notification.send_lesson_message('chat', lesson_session, false, message) @@ -59,7 +64,7 @@ module JamRuby end if chat_msg.save - ChatMessage.send_chat_msg music_session, chat_msg, user, client_id, channel, lesson_session, purpose, target_user, music_notation, recording + ChatMessage.send_chat_msg music_session, chat_msg, source_user, client_id, channel, lesson_session, purpose, target_user, music_notation, recording end chat_msg end diff --git a/ruby/lib/jam_ruby/models/lesson_booking.rb b/ruby/lib/jam_ruby/models/lesson_booking.rb index d170e140b..0d69548fc 100644 --- a/ruby/lib/jam_ruby/models/lesson_booking.rb +++ b/ruby/lib/jam_ruby/models/lesson_booking.rb @@ -770,20 +770,37 @@ module JamRuby def school_and_teacher if school && school.scheduling_comm? - [school.correspondence_email, teacher.email] + [school.communication_email, teacher.email] else [teacher.email] end end + def school_and_teacher_ids + if school && school.scheduling_comm? + [school.owner.id, teacher.id] + else + [teacher.id] + end + end + + def school_over_teacher if school && school.scheduling_comm? - [school.correspondence_email] + [school.communication_email] else [teacher.email] end end + def school_over_teacher_ids + if school && school.scheduling_comm? + [school.owner.id] + else + [teacher.id] + end + end + def self.find_bookings_needing_sessions(minimum_start_time) MusicSession.select([:lesson_booking_id]).joins(:lesson_session => :lesson_booking).where("lesson_bookings.active = true").where('lesson_bookings.recurring = true').where("scheduled_start is not null").where("scheduled_start > ?", minimum_start_time).group(:lesson_booking_id).having('count(lesson_booking_id) < 2') end diff --git a/ruby/lib/jam_ruby/models/lesson_session.rb b/ruby/lib/jam_ruby/models/lesson_session.rb index 0b0b69acf..a1c946359 100644 --- a/ruby/lib/jam_ruby/models/lesson_session.rb +++ b/ruby/lib/jam_ruby/models/lesson_session.rb @@ -11,7 +11,7 @@ module JamRuby @@log = Logging.logger[LessonSession] delegate :sent_billing_notices, :last_billing_attempt_at, :billing_attempts, :billing_should_retry, :billed_at, :billing_error_detail, :billing_error_reason, :is_card_declined?, :is_card_expired?, :last_billed_at_date, :sent_billing_notices, to: :lesson_payment_charge, allow_nil: true - delegate :is_test_drive?, :is_single_free?, :is_normal?, :approved_before?, :is_active?, :recurring, :is_monthly_payment?, :school_on_school?, :scheduling_email, :teacher_school_emails, :school_and_teacher, :school_over_teacher, to: :lesson_booking + delegate :is_test_drive?, :is_single_free?, :is_normal?, :approved_before?, :is_active?, :recurring, :is_monthly_payment?, :school_on_school?, :scheduling_email, :teacher_school_emails, :school_and_teacher, :school_over_teacher, :school_and_teacher_ids, :school_over_teacher_ids, to: :lesson_booking delegate :pretty_scheduled_start, to: :music_session @@ -78,12 +78,13 @@ module JamRuby scope :upcoming, -> { joins(:music_session).where('music_sessions.scheduled_start > ?', Time.now) } scope :past_cancel_window, -> { joins(:music_session).where('music_sessions.scheduled_start > ?', 24.hours.from_now) } # show all requested/countered sessions where the student was the last to communicate - scope :slow_responses, -> {joins(:lesson_booking).where('lesson_sessions.status = ? OR lesson_sessions.status = ?', LessonSession::STATUS_REQUESTED, LessonSession::STATUS_COUNTERED) - .where('lesson_bookings.counterer_id IS NULL OR lesson_bookings.user_id = lesson_bookings.counterer_id') - .order('(COALESCE(lesson_bookings.countered_at, lesson_bookings.sent_notices_at)) ASC')} - scope :least_time_left, -> {joins(:lesson_booking, :music_session).where('lesson_sessions.status = ? OR lesson_sessions.status = ?', LessonSession::STATUS_REQUESTED, LessonSession::STATUS_COUNTERED) - .where('lesson_bookings.counterer_id IS NULL OR lesson_bookings.user_id = lesson_bookings.counterer_id') - .order('music_sessions.scheduled_start DESC')} + scope :slow_responses, -> { joins(:lesson_booking).where('lesson_sessions.status = ? OR lesson_sessions.status = ?', LessonSession::STATUS_REQUESTED, LessonSession::STATUS_COUNTERED) + .where('lesson_bookings.counterer_id IS NULL OR lesson_bookings.user_id = lesson_bookings.counterer_id') + .order('(COALESCE(lesson_bookings.countered_at, lesson_bookings.sent_notices_at)) ASC') } + scope :least_time_left, -> { joins(:lesson_booking, :music_session).where('lesson_sessions.status = ? OR lesson_sessions.status = ?', LessonSession::STATUS_REQUESTED, LessonSession::STATUS_COUNTERED) + .where('lesson_bookings.counterer_id IS NULL OR lesson_bookings.user_id = lesson_bookings.counterer_id') + .order('music_sessions.scheduled_start DESC') } + def create_charge if !school_on_school? && !is_test_drive? && !is_monthly_payment? self.lesson_payment_charge = LessonPaymentCharge.new @@ -141,6 +142,7 @@ module JamRuby lesson_session.lesson_booking.save(validate: false) end end + def self.auto_cancel MusicSession.joins(lesson_session: :lesson_booking).where('lesson_sessions.status = ?', LessonSession::STATUS_REQUESTED).where("? > scheduled_start + (INTERVAL '1 minutes' * (duration))", Time.now).each do |music_session| lesson_session = music_session.lesson_session @@ -531,6 +533,7 @@ module JamRuby self.autocanceling = false end + def validate_canceled if !is_canceled? self.errors.add(:status, "This session is already #{self.status}.") @@ -580,21 +583,45 @@ module JamRuby limit ||= 100 limit = limit.to_i + school_owner = user.owned_school && user.owned_school.scheduling_comm? + + is_teacher = !user.teacher.nil? + query = LessonSession.unscoped.joins([:music_session, :lesson_booking]).joins(music_session: :creator) #query = query.includes([:teacher, :music_session]) query = query.includes([:music_session]) query = query.order('music_sessions.scheduled_start DESC') - if params[:as_teacher].present? - if params[:as_teacher] == true || params[:as_teacher] == "true" - if user.teacher && user.teacher.school_id - school_extra = "OR (lesson_bookings.school_id = '#{user.teacher.school_id}')" + if params[:as_teacher].present? + if school_owner || params[:as_teacher] == true || params[:as_teacher] == "true" + + # if a school owner is viewing, grab his owned school ID. Otherwise use a teacher's school ID, if applicable + school_id = school_owner ? user.owned_school.id : (user.teacher ? user.teacher.school_id : nil) + + if school_id + school_extra = "OR (lesson_bookings.school_id = '#{school_id}')" else school_extra = '' end - query = query.where('lesson_sessions.teacher_id = ?', user.id) + if school_owner + extra_teacher= '' + if is_teacher + # if the school owner is a teacher, show his bookings too + extra_teacher = " OR lesson_sessions.teacher_id = '#{user.teacher.id}'" + end + query = query.where('lesson_sessions.teacher_id in (?)' + extra_teacher, user.owned_school.teachers.map {|t| t.user.id}) + query = query.where('lesson_sessions.status = ? OR lesson_sessions.status = ?', LessonSession::STATUS_REQUESTED, LessonSession::STATUS_COUNTERED) + else + # this is a normal teacher (not a school owner) + if school_id && user.teacher.school.scheduling_comm? + # the school wants to control scheduling communication. So hide sessions in the requested/countered status from them + query = query.where('lesson_sessions.status != ? AND lesson_sessions.status != ?', LessonSession::STATUS_REQUESTED, LessonSession::STATUS_COUNTERED) + end + query = query.where('lesson_sessions.teacher_id = ?', user.id) + end + else if user.school_id school_extra = "OR (lesson_bookings.school_id = '#{user.school_id}')" diff --git a/ruby/lib/jam_ruby/models/school.rb b/ruby/lib/jam_ruby/models/school.rb index e5e79373d..1e7523b50 100644 --- a/ruby/lib/jam_ruby/models/school.rb +++ b/ruby/lib/jam_ruby/models/school.rb @@ -16,8 +16,8 @@ module JamRuby belongs_to :user, class_name: ::JamRuby::User, inverse_of: :owned_school belongs_to :affiliate_partner, class_name: "JamRuby::AffiliatePartner" - has_many :students, class_name: ::JamRuby::User - has_many :teachers, class_name: ::JamRuby::Teacher + has_many :students, class_name: "JamRuby::User" + has_many :teachers, class_name: "JamRuby::Teacher" has_many :school_invitations, class_name: 'JamRuby::SchoolInvitation' has_many :teacher_payments, class_name: 'JamRuby::TeacherPayment' has_many :teacher_distributions, class_name: 'JamRuby::TeacherDistribution' diff --git a/ruby/spec/jam_ruby/models/lesson_session_spec.rb b/ruby/spec/jam_ruby/models/lesson_session_spec.rb index 48c158e32..3988a2176 100644 --- a/ruby/spec/jam_ruby/models/lesson_session_spec.rb +++ b/ruby/spec/jam_ruby/models/lesson_session_spec.rb @@ -247,5 +247,42 @@ describe LessonSession do query = LessonSession.index(FactoryGirl.create(:user), {as_teacher: true})[:query] query.length.should eq 0 end + + describe "schools" do + let (:school) {FactoryGirl.create(:school, scheduling_communication: School::SCHEDULING_COMM_SCHOOL)} + describe "owner" do + + it "works when not a teacher" do + query = LessonSession.index(school.owner, {as_teacher: true})[:query] + query.length.should eql 0 + + teacher.teacher.school = school + teacher.teacher.save! + teacher.reload + school.reload + + school.teachers.should eql [teacher.teacher] + lesson = normal_lesson(user, teacher, {accept: false}) + lesson.status.should eql LessonSession::STATUS_REQUESTED + lesson.lesson_booking.school.should eql school + school.owner.reload + query = LessonSession.index(school.owner, {as_teacher: true})[:query] + query.length.should eql 1 + + query = LessonSession.index(teacher, {as_teacher: true})[:query] + query.length.should eql 0 + + + lesson = normal_lesson(user, teacher, {accept: true}) + lesson.status.should eql LessonSession::STATUS_APPROVED + lesson.lesson_booking.school.should eql school + query = LessonSession.index(school.owner, {as_teacher: true})[:query] + query.length.should eql 1 + + query = LessonSession.index(teacher, {as_teacher: true})[:query] + query.length.should eql 1 + end + end + end end end diff --git a/ruby/spec/mailers/teacher_lesson_email_spec.rb b/ruby/spec/mailers/teacher_lesson_email_spec.rb index 1a49bc635..d1ddaf0ac 100644 --- a/ruby/spec/mailers/teacher_lesson_email_spec.rb +++ b/ruby/spec/mailers/teacher_lesson_email_spec.rb @@ -30,7 +30,7 @@ describe "TeacherLessonEmails" do elsif @schoolDirectComm mail.to.should eql [teacher.email] else - mail.to.should eql [teacher.email, school.correspondence_email] + mail.to.should eql [school.communication_email, teacher.email] end end @@ -51,94 +51,97 @@ describe "TeacherLessonEmails" do } it "teacher_lesson_request" do - UserMailer.teacher_lesson_request(lesson.lesson_booking) + UserMailer.teacher_lesson_request(lesson.lesson_booking).deliver school_over_teacher end it "teacher_lesson_accepted" do - UserMailer.teacher_lesson_accepted(lesson, "come along now and teach", lesson.lesson_booking.lesson_booking_slots[0]) + UserMailer.teacher_lesson_accepted(lesson, "come along now and teach", lesson.lesson_booking.lesson_booking_slots[0]).deliver school_and_teacher end it "teacher_lesson_update_all" do - UserMailer.teacher_lesson_update_all(lesson, "come along now and teach", lesson.lesson_booking.lesson_booking_slots[0]) + UserMailer.teacher_lesson_update_all(lesson, "come along now and teach", lesson.lesson_booking.lesson_booking_slots[0]).deliver school_and_teacher end it "teacher_lesson_counter" do - UserMailer.teacher_lesson_counter(lesson, lesson.lesson_booking.lesson_booking_slots[0]) + UserMailer.teacher_lesson_counter(lesson, lesson.lesson_booking.lesson_booking_slots[0]).deliver school_over_teacher end it "teacher_lesson_normal_done" do - UserMailer.teacher_lesson_normal_done(lesson) + UserMailer.teacher_lesson_normal_done(lesson).deliver school_over_teacher end it "teacher_lesson_completed" do - UserMailer.teacher_lesson_completed(lesson) + UserMailer.teacher_lesson_completed(lesson).deliver school_and_teacher end it "teacher_test_drive_no_bill" do - UserMailer.teacher_test_drive_no_bill(lesson) + UserMailer.teacher_test_drive_no_bill(lesson).deliver school_and_teacher end it "teacher_lesson_normal_no_bill" do - UserMailer.teacher_lesson_normal_no_bill(lesson) + UserMailer.teacher_lesson_normal_no_bill(lesson).deliver school_and_teacher end it "teacher_unable_charge_monthly" do + pending "insufficient test setup" paid = monthly_lesson(user, teacher, {accept:true, finish: true}) paid.reload - UserMailer.teacher_unable_charge_monthly(paid.lesson_package_purchase) + UserMailer.teacher_unable_charge_monthly(paid.lesson_package_purchase).deliver school_over_teacher end it "teacher_lesson_monthly_charged" do + pending "insufficient test setup" paid = monthly_lesson(user, teacher, {accept:true, finish: true}) paid.reload - UserMailer.teacher_lesson_monthly_charged(paid.lesson_package_purchase) + UserMailer.teacher_lesson_monthly_charged(paid.lesson_package_purchase).deliver school_over_teacher end it "teacher_distribution_done" do teacher_payment = FactoryGirl.create(:teacher_payment, teacher: teacher, teacher_distribution: FactoryGirl.create(:teacher_distribution, lesson_session: lesson)) - UserMailer.teacher_distribution_done(teacher_payment) + UserMailer.teacher_distribution_done(teacher_payment).deliver school_over_teacher end it "teacher_distribution_fail" do teacher_payment = FactoryGirl.create(:teacher_payment, teacher: teacher, teacher_distribution: FactoryGirl.create(:teacher_distribution, lesson_session: lesson)) - UserMailer.teacher_distribution_fail(teacher_payment) + UserMailer.teacher_distribution_fail(teacher_payment).deliver school_over_teacher end it "teacher_lesson_booking_canceled" do canceled_lesson = normal_lesson(user, teacher, {cancel: true}) - UserMailer.teacher_lesson_booking_canceled(canceled_lesson.lesson_booking, "Sorry I can't teach anymore!") + UserMailer.teacher_lesson_booking_canceled(canceled_lesson.lesson_booking, "Sorry I can't teach anymore!").deliver school_and_teacher end it "teacher_lesson_canceled" do canceled_lesson = normal_lesson(user, teacher, {cancel: true}) - UserMailer.teacher_lesson_canceled(canceled_lesson, "Sorry I can't teach anymore!") + UserMailer.teacher_lesson_canceled(canceled_lesson, "Sorry I can't teach anymore!").deliver school_and_teacher end it "lesson_chat" do - + msg = ChatMessage.create(user, nil, "nathuntoehun ", "lesson", "abc", teacher, lesson) + UserMailer.lesson_chat(msg).deliver end it "teacher_counter_reminder" do - UserMailer.teacher_counter_reminder(lesson) + UserMailer.teacher_counter_reminder(lesson).deliver school_over_teacher end it "lesson_starting_soon_teacher" do - UserMailer.lesson_starting_soon_teacher(lesson) + UserMailer.lesson_starting_soon_teacher(lesson).deliver teacher_always end end @@ -150,8 +153,106 @@ describe "TeacherLessonEmails" do } let(:school) { FactoryGirl.create(:school, scheduling_communication: School::SCHEDULING_COMM_TEACHER) } let(:user) { FactoryGirl.create(:user) } - let(:teacher_obj) { FactoryGirl.create(:teacher_obj, school) } - let(:teacher) { FactoryGirl.create(:teacher_user, teacher: teacher_obj) } + let(:teacher_obj) { FactoryGirl.create(:teacher, school: school) } + let(:teacher) { FactoryGirl.create(:user, teacher: teacher_obj) } + let(:lesson) { normal_lesson(user, teacher) } + let(:mail) { UserMailer.deliveries[-1] } + + + it "teacher_lesson_request" do + UserMailer.teacher_lesson_request(lesson.lesson_booking).deliver + school_over_teacher + end + + it "teacher_lesson_accepted" do + UserMailer.teacher_lesson_accepted(lesson, "come along now and teach", lesson.lesson_booking.lesson_booking_slots[0]).deliver + school_and_teacher + end + + it "teacher_lesson_update_all" do + UserMailer.teacher_lesson_update_all(lesson, "come along now and teach", lesson.lesson_booking.lesson_booking_slots[0]).deliver + school_and_teacher + end + + it "teacher_lesson_counter" do + UserMailer.teacher_lesson_counter(lesson, lesson.lesson_booking.lesson_booking_slots[0]).deliver + school_over_teacher + end + + it "teacher_lesson_normal_done" do + UserMailer.teacher_lesson_normal_done(lesson).deliver + school_over_teacher + end + + it "teacher_lesson_completed" do + UserMailer.teacher_lesson_completed(lesson).deliver + school_and_teacher + end + + it "teacher_test_drive_no_bill" do + UserMailer.teacher_test_drive_no_bill(lesson).deliver + school_and_teacher + end + + it "teacher_lesson_normal_no_bill" do + UserMailer.teacher_lesson_normal_no_bill(lesson).deliver + school_and_teacher + end + + it "teacher_unable_charge_monthly" do + pending "insufficient test setup" + paid = monthly_lesson(user, teacher, {accept:true, finish: true}) + paid.reload + UserMailer.teacher_unable_charge_monthly(paid.lesson_package_purchase).deliver + school_over_teacher + end + + it "teacher_lesson_monthly_charged" do + pending "insufficient test setup" + paid = monthly_lesson(user, teacher, {accept:true, finish: true}) + paid.reload + UserMailer.teacher_lesson_monthly_charged(paid.lesson_package_purchase).deliver + school_over_teacher + end + + it "teacher_distribution_done" do + teacher_payment = FactoryGirl.create(:teacher_payment, teacher: teacher, teacher_distribution: FactoryGirl.create(:teacher_distribution, lesson_session: lesson)) + UserMailer.teacher_distribution_done(teacher_payment).deliver + school_over_teacher + end + + it "teacher_distribution_fail" do + teacher_payment = FactoryGirl.create(:teacher_payment, teacher: teacher, teacher_distribution: FactoryGirl.create(:teacher_distribution, lesson_session: lesson)) + UserMailer.teacher_distribution_fail(teacher_payment).deliver + school_over_teacher + end + + it "teacher_lesson_booking_canceled" do + canceled_lesson = normal_lesson(user, teacher, {cancel: true}) + UserMailer.teacher_lesson_booking_canceled(canceled_lesson.lesson_booking, "Sorry I can't teach anymore!").deliver + school_and_teacher + end + + it "teacher_lesson_canceled" do + canceled_lesson = normal_lesson(user, teacher, {cancel: true}) + UserMailer.teacher_lesson_canceled(canceled_lesson, "Sorry I can't teach anymore!").deliver + school_and_teacher + end + + it "lesson_chat" do + msg = ChatMessage.create(user, nil, "nathuntoehun ", "lesson", "abc", teacher, lesson) + UserMailer.lesson_chat(msg).deliver + end + + it "teacher_counter_reminder" do + UserMailer.teacher_counter_reminder(lesson).deliver + school_over_teacher + end + + it "lesson_starting_soon_teacher" do + UserMailer.lesson_starting_soon_teacher(lesson).deliver + teacher_always + end end @@ -162,7 +263,104 @@ describe "TeacherLessonEmails" do } let(:school) { FactoryGirl.create(:school, scheduling_communication: School::SCHEDULING_COMM_SCHOOL) } let(:user) { FactoryGirl.create(:user) } - let(:teacher_obj) { FactoryGirl.create(:teacher_obj, school) } - let(:teacher) { FactoryGirl.create(:teacher_user, teacher: teacher_obj) } + let(:teacher_obj) { FactoryGirl.create(:teacher, school: school) } + let(:teacher) { FactoryGirl.create(:user, teacher: teacher_obj) } + let(:lesson) { normal_lesson(user, teacher) } + let(:mail) { UserMailer.deliveries[-1] } + + it "teacher_lesson_request" do + UserMailer.teacher_lesson_request(lesson.lesson_booking).deliver + school_over_teacher + end + + it "teacher_lesson_accepted" do + UserMailer.teacher_lesson_accepted(lesson, "come along now and teach", lesson.lesson_booking.lesson_booking_slots[0]).deliver + school_and_teacher + end + + it "teacher_lesson_update_all" do + UserMailer.teacher_lesson_update_all(lesson, "come along now and teach", lesson.lesson_booking.lesson_booking_slots[0]).deliver + school_and_teacher + end + + it "teacher_lesson_counter" do + UserMailer.teacher_lesson_counter(lesson, lesson.lesson_booking.lesson_booking_slots[0]).deliver + school_over_teacher + end + + it "teacher_lesson_normal_done" do + UserMailer.teacher_lesson_normal_done(lesson).deliver + school_over_teacher + end + + it "teacher_lesson_completed" do + UserMailer.teacher_lesson_completed(lesson).deliver + school_and_teacher + end + + it "teacher_test_drive_no_bill" do + UserMailer.teacher_test_drive_no_bill(lesson).deliver + school_and_teacher + end + + it "teacher_lesson_normal_no_bill" do + UserMailer.teacher_lesson_normal_no_bill(lesson).deliver + school_and_teacher + end + + it "teacher_unable_charge_monthly" do + pending "insufficient test setup" + paid = monthly_lesson(user, teacher, {accept:true, finish: true}) + paid.reload + UserMailer.teacher_unable_charge_monthly(paid.lesson_package_purchase).deliver + school_over_teacher + end + + it "teacher_lesson_monthly_charged" do + pending "insufficient test setup" + paid = monthly_lesson(user, teacher, {accept:true, finish: true}) + paid.reload + UserMailer.teacher_lesson_monthly_charged(paid.lesson_package_purchase).deliver + school_over_teacher + end + + it "teacher_distribution_done" do + teacher_payment = FactoryGirl.create(:teacher_payment, teacher: teacher, teacher_distribution: FactoryGirl.create(:teacher_distribution, lesson_session: lesson)) + UserMailer.teacher_distribution_done(teacher_payment).deliver + school_over_teacher + end + + it "teacher_distribution_fail" do + teacher_payment = FactoryGirl.create(:teacher_payment, teacher: teacher, teacher_distribution: FactoryGirl.create(:teacher_distribution, lesson_session: lesson)) + UserMailer.teacher_distribution_fail(teacher_payment).deliver + school_over_teacher + end + + it "teacher_lesson_booking_canceled" do + canceled_lesson = normal_lesson(user, teacher, {cancel: true}) + UserMailer.teacher_lesson_booking_canceled(canceled_lesson.lesson_booking, "Sorry I can't teach anymore!").deliver + school_and_teacher + end + + it "teacher_lesson_canceled" do + canceled_lesson = normal_lesson(user, teacher, {cancel: true}) + UserMailer.teacher_lesson_canceled(canceled_lesson, "Sorry I can't teach anymore!").deliver + school_and_teacher + end + + it "lesson_chat" do + msg = ChatMessage.create(user, nil, "nathuntoehun ", "lesson", "abc", teacher, lesson) + UserMailer.lesson_chat(msg).deliver + end + + it "teacher_counter_reminder" do + UserMailer.teacher_counter_reminder(lesson).deliver + school_over_teacher + end + + it "lesson_starting_soon_teacher" do + UserMailer.lesson_starting_soon_teacher(lesson).deliver + teacher_always + end end end diff --git a/ruby/spec/support/lesson_session.rb b/ruby/spec/support/lesson_session.rb index dfa113e02..855f13a46 100644 --- a/ruby/spec/support/lesson_session.rb +++ b/ruby/spec/support/lesson_session.rb @@ -64,8 +64,12 @@ def book_lesson(user, teacher, options) if user.most_recent_test_drive_purchase.nil? LessonPackagePurchase.create(user, booking, LessonPackageType.package_for_test_drive_count(options[:package_count])) end + elsif options[:monthly] + puts "did it" + LessonPackagePurchase.create(user, booking, LessonPackageType.single, Date.today.year, Date.today.month) end + if options[:counter] if options[:monthly] counter_slot = FactoryGirl.build(:lesson_booking_slot_recurring) diff --git a/web/app/assets/images/landing/ad-session-window.png b/web/app/assets/images/landing/ad-session-window.png new file mode 100644 index 000000000..a5bbd38c0 Binary files /dev/null and b/web/app/assets/images/landing/ad-session-window.png differ diff --git a/web/app/assets/images/landing/ad-video-window.png b/web/app/assets/images/landing/ad-video-window.png new file mode 100644 index 000000000..336772c07 Binary files /dev/null and b/web/app/assets/images/landing/ad-video-window.png differ diff --git a/web/app/assets/javascripts/react-components/landing/JamClassStudentLandingPage.js.jsx.coffee b/web/app/assets/javascripts/react-components/landing/JamClassStudentLandingPage.js.jsx.coffee index addb00d93..f854d5e2a 100644 --- a/web/app/assets/javascripts/react-components/landing/JamClassStudentLandingPage.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/landing/JamClassStudentLandingPage.js.jsx.coffee @@ -54,8 +54,8 @@ rest = context.JK.Rest()
+