1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

(quality) remove obsolete NotificationType.find_by_name

This commit is contained in:
Sylvain 2023-02-16 16:08:24 +01:00
parent 2fa59167ec
commit e0931545e8
15 changed files with 89 additions and 75 deletions

View File

@ -21,7 +21,7 @@ class ReservationReminderWorker
already_sent = Notification.where( already_sent = Notification.where(
attached_object_type: Reservation.name, attached_object_type: Reservation.name,
attached_object_id: r.id, attached_object_id: r.id,
notification_type_id: NotificationType.find_by_name('notify_member_reservation_reminder') notification_type_id: NotificationType.find_by(name: 'notify_member_reservation_reminder')
).count ).count
next if already_sent.positive? next if already_sent.positive?

View File

@ -30,7 +30,7 @@ class AbusesTest < ActionDispatch::IntegrationTest
assert_equal 'Project', abuse[:reporting][:signaled_type], 'signaled object type mismatch' assert_equal 'Project', abuse[:reporting][:signaled_type], 'signaled object type mismatch'
# Check notifications were sent for every admins # Check notifications were sent for every admins
notifications = Notification.where(notification_type_id: NotificationType.find_by_name('notify_admin_abuse_reported'), # rubocop:disable Rails/DynamicFindBy notifications = Notification.where(notification_type_id: NotificationType.find_by(name: 'notify_admin_abuse_reported'),
attached_object_type: 'Abuse', attached_object_type: 'Abuse',
attached_object_id: abuse[:reporting][:id]) attached_object_id: abuse[:reporting][:id])
assert_not_empty notifications, 'no notifications were created' assert_not_empty notifications, 'no notifications were created'

View File

@ -145,7 +145,7 @@ class AuthProvidersTest < ActionDispatch::IntegrationTest
# check resulting notification # check resulting notification
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_user_auth_migration'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_user_auth_migration'),
attached_object_type: 'User', attached_object_type: 'User',
attached_object_id: user.id attached_object_id: user.id
) )

View File

@ -92,7 +92,7 @@ class Events::RecurrenceTest < ActionDispatch::IntegrationTest
amount: 20, amount: 20,
category_id: 2, category_id: 2,
recurrence: 'month', recurrence: 'month',
recurrence_end_at: 3.months.from_now.utc + 2.weeks recurrence_end_at: 2.weeks.from_now.utc + 3.months
} }
}, },
headers: upload_headers headers: upload_headers
@ -103,7 +103,7 @@ class Events::RecurrenceTest < ActionDispatch::IntegrationTest
# Check the events were correctly created # Check the events were correctly created
db_events = Event.where(title: name) db_events = Event.where(title: name)
assert_equal 4, db_events.count assert_equal 3, db_events.count
assert(db_events.all? { |event| !event.event_image.attachment.nil? }) assert(db_events.all? { |event| !event.event_image.attachment.nil? })
assert(db_events.all? { |event| !event.description.empty? }) 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 >= 2.weeks.from_now.to_date })

View File

@ -41,7 +41,7 @@ class Exports::MembersExportTest < ActionDispatch::IntegrationTest
# test data # test data
wb = workbook[I18n.t('export_members.members')] wb = workbook[I18n.t('export_members.members')]
member = User.find(wb.sheet_data[1][0].value) member = User.find(wb.sheet_data[1][0].value)
assert_equal (member.is_allow_newsletter ? 1 : 0), wb.sheet_data[1][4].value assert_equal (member.is_allow_newsletter ? 1 : 0), wb.sheet_data[1][5].value
# Clean XLSX file # Clean XLSX file
require 'fileutils' require 'fileutils'

View File

@ -52,10 +52,12 @@ class Subscriptions::CreateAsAdminTest < ActionDispatch::IntegrationTest
# Check that the user benefit from prices of his plan # Check that the user benefit from prices of his plan
printer = Machine.find_by(slug: 'imprimante-3d') printer = Machine.find_by(slug: 'imprimante-3d')
assert_equal 15, (printer.prices.find_by(group_id: user.group_id, plan_id: user.subscription.plan_id).amount / 100.00), 'machine hourly price does not match' assert_equal 15,
(printer.prices.find_by(group_id: user.group_id, plan_id: user.subscription.plan_id).amount / 100.00),
'machine hourly price does not match'
# Check notification was sent to the user # Check notification was sent to the user
notification = Notification.find_by(notification_type_id: NotificationType.find_by_name('notify_member_subscribed_plan'), notification = Notification.find_by(notification_type_id: NotificationType.find_by(name: 'notify_member_subscribed_plan'),
attached_object_type: 'Subscription', attached_object_id: subscription.id) attached_object_type: 'Subscription', attached_object_id: subscription.id)
assert_not_nil notification, 'user notification was not created' assert_not_nil notification, 'user notification was not created'
assert_equal user.id, notification.receiver_id, 'wrong user notified' assert_equal user.id, notification.receiver_id, 'wrong user notified'

