jam-cloud/web/lib/tasks/lesson.rake

119 lines
3.7 KiB
Ruby

require 'factory_girl'
require 'timecop'
require 'rspec-rails'
begin
require Rails.root.join('spec', 'support', 'lessons.rb')
rescue LoadError
puts "for production; we ignore LoadError"
rescue TypeError
puts "for production, we ignore type error"
end
namespace :lessons do
task book_completed: :environment do |task, args|
user = User.find_by_email(ENV['STUDENT'])
teacher = User.find_by_email(ENV['TEACHER'])
recurring = ENV['RECURRING'] == '1'
slots = []
Timecop.travel(Date.today - 5)
slots << FactoryGirl.build(:lesson_booking_slot_single, preferred_day: Date.today - 3, timezone: 'America/Chicago')
slots << FactoryGirl.build(:lesson_booking_slot_single, preferred_day: Date.today - 4, timezone: 'America/Chicago')
if recurring
payment_style = LessonBooking::PAYMENT_STYLE_MONTHLY
else
payment_style = LessonBooking::PAYMENT_STYLE_SINGLE
end
lesson = normal_lesson(user, teacher, {accept: true, finish: true, student_show:true, no_validate: true})
if lesson.errors.any?
puts lesson.errors.inspect
raise "lesson failed"
end
puts "http://localhost:3000/client#/jamclass/lesson-booking/#{lesson.id}"
end
task book_normal: :environment do |task, args|
user = User.find_by_email(ENV['STUDENT'])
teacher = User.find_by_email(ENV['TEACHER'])
recurring = ENV['RECURRING'] == '1'
slots = []
if recurring
slots << FactoryGirl.build(:lesson_booking_slot_recurring, timezone: 'America/Chicago')
slots << FactoryGirl.build(:lesson_booking_slot_recurring, timezone: 'America/Chicago')
else
slots << FactoryGirl.build(:lesson_booking_slot_single, timezone: 'America/Chicago')
slots << FactoryGirl.build(:lesson_booking_slot_single, timezone: 'America/Chicago')
end
if user.stored_credit_card == false
user.stored_credit_card = true
user.save!
end
if recurring
payment_style = LessonBooking::PAYMENT_STYLE_MONTHLY
else
payment_style = LessonBooking::PAYMENT_STYLE_SINGLE
end
booking = LessonBooking.book_normal(user, teacher, slots, "Hey I've heard of you before.", recurring, payment_style, 60)
if booking.errors.any?
puts booking.errors.inspect
raise "booking failed"
end
lesson = booking.lesson_sessions[0]
#lesson.accept({message: 'Yeah I got this', slot: slots[0]})
#lesson.errors.any?.should be_false
#lesson.reload
#lesson.slot.should eql slots[0]
#lesson.status.should eql LessonSession::STATUS_APPROVED
puts "http://localhost:3000/client#/jamclass/lesson-booking/#{booking.id}"
end
task book_test_drive: :environment do |task, args|
user = User.find_by_email(ENV['STUDENT'])
teacher = User.find_by_email(ENV['TEACHER'])
slots = []
slots << FactoryGirl.build(:lesson_booking_slot_single, timezone: 'America/Chicago')
slots << FactoryGirl.build(:lesson_booking_slot_single, timezone: 'America/Chicago')
if user.stored_credit_card == false
user.stored_credit_card = true
user.save!
end
booking = LessonBooking.book_test_drive(user, teacher, slots, "Hey I've heard of you before.")
if booking.errors.any?
puts booking.errors.inspect
raise "booking failed"
end
lesson = booking.lesson_sessions[0]
if user.most_recent_test_drive_purchase.nil?
LessonPackagePurchase.create(user, lesson.lesson_booking, LessonPackageType.test_drive_4)
end
#lesson.accept({message: 'Yeah I got this', slot: slots[0]})
#lesson.errors.any?.should be_false
#lesson.reload
#lesson.slot.should eql slots[0]
#lesson.status.should eql LessonSession::STATUS_APPROVED
puts "http://localhost:3000/client#/jamclass/lesson-booking/#{lesson.lesson_booking.id}"
end
end