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

86 lines
2.6 KiB
Ruby

require 'factory_girl'
namespace :lessons do
task book_normal: :environment do |task, args|
user = User.find_by_email(ENV['STUDENT_EMAIL'])
teacher = User.find_by_email(ENV['TEACHER_EMAIL'])
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_EMAIL'])
teacher = User.find_by_email(ENV['TEACHER_EMAIL'])
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, booking, LessonPackageType.test_drive)
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/#{booking.id}"
end
end