mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Update User Invoices job does not run unless necessary global settings have been configured
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
UpdateUserInvoices = Struct.new("UpdateUserInvoices") do
|
||||
def perform
|
||||
return unless accounts_distributor = Enterprise.find_by_id(Spree::Config.accounts_distributor_id)
|
||||
return unless accounts_distributor.payment_methods.find_by_id(Spree::Config.default_accounts_payment_method_id)
|
||||
return unless accounts_distributor.shipping_methods.find_by_id(Spree::Config.default_accounts_shipping_method_id)
|
||||
|
||||
# If it is the first of the month, update invoices for the previous month up until midnight last night
|
||||
# Otherwise, update invoices for the current month
|
||||
start_date = (Time.now - 1.day).beginning_of_month
|
||||
|
||||
@@ -16,27 +16,70 @@ describe UpdateUserInvoices do
|
||||
let!(:billable_period2) { create(:billable_period, owner: user, begins_at: start_of_july + 12.days, ends_at: start_of_july + 20.days) }
|
||||
|
||||
describe "perform" do
|
||||
let(:accounts_distributor) { double(:accounts_distributor) }
|
||||
before do
|
||||
allow(Enterprise).to receive(:find_by_id) { accounts_distributor }
|
||||
allow(accounts_distributor).to receive(:payment_methods) { double(:payment_methods, find_by_id: true) }
|
||||
allow(accounts_distributor).to receive(:shipping_methods) { double(:shipping_methods, find_by_id: true) }
|
||||
allow(updater).to receive(:update_invoice_for)
|
||||
end
|
||||
|
||||
context "on the first of the month" do
|
||||
travel_to(3.hours)
|
||||
context "when necessary global config setting have not been set" do
|
||||
travel_to(20.days)
|
||||
|
||||
it "updates the user's current invoice with billable_periods from the previous month" do
|
||||
updater.perform
|
||||
expect(updater).to have_received(:update_invoice_for).once
|
||||
.with(user, [old_billable_period])
|
||||
context "when accounts_distributor has been set" do
|
||||
before do
|
||||
allow(Enterprise).to receive(:find_by_id) { false }
|
||||
updater.perform
|
||||
end
|
||||
|
||||
it "doesn't run" do
|
||||
expect(updater).to_not have_received(:update_invoice_for)
|
||||
end
|
||||
end
|
||||
|
||||
context "when default payment method has been set" do
|
||||
before do
|
||||
allow(accounts_distributor).to receive(:payment_methods) { double(:payment_methods, find_by_id: false) }
|
||||
updater.perform
|
||||
end
|
||||
|
||||
it "doesn't run" do
|
||||
expect(updater).to_not have_received(:update_invoice_for)
|
||||
end
|
||||
end
|
||||
|
||||
context "when default shipping method has been set" do
|
||||
before do
|
||||
allow(accounts_distributor).to receive(:shipping_methods) { double(:shipping_methods, find_by_id: false) }
|
||||
updater.perform
|
||||
end
|
||||
|
||||
it "doesn't run" do
|
||||
expect(updater).to_not have_received(:update_invoice_for)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "on other days" do
|
||||
travel_to(20.days)
|
||||
context "when necessary global config setting have been set" do
|
||||
context "on the first of the month" do
|
||||
travel_to(3.hours)
|
||||
|
||||
it "updates the user's current invoice with billable_periods from the current month" do
|
||||
updater.perform
|
||||
expect(updater).to have_received(:update_invoice_for).once
|
||||
.with(user, [billable_period1, billable_period2])
|
||||
it "updates the user's current invoice with billable_periods from the previous month" do
|
||||
updater.perform
|
||||
expect(updater).to have_received(:update_invoice_for).once
|
||||
.with(user, [old_billable_period])
|
||||
end
|
||||
end
|
||||
|
||||
context "on other days" do
|
||||
travel_to(20.days)
|
||||
|
||||
it "updates the user's current invoice with billable_periods from the current month" do
|
||||
updater.perform
|
||||
expect(updater).to have_received(:update_invoice_for).once
|
||||
.with(user, [billable_period1, billable_period2])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user