View File

@ -59,7 +59,7 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
# Check notifications were sent for every admins # Check notifications were sent for every admins
notifications = Notification.where( notifications = Notification.where(
notification_type_id: NotificationType.find_by_name('notify_admin_subscribed_plan'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_admin_subscribed_plan'),
attached_object_type: 'Subscription', attached_object_type: 'Subscription',
attached_object_id: subscription[:id] attached_object_id: subscription[:id]
) )
@ -164,7 +164,7 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
# Check notifications were sent for every admins # Check notifications were sent for every admins
notifications = Notification.where( notifications = Notification.where(
notification_type_id: NotificationType.find_by_name('notify_admin_subscribed_plan'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_admin_subscribed_plan'),
attached_object_type: 'Subscription', attached_object_type: 'Subscription',
attached_object_id: subscription[:id] attached_object_id: subscription[:id]
) )
@ -191,53 +191,6 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
assert_equal invoice.wallet_transaction_id, transaction.id assert_equal invoice.wallet_transaction_id, transaction.id
end end
test 'user takes a subscription with payment schedule' do
plan = Plan.find_by(group_id: @user.group.id, type: 'Plan', base_name: 'Abonnement mensualisable')
payment_schedule_count = PaymentSchedule.count
payment_schedule_items_count = PaymentScheduleItem.count
VCR.use_cassette('subscriptions_user_create_with_payment_schedule') do
post '/api/stripe/setup_subscription',
params: {
payment_method_id: stripe_payment_method,
cart_items: {
items: [
{
subscription: {
plan_id: plan.id
}
}
],
payment_schedule: true,
payment_method: 'cart'
}
}.to_json, headers: default_headers
# Check response format & status
assert_equal 201, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the response
sub = json_response(response.body)
assert_not_nil sub[:id]
end
# Check generalities
assert_equal payment_schedule_count + 1, PaymentSchedule.count, 'missing the payment schedule'
assert_equal payment_schedule_items_count + 12, PaymentScheduleItem.count, 'missing some payment schedule items'
# Check the correct plan was subscribed
result = json_response(response.body)
assert_equal PaymentSchedule.last.id, result[:id], 'payment schedule id does not match'
subscription = PaymentSchedule.find(result[:id]).payment_schedule_objects.first.object
assert_equal plan.id, subscription.plan_id, 'subscribed plan does not match'
# Check that the user has the correct subscription
assert_not_nil @user.subscription, "user's subscription was not found"
assert_not_nil @user.subscription.plan, "user's subscribed plan was not found"
assert_equal plan.id, @user.subscription.plan_id, "user's plan does not match"
end
test 'user takes a subscription but does not confirm 3DS' do test 'user takes a subscription but does not confirm 3DS' do
plan = Plan.find_by(group_id: @user.group.id, type: 'Plan', base_name: 'Abonnement mensualisable') plan = Plan.find_by(group_id: @user.group.id, type: 'Plan', base_name: 'Abonnement mensualisable')
payment_schedule_count = PaymentSchedule.count payment_schedule_count = PaymentSchedule.count

View File

@ -0,0 +1,59 @@
# frozen_string_literal: true
require 'test_helper'
module Subscriptions; end
class Subscriptions::CreateWithPaymentScheduleTest < Minitest::Test
setup do
@user = User.find_by(username: 'jdupond')
login_as(@user, scope: :user)
end
test 'user takes a subscription with payment schedule' do
plan = Plan.find_by(group_id: @user.group.id, type: 'Plan', base_name: 'Abonnement mensualisable')
payment_schedule_count = PaymentSchedule.count
payment_schedule_items_count = PaymentScheduleItem.count
VCR.use_cassette('subscriptions_user_create_with_payment_schedule') do
post '/api/stripe/setup_subscription',
params: {
payment_method_id: stripe_payment_method,
cart_items: {
items: [
{
subscription: {
plan_id: plan.id
}
}
],
payment_schedule: true,
payment_method: 'cart'
}
}.to_json, headers: default_headers
# Check response format & status
assert_equal 201, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the response
sub = json_response(response.body)
assert_not_nil sub[:id]
end
# Check generalities
assert_equal payment_schedule_count + 1, PaymentSchedule.count, 'missing the payment schedule'
assert_equal payment_schedule_items_count + 12, PaymentScheduleItem.count, 'missing some payment schedule items'
# Check the correct plan was subscribed
result = json_response(response.body)
assert_equal PaymentSchedule.last.id, result[:id], 'payment schedule id does not match'
subscription = PaymentSchedule.find(result[:id]).payment_schedule_objects.first.object
assert_equal plan.id, subscription.plan_id, 'subscribed plan does not match'
# Check that the user has the correct subscription
assert_not_nil @user.subscription, "user's subscription was not found"
assert_not_nil @user.subscription.plan, "user's subscribed plan was not found"
assert_equal plan.id, @user.subscription.plan_id, "user's plan does not match"
end
end

View File

@ -49,7 +49,7 @@ class Subscriptions::FreeExtensionTest < ActionDispatch::IntegrationTest
# Check notification was sent to the user # Check notification was sent to the user
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_member_subscription_extended'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_member_subscription_extended'),
attached_object_type: 'Subscription', attached_object_type: 'Subscription',
attached_object_id: subscription[:id] attached_object_id: subscription[:id]
) )

View File

@ -64,7 +64,7 @@ class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
# Check notification was sent to the user # Check notification was sent to the user
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_member_subscribed_plan'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_member_subscribed_plan'),
attached_object_type: 'Subscription', attached_object_type: 'Subscription',
attached_object_id: subscription[:id] attached_object_id: subscription[:id]
) )
@ -118,7 +118,7 @@ class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
# Check notification was sent to the user # Check notification was sent to the user
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_member_subscribed_plan'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_member_subscribed_plan'),
attached_object_type: 'Subscription', attached_object_type: 'Subscription',
attached_object_id: subscription[:id] attached_object_id: subscription[:id]
) )

View File

@ -62,7 +62,7 @@ class Subscriptions::RenewAsUserTest < ActionDispatch::IntegrationTest
# Check notifications were sent for every admins # Check notifications were sent for every admins
notifications = Notification.where( notifications = Notification.where(
notification_type_id: NotificationType.find_by_name('notify_admin_subscribed_plan'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_admin_subscribed_plan'),
attached_object_type: 'Subscription', attached_object_type: 'Subscription',
attached_object_id: subscription[:id] attached_object_id: subscription[:id]
) )

View File

@ -2,7 +2,7 @@
class NotificationsMailerPreview < ActionMailer::Preview class NotificationsMailerPreview < ActionMailer::Preview
def notify_user_auth_migration def notify_user_auth_migration
notif = Notification.where(notification_type_id: NotificationType.find_by_name('notify_user_auth_migration')).first notif = Notification.find_by(notification_type_id: NotificationType.find_by(name: 'notify_user_auth_migration'))
NotificationsMailer.send_mail_by(notif) NotificationsMailer.send_mail_by(notif)
end end
end end

View File

@ -21,7 +21,7 @@ class Trainings::AuthorizationServiceTest < ActiveSupport::TestCase
) )
# jump to the future and proceed with auto revocations # jump to the future and proceed with auto revocations
travel_to(DateTime.current + 6.months + 1.day) travel_to(6.months.from_now + 1.day)
Trainings::AuthorizationService.auto_cancel_authorizations(@training) Trainings::AuthorizationService.auto_cancel_authorizations(@training)
# Check authorization was revoked # Check authorization was revoked
@ -30,7 +30,7 @@ class Trainings::AuthorizationServiceTest < ActiveSupport::TestCase
# Check notification was sent # Check notification was sent
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_member_training_authorization_expired'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_member_training_authorization_expired'),
attached_object_type: 'Training', attached_object_type: 'Training',
attached_object_id: @training.id attached_object_id: @training.id
) )

View File

