/
reservation_instrument_switcher_spec.rb
52 lines (42 loc) · 2.06 KB
/
reservation_instrument_switcher_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require "rails_helper"
RSpec.describe ReservationInstrumentSwitcher do
let(:instrument) { FactoryBot.create(:setup_instrument, relay: create(:relay_syna)) }
let(:reservation) { FactoryBot.create(:purchased_reservation, product: instrument) }
let(:action) { described_class.new(reservation) }
describe '#switch_on!' do
def do_action
action.switch_on!
end
before do
allow(reservation).to receive(:can_switch_instrument_on?).and_return(true)
end
context "no other reservations" do
it "starts the reservation" do
expect { do_action }.to change { reservation.reload.actual_start_at }.from(nil)
end
end
context "with a long running reservation" do
let!(:running_reservation) { FactoryBot.create(:purchased_reservation, :long_running, product: instrument) }
it "moves the running reservation to problem status" do
expect { do_action }.to change { running_reservation.order_detail.reload.problem }.from(false).to(true)
end
end
context "with a problem reservation that got canceled" do
let!(:running_reservation) { FactoryBot.create(:purchased_reservation, :long_running, product: instrument) }
before { running_reservation.order_detail.update_order_status! running_reservation.user, OrderStatus.canceled, admin: true }
it "does not do anything to the canceled reservation" do
expect { do_action }.not_to change { running_reservation.reload }
end
end
context "with a problem reservation that got reconciled" do
let!(:running_reservation) { FactoryBot.create(:purchased_reservation, :long_running, product: instrument) }
before do
running_reservation.order_detail.update_order_status! running_reservation.user, OrderStatus.complete, admin: true
running_reservation.order_detail.update_order_status! running_reservation.user, OrderStatus.reconciled, admin: true
end
it "does not do anything to the canceled reservation" do
expect { do_action }.not_to change { running_reservation.reload }
end
end
end
end