forked from getlago/lago-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(refresh-credits): Add job to refresh wallets credits
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Clock | ||
class RefreshWalletsCreditsJob < ApplicationJob | ||
queue_as 'clock' | ||
|
||
def perform | ||
Wallet.active.find_each do |wallet| | ||
Wallets::RefreshCreditsJob.perform_later(wallet) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe Clock::RefreshWalletsCreditsJob, job: true do | ||
subject { described_class } | ||
|
||
describe '.perform' do | ||
let(:wallet) { create(:wallet) } | ||
|
||
before do | ||
wallet | ||
allow(Wallets::RefreshCreditsService).to receive(:call) | ||
end | ||
|
||
it 'calls the refresh service' do | ||
described_class.perform_now | ||
expect(Wallets::RefreshCreditsJob).to have_been_enqueued.with(wallet) | ||
end | ||
|
||
context 'when not active' do | ||
let(:wallet) { create(:wallet, :terminated) } | ||
|
||
it 'does not call the refresh service' do | ||
described_class.perform_now | ||
expect(Wallets::RefreshCreditsJob).not_to have_been_enqueued.with(wallet) | ||
end | ||
end | ||
end | ||
end |