Files
openfoodnetwork/lib/tasks/subscriptions/test.rake
David Rodríguez 4c6d894bc0 Bump RuboCop to 1.86.6
There were a few changes needed:

* Plugins are now specified through `plugin:` config keyword.
* All plugin gems need to be specified explicitly in Gemfile since they
  are no longer dependencies of plugins already specified explicitly.
* All plugin gems need to be updated in other to use the new APIs.
* One cop was renamed.
* New offenses safe to correct were corrected directly with `bundle exec
  rubocop -a`.
* New offenses unsafe to correct were added to the TODO configuration
  with `bundle exec rubocop --auto-gen-config --auto-gen-only-exclude
  --exclude-limit 1400 --no-auto-gen-timestamp`.
2025-10-27 11:30:33 +01:00

73 lines
2.1 KiB
Ruby

# frozen_string_literal: true
namespace :ofn do
namespace :subs do
namespace :test do
desc "Repeat placement job for a specific Order Cycle"
task repeat_placement_job: :environment do
puts "WARNING: this task will generate new, and potentially duplicate, customer orders"
exit_in_production
order_cycle_id = request_order_cycle_id
# Open Order Cycle by moving close_at to the future and open_at to the past
set_order_cycle_times(
order_cycle_id,
15.minutes.ago,
15.minutes.from_now
)
# Reset Proxy Orders of the Order Cycle
# by detatching them from existing orders and resetting placed and confirmed dates
ProxyOrder.find_by(order_cycle_id:)&.update!(
order_id: nil,
confirmed_at: nil,
placed_at: nil
)
# Run placement job to create orders
SubscriptionPlacementJob.perform_now
end
desc "Force confirmation job for a specific Order Cycle"
task force_confirmation_job: :environment do
puts "WARNING: this task will process payments in customer orders"
exit_in_production
order_cycle_id = request_order_cycle_id
# Close Orde Cycle by moving close_at to the past
set_order_cycle_times(
order_cycle_id,
30.minutes.ago,
15.minutes.ago
)
# Run Confirm Job to process payments
SubscriptionConfirmJob.perform_now
end
def exit_in_production
return unless Rails.env.production?
puts "Oops, we are in production environment. Exiting."
exit
end
def set_order_cycle_times(order_cycle_id, open_at, close_at)
OrderCycle.find(order_cycle_id).update!(
orders_open_at: open_at,
orders_close_at: close_at
)
end
def request_order_cycle_id
puts "Please input Order Cycle ID to reset"
input = $stdin.gets.chomp
exit if input.blank? || !Integer(input)
Integer(input)
end
end
end
end