mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(bug) fix running tests
This commit is contained in:
parent
e0931545e8
commit
8ca731ed53
24
test/fixtures/notification_types.yml
vendored
24
test/fixtures/notification_types.yml
vendored
@ -544,6 +544,30 @@ notification_type_68:
|
||||
|
||||
notification_type_69:
|
||||
id: 69
|
||||
name: notify_member_training_auto_cancelled
|
||||
category: trainings
|
||||
is_configurable: false
|
||||
created_at: 2023-02-16 10:42:39.143888000 Z
|
||||
updated_at: 2023-02-16 10:42:39.143888000 Z
|
||||
|
||||
notification_type_70:
|
||||
id: 70
|
||||
name: notify_member_training_authorization_expired
|
||||
category: trainings
|
||||
is_configurable: false
|
||||
created_at: 2023-02-16 10:42:39.143888000 Z
|
||||
updated_at: 2023-02-16 10:42:39.143888000 Z
|
||||
|
||||
notification_type_71:
|
||||
id: 71
|
||||
name: notify_member_training_invalidated
|
||||
category: trainings
|
||||
is_configurable: false
|
||||
created_at: 2023-02-16 10:42:39.143888000 Z
|
||||
updated_at: 2023-02-16 10:42:39.143888000 Z
|
||||
|
||||
notification_type_72:
|
||||
id: 72
|
||||
name: notify_admin_order_is_paid
|
||||
category: shop
|
||||
is_configurable: true
|
||||
|
@ -84,15 +84,15 @@ class Events::RecurrenceTest < ActionDispatch::IntegrationTest
|
||||
attachment: fixture_file_upload('/files/event/Party.jpg')
|
||||
},
|
||||
description: 'Come party tonight at the fablab...',
|
||||
start_date: 2.weeks.from_now.utc,
|
||||
end_date: 2.weeks.from_now.utc,
|
||||
start_date: 2.weeks.from_now,
|
||||
end_date: 2.weeks.from_now,
|
||||
all_day: false,
|
||||
start_time: '18:00',
|
||||
end_time: '23:29',
|
||||
amount: 20,
|
||||
category_id: 2,
|
||||
recurrence: 'month',
|
||||
recurrence_end_at: 2.weeks.from_now.utc + 3.months
|
||||
recurrence_end_at: 2.weeks.from_now + 3.months
|
||||
}
|
||||
},
|
||||
headers: upload_headers
|
||||
@ -103,13 +103,13 @@ class Events::RecurrenceTest < ActionDispatch::IntegrationTest
|
||||
|
||||
# Check the events were correctly created
|
||||
db_events = Event.where(title: name)
|
||||
assert_equal 3, db_events.count
|
||||
assert_equal 4, db_events.count
|
||||
assert(db_events.all? { |event| !event.event_image.attachment.nil? })
|
||||
assert(db_events.all? { |event| !event.description.empty? })
|
||||
assert(db_events.all? { |event| event.availability.start_at.to_date >= 2.weeks.from_now.to_date })
|
||||
assert(db_events.all? { |event| event.availability.start_at.to_date <= 3.months.from_now.end_of_day.to_date + 2.weeks })
|
||||
assert(db_events.all? { |event| event.availability.start_at.to_date <= 2.weeks.from_now.end_of_day.to_date + 3.months })
|
||||
assert(db_events.all? { |event| event.availability.end_at.to_date >= 2.weeks.from_now.to_date })
|
||||
assert(db_events.all? { |event| event.availability.end_at.to_date <= 3.months.from_now.end_of_day.to_date + 2.weeks })
|
||||
assert(db_events.all? { |event| event.availability.end_at.to_date <= 2.weeks.from_now.end_of_day.to_date + 3.months })
|
||||
assert(db_events.none?(&:all_day?))
|
||||
assert(db_events.all? { |event| event.amount == 2000 })
|
||||
assert(db_events.all? { |event| event.event_theme_ids.empty? })
|
||||
|
@ -4,7 +4,7 @@ require 'test_helper'
|
||||
|
||||
module Subscriptions; end
|
||||
|
||||
class Subscriptions::CreateWithPaymentScheduleTest < Minitest::Test
|
||||
class Subscriptions::CreateWithPaymentScheduleTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = User.find_by(username: 'jdupond')
|
||||
login_as(@user, scope: :user)
|
||||
|
@ -3,6 +3,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class Trainings::AutoCancelServiceTest < ActiveSupport::TestCase
|
||||
include ApplicationHelper
|
||||
|
||||
setup do
|
||||
@training = Training.find(4)
|
||||
@availability = Availability.find(22)
|
||||
@ -106,12 +108,13 @@ class Trainings::AutoCancelServiceTest < ActiveSupport::TestCase
|
||||
)
|
||||
end
|
||||
|
||||
test 'auto cancel reservation and generate refunds' do
|
||||
test 'auto cancel reservation but do not generate any refunds if it was free' do
|
||||
Setting.set('wallet_module', true)
|
||||
|
||||
wallet_transactions = WalletTransaction.count
|
||||
|
||||
@training.update(auto_cancel: true, auto_cancel_threshold: 3, auto_cancel_deadline: 24)
|
||||
# user 3 has subscription's credits from training 4
|
||||
customer = User.find(3)
|
||||
slot = @availability.slots.first
|
||||
|
||||
@ -153,12 +156,63 @@ class Trainings::AutoCancelServiceTest < ActiveSupport::TestCase
|
||||
assert_not_nil notification, 'admin notification was not created'
|
||||
assert notification.get_meta_data(:auto_refund)
|
||||
|
||||
# Check customer was not refunded on his wallet
|
||||
assert_equal wallet_transactions, WalletTransaction.count
|
||||
end
|
||||
|
||||
test 'auto cancel reservation and generate a refund' do
|
||||
Setting.set('wallet_module', true)
|
||||
|
||||
wallet_transactions = WalletTransaction.count
|
||||
|
||||
@training.update(auto_cancel: true, auto_cancel_threshold: 3, auto_cancel_deadline: 24)
|
||||
customer = User.find(4)
|
||||
slot = @availability.slots.first
|
||||
|
||||
# Reserve through the cart service to get an invoice associated with the reservation
|
||||
cs = CartService.new(User.admins.first)
|
||||
cs.from_hash(ActionController::Parameters.new({
|
||||
customer_id: customer.id,
|
||||
items: [
|
||||
reservation: {
|
||||
reservable_id: @training.id,
|
||||
reservable_type: @training.class.name,
|
||||
slots_reservations_attributes: [{ slot_id: slot.id }]
|
||||
}
|
||||
]
|
||||
})).build_and_save(nil, nil)
|
||||
|
||||
# Go with cancelling
|
||||
Trainings::AutoCancelService.auto_cancel_reservations(@training)
|
||||
|
||||
# Check reservation was cancelled
|
||||
r = Reservation.last
|
||||
assert_not_nil r.slots_reservations.first&.canceled_at
|
||||
|
||||
# Check notification was sent to the user
|
||||
notification = Notification.find_by(
|
||||
notification_type_id: NotificationType.find_by(name: 'notify_member_training_auto_cancelled'),
|
||||
attached_object_type: 'SlotsReservation',
|
||||
attached_object_id: r.slots_reservations.first&.id
|
||||
)
|
||||
assert_not_nil notification, 'user notification was not created'
|
||||
assert notification.get_meta_data(:auto_refund)
|
||||
|
||||
# Check notification was sent to the admin
|
||||
notification = Notification.find_by(
|
||||
notification_type_id: NotificationType.find_by(name: 'notify_admin_training_auto_cancelled'),
|
||||
attached_object_type: 'Availability',
|
||||
attached_object_id: @availability.id
|
||||
)
|
||||
assert_not_nil notification, 'admin notification was not created'
|
||||
assert notification.get_meta_data(:auto_refund)
|
||||
|
||||
# Check customer was refunded on his wallet
|
||||
assert_equal wallet_transactions + 1, WalletTransaction.count
|
||||
transaction = WalletTransaction.last
|
||||
assert_equal transaction.wallet.user.id, customer.id
|
||||
assert_equal transaction.transaction_type, 'credit'
|
||||
assert_equal transaction.amount, r.invoice_items.first.amount
|
||||
assert_equal to_centimes(transaction.amount), r.invoice_items.first.amount
|
||||
end
|
||||
|
||||
test 'training with default general parameters' do
|
||||
|
Loading…
x
Reference in New Issue
Block a user