2022-12-14 12:22:44 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
module Reservations; end
|
|
|
|
|
|
|
|
class Reservations::LastMinuteTest < ActionDispatch::IntegrationTest
|
|
|
|
setup do
|
|
|
|
@user = User.members.first
|
|
|
|
@space = Space.first
|
2022-12-23 14:21:51 +01:00
|
|
|
@availability = Availability.find(21)
|
2022-12-14 12:22:44 +01:00
|
|
|
@admin = User.with_role(:admin).first
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'user cannot reserve last minute booking' do
|
|
|
|
Setting.set('reservation_deadline', '120')
|
|
|
|
|
|
|
|
login_as(@user, scope: :user)
|
|
|
|
|
|
|
|
VCR.use_cassette('last_minute_space_reservations_not_allowed') do
|
|
|
|
post '/api/stripe/confirm_payment', params: {
|
|
|
|
payment_method_id: stripe_payment_method,
|
|
|
|
cart_items: {
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
reservation: {
|
|
|
|
reservable_id: @space.id,
|
|
|
|
reservable_type: @space.class.name,
|
|
|
|
slots_reservations_attributes: [
|
|
|
|
{
|
2022-12-23 14:21:51 +01:00
|
|
|
slot_id: @availability.slots.first.id
|
2022-12-14 12:22:44 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}.to_json, headers: default_headers
|
|
|
|
end
|
|
|
|
|
|
|
|
# general assertions
|
|
|
|
assert_equal 422, response.status
|
2023-01-04 11:12:02 +01:00
|
|
|
assert_match(I18n.t('cart_item_validation.deadline', { MINUTES: 120 }), response.body)
|
2022-12-14 12:22:44 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'user can reserve last minute booking' do
|
|
|
|
Setting.set('reservation_deadline', '0')
|
|
|
|
|
|
|
|
login_as(@user, scope: :user)
|
|
|
|
|
|
|
|
reservations_count = Reservation.count
|
|
|
|
invoice_count = Invoice.count
|
|
|
|
invoice_items_count = InvoiceItem.count
|
|
|
|
users_credit_count = UsersCredit.count
|
|
|
|
subscriptions_count = Subscription.count
|
|
|
|
|
|
|
|
VCR.use_cassette('last_minute_space_reservations_allowed') do
|
|
|
|
post '/api/stripe/confirm_payment', params: {
|
|
|
|
payment_method_id: stripe_payment_method,
|
|
|
|
cart_items: {
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
reservation: {
|
|
|
|
reservable_id: @space.id,
|
|
|
|
reservable_type: @space.class.name,
|
|
|
|
slots_reservations_attributes: [
|
|
|
|
{
|
2022-12-23 14:21:51 +01:00
|
|
|
slot_id: @availability.slots.first.id
|
2022-12-14 12:22:44 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}.to_json, headers: default_headers
|
|
|
|
end
|
|
|
|
|
|
|
|
# general assertions
|
|
|
|
assert_equal 201, response.status
|
|
|
|
assert_equal reservations_count + 1, Reservation.count
|
|
|
|
assert_equal invoice_count + 1, Invoice.count
|
|
|
|
assert_equal invoice_items_count + 1, InvoiceItem.count
|
|
|
|
assert_equal users_credit_count, UsersCredit.count
|
|
|
|
assert_equal subscriptions_count, Subscription.count
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'admin can reserve last minute booking anyway' do
|
|
|
|
Setting.set('reservation_deadline', '120')
|
|
|
|
|
|
|
|
login_as(@admin, scope: :user)
|
|
|
|
|
|
|
|
reservations_count = Reservation.count
|
|
|
|
invoice_count = Invoice.count
|
|
|
|
invoice_items_count = InvoiceItem.count
|
|
|
|
users_credit_count = UsersCredit.count
|
|
|
|
subscriptions_count = Subscription.count
|
|
|
|
|
|
|
|
post '/api/local_payment/confirm_payment', params: {
|
|
|
|
customer_id: @user.id,
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
reservation: {
|
|
|
|
reservable_id: @space.id,
|
|
|
|
reservable_type: @space.class.name,
|
|
|
|
slots_reservations_attributes: [
|
|
|
|
{
|
2022-12-23 14:21:51 +01:00
|
|
|
slot_id: @availability.slots.first.id
|
2022-12-14 12:22:44 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}.to_json, headers: default_headers
|
|
|
|
|
|
|
|
# general assertions
|
|
|
|
assert_equal 201, response.status
|
|
|
|
assert_equal reservations_count + 1, Reservation.count
|
|
|
|
assert_equal invoice_count + 1, Invoice.count
|
|
|
|
assert_equal invoice_items_count + 1, InvoiceItem.count
|
|
|
|
assert_equal users_credit_count, UsersCredit.count
|
|
|
|
assert_equal subscriptions_count, Subscription.count
|
|
|
|
end
|
|
|
|
end
|