mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(test) prevent last minutes bookings
This commit is contained in:
parent
14b5c40ec8
commit
3a2f488c56
@ -524,6 +524,7 @@ en:
|
||||
space_explications_alert: "Explanation message on the space reservation page"
|
||||
visibility_yearly: "Maximum visibility for annual subscribers"
|
||||
visibility_others: "Maximum visibility for other members"
|
||||
reservation_deadline: "Prevent reservation before it starts"
|
||||
display_name_enable: "Display names in the calendar"
|
||||
machines_sort_by: "Machines display order"
|
||||
accounting_journal_code: "Journal code"
|
||||
|
10
test/fixtures/availabilities.yml
vendored
10
test/fixtures/availabilities.yml
vendored
@ -199,3 +199,13 @@ availability_20:
|
||||
updated_at: 2022-07-18 12:38:21.616510000 Z
|
||||
nb_total_places: 5
|
||||
destroying: false
|
||||
|
||||
availability_21:
|
||||
id: 21
|
||||
start_at: <%= 10.minutes.from_now.utc.strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||
end_at: <%= (10.minutes.from_now + 1.hour).utc.strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||
available_type: space
|
||||
created_at: 2022-12-14 12:01:26.165110000 Z
|
||||
updated_at: 2022-12-14 12:01:26.165110000 Z
|
||||
nb_total_places: 2
|
||||
destroying: false
|
||||
|
8
test/fixtures/slots.yml
vendored
8
test/fixtures/slots.yml
vendored
@ -566,3 +566,11 @@ slot_132:
|
||||
created_at: '2022-07-18 12:38:21.616510'
|
||||
updated_at: '2022-07-18 12:38:21.616510'
|
||||
availability_id: 20
|
||||
|
||||
slot_133:
|
||||
id: 133
|
||||
start_at: <%= 10.minutes.from_now.utc.strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||
end_at: <%= (10.minutes.from_now + 1.hour).utc.strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||
created_at: '2022-12-14 12:01:26.165110'
|
||||
updated_at: '2022-12-14 12:01:26.165110'
|
||||
availability_id: 21
|
||||
|
9
test/fixtures/spaces_availabilities.yml
vendored
9
test/fixtures/spaces_availabilities.yml
vendored
@ -3,4 +3,11 @@ spaces_availability_1:
|
||||
space_id: 1
|
||||
availability_id: 18
|
||||
created_at: 2017-02-15 15:59:08.892741000 Z
|
||||
updated_at: 2017-02-15 15:59:08.892741000 Z
|
||||
updated_at: 2017-02-15 15:59:08.892741000 Z
|
||||
|
||||
spaces_availability_2:
|
||||
id: 2
|
||||
space_id: 1
|
||||
availability_id: 21
|
||||
created_at: 2022-12-14 12:01:26.165110000 Z
|
||||
updated_at: 2022-12-14 12:01:26.165110000 Z
|
||||
|
123
test/integration/reservations/last_minute_test.rb
Normal file
123
test/integration/reservations/last_minute_test.rb
Normal file
@ -0,0 +1,123 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module Reservations; end
|
||||
|
||||
class Reservations::LastMinuteTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = User.members.first
|
||||
@space = Space.first
|
||||
@availbility = Availability.find(21)
|
||||
@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: [
|
||||
{
|
||||
slot_id: @availbility.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}.to_json, headers: default_headers
|
||||
end
|
||||
|
||||
# general assertions
|
||||
assert_equal 422, response.status
|
||||
assert_match(/cannot reserve a slot 120 minutes prior to its start/, response.body)
|
||||
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: [
|
||||
{
|
||||
slot_id: @availbility.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}.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: [
|
||||
{
|
||||
slot_id: @availbility.slots.first.id
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}.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
|
Loading…
x
Reference in New Issue
Block a user