From e8843bfd6469c6799c97a71ee90dddf7abc3a3ee Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 31 May 2016 08:35:04 -0500 Subject: [PATCH] ready for release JamClass --- ruby/lib/jam_ruby/models/lesson_session.rb | 7 ++-- .../flows/monthly_recurring_lesson_spec.rb | 12 +++--- .../spec/jam_ruby/flows/normal_lesson_spec.rb | 8 ++-- .../jam_ruby/flows/recurring_lesson_spec.rb | 8 +++- .../jam_ruby/flows/testdrive_lesson_spec.rb | 4 +- .../jam_ruby/models/lesson_session_spec.rb | 8 ++++ ruby/spec/support/lesson_session.rb | 1 - web/app/assets/javascripts/ga.js | 13 ++++++- .../LessonBooking.js.jsx.coffee | 13 ++++--- .../LessonPayment.js.jsx.coffee | 6 +++ .../mixins/PostProcessorMixin.js.coffee | 2 +- web/app/assets/javascripts/web/welcome.js | 3 +- web/app/controllers/users_controller.rb | 3 +- .../clients/_lessonSessionActions.html.slim | 37 +++++++++---------- web/spec/features/book_test_drive_spec.rb | 2 +- 15 files changed, 80 insertions(+), 47 deletions(-) diff --git a/ruby/lib/jam_ruby/models/lesson_session.rb b/ruby/lib/jam_ruby/models/lesson_session.rb index a1c946359..00d3879d8 100644 --- a/ruby/lib/jam_ruby/models/lesson_session.rb +++ b/ruby/lib/jam_ruby/models/lesson_session.rb @@ -796,11 +796,12 @@ module JamRuby self.countered_slot = slot self.countered_lesson = self self.status = STATUS_COUNTERED - if !update_all + #if !update_all self.counter_slot = slot - end + #end if self.save - if update_all && !lesson_booking.counter(self, proposer, slot) + #if update_all && !lesson_booking.counter(self, proposer, slot) + if !lesson_booking.counter(self, proposer, slot) response = lesson_booking raise ActiveRecord::Rollback end diff --git a/ruby/spec/jam_ruby/flows/monthly_recurring_lesson_spec.rb b/ruby/spec/jam_ruby/flows/monthly_recurring_lesson_spec.rb index ee2aea0bf..ea39a1573 100644 --- a/ruby/spec/jam_ruby/flows/monthly_recurring_lesson_spec.rb +++ b/ruby/spec/jam_ruby/flows/monthly_recurring_lesson_spec.rb @@ -42,7 +42,6 @@ describe "Monthly Recurring Lesson Flow" do ########## Need validate their credit card token = create_stripe_token result = user.payment_update({token: token, zip: '78759', normal: true, booking_id: booking.id}) - puts "result #{result.inspect}" booking.reload booking.card_presumed_ok.should be_true booking.errors.any?.should be_false @@ -118,7 +117,7 @@ describe "Monthly Recurring Lesson Flow" do ######## Teacher accepts slot UserMailer.deliveries.clear - lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false}) + lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false, accepter: teacher_user}) UserMailer.deliveries.each do |del| # puts del.inspect end @@ -203,7 +202,7 @@ describe "Monthly Recurring Lesson Flow" do payment = TeacherPayment.first payment.amount_in_cents.should eql 3000 payment.fee_in_cents.should eql (3000 * 0.28).round - payment.teacher_payment_charge.amount_in_cents.should eql 3000 + payment.teacher_payment_charge.amount_in_cents.should eql (3000 + 3000 * APP_CONFIG.stripe[:ach_pct]).round payment.teacher_payment_charge.fee_in_cents.should eql (3000 * 0.28).round payment.teacher.should eql teacher_user payment.teacher_distribution.should eql teacher_distribution @@ -320,7 +319,7 @@ describe "Monthly Recurring Lesson Flow" do ######## Teacher accepts slot UserMailer.deliveries.clear - lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false}) + lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false, accepter: teacher_user}) UserMailer.deliveries.each do |del| # puts del.inspect end @@ -419,6 +418,7 @@ describe "Monthly Recurring Lesson Flow" do it "affiliate gets their cut" do + Timecop.travel(2016, 05, 15) user.affiliate_referral = affiliate_partner user.save! teacher_user.affiliate_referral = affiliate_partner2 @@ -429,7 +429,6 @@ describe "Monthly Recurring Lesson Flow" do user.reload - puts "user.lesson_purchases #{user.lesson_purchases}" user.lesson_purchases.count.should eql 1 lesson_package_purchase = user.lesson_purchases.first teacher_distribution = lesson_package_purchase.teacher_distribution @@ -447,6 +446,7 @@ describe "Monthly Recurring Lesson Flow" do end it "school affiliate gets nothing when teacher school is involved" do + Timecop.travel(2016, 05, 15) teacher.school = school teacher.save! @@ -469,6 +469,8 @@ describe "Monthly Recurring Lesson Flow" do end it "student school affiliates gets cut when student school is involved. so does teacher's" do + # in the middle of the month so that we don't get the next month's in-advance purchase put on us + Timecop.travel(2016, 05, 15) user.affiliate_referral = school.affiliate_partner user.save! diff --git a/ruby/spec/jam_ruby/flows/normal_lesson_spec.rb b/ruby/spec/jam_ruby/flows/normal_lesson_spec.rb index b9a558afd..e0fbde071 100644 --- a/ruby/spec/jam_ruby/flows/normal_lesson_spec.rb +++ b/ruby/spec/jam_ruby/flows/normal_lesson_spec.rb @@ -68,7 +68,7 @@ describe "Normal Lesson Flow" do ######## Teacher accepts slot UserMailer.deliveries.clear - lesson_session.accept({message: 'Yeah I got this', slot: booking.default_slot.id, update_all: false}) + lesson_session.accept({message: 'Yeah I got this', slot: booking.default_slot.id, update_all: false, accepter: teacher_user}) lesson_session.errors.any?.should be_false lesson_session.reload lesson_session.slot.should eql booking.default_slot @@ -251,7 +251,7 @@ describe "Normal Lesson Flow" do payment = TeacherPayment.first payment.amount_in_cents.should eql 3000 payment.fee_in_cents.should eql (3000 * 0.28).round - payment.teacher_payment_charge.amount_in_cents.should eql 3000 + payment.teacher_payment_charge.amount_in_cents.should eql (3000 + 3000 * APP_CONFIG.stripe[:ach_pct]).round payment.teacher_payment_charge.fee_in_cents.should eql (3000 * 0.28).round payment.teacher.should eql teacher_user payment.teacher_distribution.should eql teacher_distribution @@ -352,7 +352,7 @@ describe "Normal Lesson Flow" do ######## Teacher accepts slot UserMailer.deliveries.clear - lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false}) + lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false,accepter: teacher_user}) lesson_session.errors.any?.should be_false lesson_session.reload lesson_session.slot.should eql student_counter @@ -508,7 +508,7 @@ describe "Normal Lesson Flow" do ######## Teacher accepts slot UserMailer.deliveries.clear - lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false}) + lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false, accepter: teacher_user}) lesson_session.errors.any?.should be_false lesson_session.reload lesson_session.slot.should eql student_counter diff --git a/ruby/spec/jam_ruby/flows/recurring_lesson_spec.rb b/ruby/spec/jam_ruby/flows/recurring_lesson_spec.rb index 00924d4e6..fed085dc9 100644 --- a/ruby/spec/jam_ruby/flows/recurring_lesson_spec.rb +++ b/ruby/spec/jam_ruby/flows/recurring_lesson_spec.rb @@ -105,7 +105,7 @@ describe "Recurring Lesson Flow" do ######## Teacher accepts slot UserMailer.deliveries.clear - lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false}) + lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false, accepter: teacher_user}) UserMailer.deliveries.each do |del| # puts del.inspect end @@ -132,7 +132,8 @@ describe "Recurring Lesson Flow" do notification.student_directed.should eql true notification.purpose.should eql 'accept' notification.description.should eql NotificationTypes::LESSON_MESSAGE - + user.reload + user.sales.length.should eql 0 # teacher & student get into session start = lesson_session.scheduled_start @@ -181,6 +182,9 @@ describe "Recurring Lesson Flow" do lesson_session.sent_billing_notices.should be true user.reload user.remaining_test_drives.should eql 0 + UserMailer.deliveries.each do |d| + puts d.subject + end UserMailer.deliveries.length.should eql 2 # one for student, one for teacher end end diff --git a/ruby/spec/jam_ruby/flows/testdrive_lesson_spec.rb b/ruby/spec/jam_ruby/flows/testdrive_lesson_spec.rb index 5db43fb37..5d258f958 100644 --- a/ruby/spec/jam_ruby/flows/testdrive_lesson_spec.rb +++ b/ruby/spec/jam_ruby/flows/testdrive_lesson_spec.rb @@ -140,7 +140,7 @@ describe "TestDrive Lesson Flow" do ######## Teacher accepts slot UserMailer.deliveries.clear - lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false}) + lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false, accepter: teacher_user}) lesson_session.errors.any?.should be_false lesson_session.reload lesson_session.slot.should eql student_counter @@ -237,7 +237,7 @@ describe "TestDrive Lesson Flow" do teacher_distribution.ready.should be_true teacher_distribution.distributed.should be_true - teacher_payment.teacher_payment_charge.amount_in_cents.should eql 1000 + teacher_payment.teacher_payment_charge.amount_in_cents.should eql (1000 + 1000 * APP_CONFIG.stripe[:ach_pct]).round teacher_payment.teacher_payment_charge.fee_in_cents.should eql 0 user.sales.count.should eql 1 diff --git a/ruby/spec/jam_ruby/models/lesson_session_spec.rb b/ruby/spec/jam_ruby/models/lesson_session_spec.rb index 3988a2176..633152ca1 100644 --- a/ruby/spec/jam_ruby/models/lesson_session_spec.rb +++ b/ruby/spec/jam_ruby/models/lesson_session_spec.rb @@ -10,6 +10,14 @@ describe LessonSession do let(:lesson_booking) {b = LessonBooking.book_normal(user, teacher, [slot1, slot2], "Hey I've heard of you before.", false, LessonBooking::PAYMENT_STYLE_SINGLE, 60); b.card_presumed_ok = true; b.save!; b} let(:lesson_session) {lesson_booking.lesson_sessions[0]} + describe "counter" do + describe "recurring" do + it "" do + + end + end + end + describe "autocancel" do it "can't autocancel in the past" do lesson_session.status.should eql LessonSession::STATUS_REQUESTED diff --git a/ruby/spec/support/lesson_session.rb b/ruby/spec/support/lesson_session.rb index 4943a9ca9..1a731423e 100644 --- a/ruby/spec/support/lesson_session.rb +++ b/ruby/spec/support/lesson_session.rb @@ -65,7 +65,6 @@ def book_lesson(user, teacher, options) 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 diff --git a/web/app/assets/javascripts/ga.js b/web/app/assets/javascripts/ga.js index 0c47505ff..d68ece250 100644 --- a/web/app/assets/javascripts/ga.js +++ b/web/app/assets/javascripts/ga.js @@ -99,6 +99,10 @@ ioTargetFail : 'ioTargetFail' } + var jamClassReasons = { + testDrive: 'TestDrive' + } + var networkTestFailReasons = { stun : 'STUN', bandwidth : 'Bandwidth', @@ -129,7 +133,8 @@ jkFollow : 'jkFollow', jkFavorite : 'jkFavorite', jkComment : 'jkComment', - fileDownload: "DownloadFile" + fileDownload: "DownloadFile", + jamclass: 'JamClass' }; // JamTrack categories and actions: @@ -204,6 +209,11 @@ context.ga('send', 'event', categories.register, action, registrationType); } + function trackTestDrivePurchase(count) { + + context.ga('send', 'event', categories.jamclass, jamClassReasons.testDrive, count); + + } function trackDownload(platform) { var normalizedPlatform = translatePlatformForGA(platform); @@ -490,6 +500,7 @@ GA.virtualPageView = virtualPageView; GA.trackTiming = trackTiming; GA.trackFileDownload = trackFileDownload; + GA.trackTestDrivePurchase = trackTestDrivePurchase; context.JK.GA = GA; diff --git a/web/app/assets/javascripts/react-components/LessonBooking.js.jsx.coffee b/web/app/assets/javascripts/react-components/LessonBooking.js.jsx.coffee index 26fc25f19..023b9a66b 100644 --- a/web/app/assets/javascripts/react-components/LessonBooking.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/LessonBooking.js.jsx.coffee @@ -172,10 +172,10 @@ UserStore = context.UserStore if booking.counter_slot? startSlotDecision = booking.counter_slot.id else - if booking.accepter_id? - startSlotDecision = 'counter' - else - startSlotDecision = booking.default_slot.id + if booking.accepter_id? + startSlotDecision = 'counter' + else + startSlotDecision = booking.default_slot.id update_all = !booking.focused_lesson?.id? @@ -189,10 +189,11 @@ UserStore = context.UserStore @processBooking(booking) - #if booking.onlyOptions + if booking.onlyOption # you see two options (accept, and propose new) if it's a counter and you are not the last to act # the only choice possible in most cases is to propose a new time - # nextState.slot_decision = 'counter' + #nextState.slot_decision = 'counter' + startSlotDecision = 'counter' @setState({booking: booking, updating: false, slot_decision: startSlotDecision, updatingLesson: false, update_all: update_all}) getLessonBookingDone: (response) -> diff --git a/web/app/assets/javascripts/react-components/LessonPayment.js.jsx.coffee b/web/app/assets/javascripts/react-components/LessonPayment.js.jsx.coffee index c0ce9c79a..e299a0780 100644 --- a/web/app/assets/javascripts/react-components/LessonPayment.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/LessonPayment.js.jsx.coffee @@ -294,6 +294,12 @@ UserStore = context.UserStore logger.debug("testDriveCount: " + testDriveCount) + testDriveCountInt = parseInt(testDriveCount); + if context._.isNaN(testDriveCountInt) + testDriveCountInt = 3 + + context.JK.GA.trackTestDrivePurchase(testDriveCountInt); + if response.test_drive?.teacher_id teacher_id = response.test_drive.teacher_id if testDriveCount == '1' diff --git a/web/app/assets/javascripts/react-components/mixins/PostProcessorMixin.js.coffee b/web/app/assets/javascripts/react-components/mixins/PostProcessorMixin.js.coffee index fdf561dd7..811f956ba 100644 --- a/web/app/assets/javascripts/react-components/mixins/PostProcessorMixin.js.coffee +++ b/web/app/assets/javascripts/react-components/mixins/PostProcessorMixin.js.coffee @@ -23,7 +23,7 @@ teacherActions = window.JK.Actions.Teacher lesson.isAdmin = context.JK.currentUserAdmin lesson.schoolOnSchool = lesson['school_on_school?'] lesson.cardNotOk = !lesson.schoolOnSchool && !lesson.lesson_booking.card_presumed_ok - + lesson.isActive = lesson['is_active?'] if (lesson.status == 'requested' || lesson.status == 'countered') lesson.isRequested = true if lesson.cardNotOk diff --git a/web/app/assets/javascripts/web/welcome.js b/web/app/assets/javascripts/web/welcome.js index dd570b763..61cc44f1a 100644 --- a/web/app/assets/javascripts/web/welcome.js +++ b/web/app/assets/javascripts/web/welcome.js @@ -76,7 +76,8 @@ $('.like-link').click(function() { var like_site = $(this).data('site'); - JK.GA.trackJKSocial(JK.GA.Categories.jkLike, like_site, JK.clientType()); + // removed because we are juggling 20 events max in GA + //JK.GA.trackJKSocial(JK.GA.Categories.jkLike, like_site, JK.clientType()); window.open("/endorse/0/"+like_site, '_blank'); }); } diff --git a/web/app/controllers/users_controller.rb b/web/app/controllers/users_controller.rb index 8d19082cd..62dca654c 100644 --- a/web/app/controllers/users_controller.rb +++ b/web/app/controllers/users_controller.rb @@ -380,7 +380,8 @@ class UsersController < ApplicationController js =< $(function() { - JK.GA.trackJKSocial(JK.GA.Categories.jkLike, '#{service}', 'email'); + // // removed because we are juggling 20 events max in GA + // JK.GA.trackJKSocial(JK.GA.Categories.jkLike, '#{service}', 'email'); window.location = "#{url}"; }); diff --git a/web/app/views/clients/_lessonSessionActions.html.slim b/web/app/views/clients/_lessonSessionActions.html.slim index 9e0a4fc18..266fcbb8d 100644 --- a/web/app/views/clients/_lessonSessionActions.html.slim +++ b/web/app/views/clients/_lessonSessionActions.html.slim @@ -14,25 +14,7 @@ script type='text/template' id='template-lesson-session-actions' li data-lesson-option="attach-audio" a href='#' Attach Audio File - = '{% } else if (data.isRequested) { %}' - ul - li data-lesson-option="status" - a href='#' View Status - - li data-lesson-option="messages" - a href='#' View Messages - - li data-lesson-option="messages" - a href='#' Attach Message - - li data-lesson-option="cancel" - = '{% if (data.isStudent) { %}' - a href='#' Cancel Request - = '{% } else { %}' - a href='#' Decline Request - = '{% } %}' - - = '{% } else if (data.isScheduled) { %}' + = '{% } else if (data.isActive) { %}' ul li data-lesson-option="status" a href='#' View Status @@ -67,6 +49,23 @@ script type='text/template' id='template-lesson-session-actions' li data-lesson-option="start-65-ago" a href='#' Set Start 65 Min Ago = '{% } %}' + = '{% } else if (data.isRequested) { %}' + ul + li data-lesson-option="status" + a href='#' View Status + + li data-lesson-option="messages" + a href='#' View Messages + + li data-lesson-option="messages" + a href='#' Attach Message + + li data-lesson-option="cancel" + = '{% if (data.isStudent) { %}' + a href='#' Cancel Request + = '{% } else { %}' + a href='#' Decline Request + = '{% } %}' = '{% } else { %}' ul diff --git a/web/spec/features/book_test_drive_spec.rb b/web/spec/features/book_test_drive_spec.rb index 631c0bd78..ba0cfa242 100644 --- a/web/spec/features/book_test_drive_spec.rb +++ b/web/spec/features/book_test_drive_spec.rb @@ -49,7 +49,7 @@ describe "Test Drive", :js => true, :type => :feature, :capybara_feature => true # we tell user they have test drive purchased, and take them to the teacher screen find('#banner h1', text: 'Test Drive Purchased') - find('#banner .dialog-inner', text: "You have purchased #{4} TestDrive credits and have used 1 credit it to request a JamClass with #{teacher_user.name}") + find('#banner .dialog-inner', text: "You have purchased #{4} TestDrive credits and have used 1 credit to request a JamClass with #{teacher_user.name}") # dismiss banner find('a.button-orange', text:'CLOSE').trigger(:click)