Last active
May 10, 2016 14:34
-
-
Save carloscortegagna/b760812d12c9b341d2276c82d839c8c0 to your computer and use it in GitHub Desktop.
Test chiusura lezione
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context 'real use cases, lasted less than min duration' do | |
it 'elapsed seconds = 0, lesson duration = 30min, residual seconds = 45min, pay MIN' do | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 45*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_falsey | |
expect(lesson_service.lasted_less_than_min_duration?).to be_truthy | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.max_duration).to eql lesson.duration | |
expect(lesson_service.close_and_pay!('min')).to be_truthy | |
expect(lesson_service.to_pay_seconds).to eq 15*60 | |
expect(lesson.status).to eq 'completed' | |
expect(lesson.duration).to eq 15*60 | |
end | |
it 'elapsed seconds = 0, lesson duration = 30min, residual seconds = 45min, pay MAX' do | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 45*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_falsey | |
expect(lesson_service.lasted_less_than_min_duration?).to be_truthy | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.max_duration).to eql lesson.duration | |
expect(lesson_service.close_and_pay!('max')).to be_truthy | |
expect(lesson_service.to_pay_seconds).to eq 30*60 | |
expect(lesson.status).to eq 'completed' | |
expect(lesson.duration).to eq 30*60 | |
end | |
it 'elapsed seconds = 0, lesson duration = 30min, residual seconds = 45min, pay REAL' do | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 45*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_falsey | |
expect(lesson_service.lasted_less_than_min_duration?).to be_truthy | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.max_duration).to eql lesson.duration | |
expect(lesson_service.close_and_pay!('real')).to be_falsey | |
expect(lesson_service.to_pay_seconds).to be_nil | |
expect(lesson.status).to eq 'scheduled' | |
expect(lesson.duration).to eq 30*60 | |
expect(VirtualRoomLessonService.new(lesson).elapsed_seconds).to eq 0 | |
end | |
it 'elapsed seconds = 5min, lesson duration = 30min, residual seconds = 45min, pay MIN' do | |
create_connection_for_minutes(lesson, Time.now, 5) | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 45*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_truthy | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.max_duration).to eql lesson.duration | |
expect(lesson_service.close_and_pay!('min')).to be_truthy | |
expect(lesson_service.to_pay_seconds).to eq 15*60 | |
expect(lesson.status).to eq 'completed' | |
expect(lesson.duration).to eq 15*60 | |
end | |
it 'elapsed seconds = 5min, lesson duration = 30min, residual seconds = 40min, pay MAX' do | |
create_connection_for_minutes(lesson, Time.now, 5) | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 40*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_truthy | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.max_duration).to eql 30*60 | |
expect(lesson_service.close_and_pay!('max')).to be_truthy | |
expect(lesson_service.to_pay_seconds).to eq 30*60 | |
expect(lesson.status).to eq 'completed' | |
expect(lesson.duration).to eq 30*60 | |
end | |
it 'elapsed seconds = 5min, lesson duration = 30min, residual seconds = 20min, pay MAX' do | |
create_connection_for_minutes(lesson, Time.now, 5) | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 20*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_truthy | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.max_duration).to eql 20*60 | |
expect(lesson_service.close_and_pay!('max')).to be_truthy | |
expect(lesson_service.to_pay_seconds).to eq 20*60 | |
expect(lesson.status).to eq 'completed' | |
expect(lesson.duration).to eq 20*60 | |
end | |
end | |
context 'real use cases, lasted less than duration' do | |
it 'elapsed seconds = 16min, lesson duration = 30min, residual seconds = 40min, pay MIN' do | |
create_connection_for_minutes(lesson, Time.now, 16) | |
lesson.duration = 30*60 | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 40*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_falsey | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.show_max_duration?).to be_truthy | |
expect(lesson_service.max_duration).to eql lesson.duration | |
expect(lesson_service.close_and_pay!('min')).to be_falsey | |
expect(lesson_service.to_pay_seconds).to be_nil | |
expect(lesson.status).to eq 'underway' | |
expect(lesson.duration).to eq 30*60 | |
expect(VirtualRoomLessonService.new(lesson).elapsed_seconds).to eq 16*60 | |
end | |
it 'elapsed seconds = 16min, lesson duration = 30min, residual seconds = 40min, pay MAX' do | |
create_connection_for_minutes(lesson, Time.now, 16) | |
lesson.duration = 30*60 | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 40*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_falsey | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.show_max_duration?).to be_truthy | |
expect(lesson_service.max_duration).to eql lesson.duration | |
expect(lesson_service.close_and_pay!('max')).to be_truthy | |
expect(lesson_service.to_pay_seconds).to eq 30*60 | |
expect(lesson.status).to eq 'completed' | |
expect(lesson.duration).to eq 30*60 | |
expect(VirtualRoomLessonService.new(lesson).elapsed_seconds).to eq 30*60 | |
end | |
it 'elapsed seconds = 16min, lesson duration = 30min, residual seconds = 40min, pay REAL' do | |
create_connection_for_minutes(lesson, Time.now, 16) | |
lesson.duration = 30*60 | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 40*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_falsey | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.show_max_duration?).to be_truthy | |
expect(lesson_service.max_duration).to eql lesson.duration | |
expect(lesson_service.close_and_pay!('real')).to be_truthy | |
expect(lesson_service.to_pay_seconds).to eq 16*60 | |
expect(lesson.status).to eq 'completed' | |
expect(lesson.duration).to eq 16*60 | |
end | |
it 'elapsed seconds = 16min, lesson duration = 30min, residual seconds = 25min, pay MAX' do | |
create_connection_for_minutes(lesson, Time.now, 16) | |
lesson.duration = 30*60 | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 25*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_falsey | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.show_max_duration?).to be_truthy | |
expect(lesson_service.max_duration).to eql 25*60 | |
expect(lesson_service.close_and_pay!('max')).to be_truthy | |
expect(lesson_service.to_pay_seconds).to eq 25*60 | |
expect(lesson.status).to eq 'completed' | |
expect(lesson.duration).to eq 25*60 | |
expect(VirtualRoomLessonService.new(lesson).elapsed_seconds).to eq 25*60 | |
end | |
it 'elapsed seconds = 16min, lesson duration = 30min, residual seconds = 16min, pay MAX' do | |
create_connection_for_minutes(lesson, Time.now, 16) | |
lesson.duration = 30*60 | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 16*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_falsey | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.show_max_duration?).to be_falsey | |
expect(lesson_service.close_and_pay!('max')).to be_falsey | |
expect(lesson_service.to_pay_seconds).to be_nil | |
expect(lesson.status).to eq 'underway' | |
expect(lesson.duration).to eq 30*60 | |
expect(VirtualRoomLessonService.new(lesson).elapsed_seconds).to eq 16*60 | |
end | |
it 'elapsed seconds = 16min, lesson duration = 30min, residual seconds = 16min, pay REAL' do | |
create_connection_for_minutes(lesson, Time.now, 16) | |
lesson.duration = 30*60 | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 16*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_falsey | |
expect(lesson_service.lasted_less_than_duration?).to be_truthy | |
expect(lesson_service.show_min_duration?).to be_truthy | |
expect(lesson_service.show_max_duration?).to be_falsey | |
expect(lesson_service.close_and_pay!('real')).to be_truthy | |
expect(lesson_service.to_pay_seconds).to eq 16*60 | |
expect(lesson.status).to eq 'completed' | |
expect(lesson.duration).to eq 16*60 | |
expect(VirtualRoomLessonService.new(lesson).elapsed_seconds).to eq 16*60 | |
end | |
end | |
context 'real use cases, lasted more than duration' do | |
it 'elapsed seconds = 16min, lesson duration = 15min, residual seconds = 30min, pay REAL' do | |
create_connection_for_minutes(lesson, Time.now, 16) | |
lesson.duration = 15*60 | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 30*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_falsey | |
expect(lesson_service.lasted_less_than_duration?).to be_falsey | |
expect(lesson_service.close_and_pay!('real')).to be_truthy | |
expect(lesson_service.to_pay_seconds).to eq 16*60 | |
expect(lesson.status).to eq 'completed' | |
expect(lesson.duration).to eq 16*60 | |
expect(VirtualRoomLessonService.new(lesson).elapsed_seconds).to eq 16*60 | |
end | |
it 'elapsed seconds = 16min, lesson duration = 15min, residual seconds = 30min, pay MAX or MIN' do | |
create_connection_for_minutes(lesson, Time.now, 16) | |
lesson.duration = 15*60 | |
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 30*60, expire_at: Time.now+1.year, status: :paid) | |
expect(lesson_service.lesson_started?).to be_truthy | |
expect(lesson_service.lasted_less_than_min_duration?).to be_falsey | |
expect(lesson_service.lasted_less_than_duration?).to be_falsey | |
expect(lesson_service.close_and_pay!('max')).to be_falsey | |
expect(lesson_service.to_pay_seconds).to be_nil | |
expect(lesson_service.close_and_pay!('min')).to be_falsey | |
expect(lesson_service.to_pay_seconds).to be_nil | |
expect(lesson.status).to eq 'underway' | |
expect(lesson.duration).to eq 15*60 | |
expect(VirtualRoomLessonService.new(lesson).elapsed_seconds).to eq 16*60 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment