1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-02 13:24:20 +01:00
fab-manager/test/integration/reservations/create_test.rb

49 lines
1.5 KiB
Ruby
Raw Normal View History

module Reservations
class CreateTest < ActionDispatch::IntegrationTest
setup do
@user = User.with_role(:member).first
login_as(@user, scope: :user)
end
test "user without plan reserves a machine with success" do
machine = Machine.find(6)
availability = machine.availabilities.first
reservations_count = Reservation.count
invoice_items_count = InvoiceItem.count
VCR.use_cassette("reservations_create_without_plan_success") do
post reservations_path, { reservation: {
user_id: @user.id,
reservable_id: machine.id,
reservable_type: machine.class.name,
2016-04-06 15:22:32 +02:00
card_token: stripe_card_token,
slots_attributes: [
{ start_at: availability.start_at.to_s(:iso8601),
end_at: (availability.start_at + 1.hour).to_s(:iso8601),
availability_id: availability.id
}
]
2016-04-06 15:22:32 +02:00
}}.to_json, default_headers
end
# general assertions
assert_equal 201, response.status
assert_equal reservations_count + 1, Reservation.count
assert_equal invoice_items_count + 1, InvoiceItem.count
# reservation assertions
reservation = Reservation.last
assert reservation.invoice
assert_equal 1, reservation.invoice.invoice_items.count
# invoice_items
invoice_item = InvoiceItem.last
assert invoice_item.stp_invoice_item_id
assert_equal invoice_item.amount, machine.prices.find_by(group_id: @user.group_id).amount
end
end
end