mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-13 23:48:55 +01:00
40 lines
1.3 KiB
Ruby
40 lines
1.3 KiB
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
require 'test_helper'
|
||
|
|
||
|
class Trainings::AuthorizationServiceTest < ActiveSupport::TestCase
|
||
|
setup do
|
||
|
@training = Training.find(4)
|
||
|
@user = User.find(9)
|
||
|
end
|
||
|
|
||
|
test 'training authorization is revoked after 6 month' do
|
||
|
# Mark training to auto-revoke after 6 month
|
||
|
@training.update(
|
||
|
authorization: true,
|
||
|
authorization_period: 6
|
||
|
)
|
||
|
# User validates a training
|
||
|
StatisticProfileTraining.create!(
|
||
|
statistic_profile_id: @user.statistic_profile.id,
|
||
|
training_id: @training.id
|
||
|
)
|
||
|
|
||
|
# jump to the future and proceed with auto revocations
|
||
|
travel_to(DateTime.current + 6.months + 1.day)
|
||
|
Trainings::AuthorizationService.auto_cancel_authorizations(@training)
|
||
|
|
||
|
# Check authorization was revoked
|
||
|
assert_nil StatisticProfileTraining.find_by(statistic_profile_id: @user.statistic_profile.id, training_id: @training.id)
|
||
|
assert_not @user.training_machine?(Machine.find(3))
|
||
|
|
||
|
# Check notification was sent
|
||
|
notification = Notification.find_by(
|
||
|
notification_type_id: NotificationType.find_by_name('notify_member_training_authorization_expired'), # rubocop:disable Rails/DynamicFindBy
|
||
|
attached_object_type: 'Training',
|
||
|
attached_object_id: @training.id
|
||
|
)
|
||
|
assert_not_nil notification, 'user notification was not created'
|
||
|
end
|
||
|
end
|