From 1528de57a4b878faaedecf751b9d682de8af3aa0 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 24 May 2016 10:45:15 -0500 Subject: [PATCH] clean up no bill email --- ruby/lib/jam_ruby/app/mailers/user_mailer.rb | 4 ++-- .../student_test_drive_no_bill.html.erb | 2 +- .../teacher_test_drive_no_bill.html.erb | 2 +- ruby/lib/jam_ruby/models/lesson_session.rb | 18 ++++++++++++++++-- ruby/spec/mailers/render_emails_spec.rb | 15 +++++++++++++++ ruby/spec/support/lesson_session.rb | 2 -- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/ruby/lib/jam_ruby/app/mailers/user_mailer.rb b/ruby/lib/jam_ruby/app/mailers/user_mailer.rb index c87ea7e3a..5b334c4ed 100644 --- a/ruby/lib/jam_ruby/app/mailers/user_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/user_mailer.rb @@ -952,7 +952,7 @@ module JamRuby @session_url = lesson_session.web_url @lesson_session = lesson_session - email = @student.email + email = @teacher.email subject = "Your TestDrive with #{@teacher.name} was not successful" unique_args = {:type => "teacher_test_drive_no_bill"} @@ -960,7 +960,7 @@ module JamRuby sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) - sendgrid_substitute('@USERID', [@student.id]) + sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => subject) do |format| format.text diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_test_drive_no_bill.html.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_test_drive_no_bill.html.erb index deee9c563..a10a0bc5d 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_test_drive_no_bill.html.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/student_test_drive_no_bill.html.erb @@ -6,7 +6,7 @@ Hello <%= @student.name %>,

-

You have not used a credit for today's TestDrive with <%= @teacher.name %>. +

You have not used a credit for today's TestDrive with <%= @teacher.name %> because <%= @lesson_session.error_display %>.

Click the button below to see more information about this session. diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_test_drive_no_bill.html.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_test_drive_no_bill.html.erb index 4045e0bbf..63b6ad7cb 100644 --- a/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_test_drive_no_bill.html.erb +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/user_mailer/teacher_test_drive_no_bill.html.erb @@ -6,7 +6,7 @@ Hello <%= @teacher.name %>,

-

Your TestDrive with <%= @student.name %> was not successful because <@= lesson_session.error_display %>. +

Your TestDrive with <%= @student.name %> was not successful because <%= @lesson_session.error_display %>.

Click the button below to see more information about this session. diff --git a/ruby/lib/jam_ruby/models/lesson_session.rb b/ruby/lib/jam_ruby/models/lesson_session.rb index bc0e74a47..a0fd51a06 100644 --- a/ruby/lib/jam_ruby/models/lesson_session.rb +++ b/ruby/lib/jam_ruby/models/lesson_session.rb @@ -266,9 +266,23 @@ module JamRuby def error_display if analysed - "" + if !success + analysis_json = JSON.parse(self.analysis) + if analysis_json["teacher_analysis"]["missed"] && analysis_json["student_analysis"]["missed"] + "both the student and teacher missed the lesson" + elsif analysis_json["teacher_analysis"]["missed"] + "the teacher missed the lesson" + elsif analysis_json["student_analysis"]["missed"] + "the student missed the lesson" + else + "unknown error reason" + end + + else + "because no error" + end else - "unknown reason" + "not yet analysed" end end diff --git a/ruby/spec/mailers/render_emails_spec.rb b/ruby/spec/mailers/render_emails_spec.rb index 7ef34fe58..5405ae4af 100644 --- a/ruby/spec/mailers/render_emails_spec.rb +++ b/ruby/spec/mailers/render_emails_spec.rb @@ -98,6 +98,21 @@ describe "RenderMailers", :slow => true do UserMailer.student_scheduled_jamclass_invitation(lesson_session.student, "custom message", lesson_session.music_session).deliver end + it "student_test_drive_no_bill" do + @filename = "student_test_drive_no_bill" + lesson = testdrive_lesson(user, teacher, {accept: true, miss: true}) + + UserMailer.deliveries.clear + UserMailer.student_test_drive_no_bill(lesson).deliver + end + + it "teacher_test_drive_no_bill" do + @filename = "teacher_test_drive_no_bill" + lesson = testdrive_lesson(user, teacher, {accept: true, miss: true}) + + UserMailer.deliveries.clear + UserMailer.teacher_test_drive_no_bill(lesson).deliver + end it "student_test_drive_lesson_completed" do @filename = "student_test_drive_lesson_completed" lesson = testdrive_lesson(user, teacher) diff --git a/ruby/spec/support/lesson_session.rb b/ruby/spec/support/lesson_session.rb index b263ed73b..420847a76 100644 --- a/ruby/spec/support/lesson_session.rb +++ b/ruby/spec/support/lesson_session.rb @@ -74,8 +74,6 @@ def book_lesson(user, teacher, options) end if options[:miss] - # teacher & student get into session - Timecop.travel(end_time + 1)