@ -31,7 +31,7 @@ class Trainings::AutoCancelServiceTest < ActiveSupport::TestCase
# Check notification was sent to the user # Check notification was sent to the user
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_member_training_auto_cancelled'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_member_training_auto_cancelled'),
attached_object_type: 'SlotsReservation', attached_object_type: 'SlotsReservation',
attached_object_id: r.slots_reservations.first&.id attached_object_id: r.slots_reservations.first&.id
) )
@ -40,7 +40,7 @@ class Trainings::AutoCancelServiceTest < ActiveSupport::TestCase
# Check notification was sent to the admin # Check notification was sent to the admin
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_admin_training_auto_cancelled'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_admin_training_auto_cancelled'),
attached_object_type: 'Availability', attached_object_type: 'Availability',
attached_object_id: @availability.id attached_object_id: @availability.id
) )
@ -95,12 +95,12 @@ class Trainings::AutoCancelServiceTest < ActiveSupport::TestCase
# Check no notifications were sent # Check no notifications were sent
assert_empty Notification.where( assert_empty Notification.where(
notification_type_id: NotificationType.find_by_name('notify_member_training_auto_cancelled'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_member_training_auto_cancelled'),
attached_object_type: 'SlotsReservation', attached_object_type: 'SlotsReservation',
attached_object_id: [r1.slots_reservations.first&.id, r2.slots_reservations.first&.id, r3.slots_reservations.first&.id] attached_object_id: [r1.slots_reservations.first&.id, r2.slots_reservations.first&.id, r3.slots_reservations.first&.id]
) )
assert_nil Notification.find_by( assert_nil Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_admin_training_auto_cancelled'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_admin_training_auto_cancelled'),
attached_object_type: 'Availability', attached_object_type: 'Availability',
attached_object_id: @availability.id attached_object_id: @availability.id
) )
@ -137,7 +137,7 @@ class Trainings::AutoCancelServiceTest < ActiveSupport::TestCase
# Check notification was sent to the user # Check notification was sent to the user
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_member_training_auto_cancelled'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_member_training_auto_cancelled'),
attached_object_type: 'SlotsReservation', attached_object_type: 'SlotsReservation',
attached_object_id: r.slots_reservations.first&.id attached_object_id: r.slots_reservations.first&.id
) )
@ -146,7 +146,7 @@ class Trainings::AutoCancelServiceTest < ActiveSupport::TestCase
# Check notification was sent to the admin # Check notification was sent to the admin
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_admin_training_auto_cancelled'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_admin_training_auto_cancelled'),
attached_object_type: 'Availability', attached_object_type: 'Availability',
attached_object_id: @availability.id attached_object_id: @availability.id
) )

View File

@ -21,7 +21,7 @@ class Trainings::InvalidationServiceTest < ActiveSupport::TestCase
) )
# jump to the future and proceed with auto invalidations # jump to the future and proceed with auto invalidations
travel_to(DateTime.current + 6.months + 1.day) travel_to(6.months.from_now + 1.day)
Trainings::InvalidationService.auto_invalidate(@training) Trainings::InvalidationService.auto_invalidate(@training)
# Check authorization was revoked # Check authorization was revoked
@ -30,7 +30,7 @@ class Trainings::InvalidationServiceTest < ActiveSupport::TestCase
# Check notification was sent # Check notification was sent
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_member_training_invalidated'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_member_training_invalidated'),
attached_object_type: 'Training', attached_object_type: 'Training',
attached_object_id: @training.id attached_object_id: @training.id
) )
@ -51,7 +51,7 @@ class Trainings::InvalidationServiceTest < ActiveSupport::TestCase
# User reserves a machine authorized by this training # User reserves a machine authorized by this training
machine = @training.machines.first machine = @training.machines.first
slot = machine.availabilities.where('start_at > ?', DateTime.current).first&.slots&.first slot = machine.availabilities.where('start_at > ?', Time.current).first&.slots&.first
Reservation.create!( Reservation.create!(
reservable_id: machine.id, reservable_id: machine.id,
reservable_type: Machine.name, reservable_type: Machine.name,
@ -60,7 +60,7 @@ class Trainings::InvalidationServiceTest < ActiveSupport::TestCase
) )
# jump to the future and proceed with auto invalidations # jump to the future and proceed with auto invalidations
travel_to(DateTime.current + 6.months + 1.day) travel_to(6.months.from_now + 1.day)
Trainings::InvalidationService.auto_invalidate(@training) Trainings::InvalidationService.auto_invalidate(@training)
# Check authorization was not revoked # Check authorization was not revoked
@ -69,7 +69,7 @@ class Trainings::InvalidationServiceTest < ActiveSupport::TestCase
# Check notification was not sent # Check notification was not sent
notification = Notification.find_by( notification = Notification.find_by(
notification_type_id: NotificationType.find_by_name('notify_member_training_invalidated'), # rubocop:disable Rails/DynamicFindBy notification_type_id: NotificationType.find_by(name: 'notify_member_training_invalidated'),
attached_object_type: 'Training', attached_object_type: 'Training',
attached_object_id: @training.id attached_object_id: @training.id
) )