mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Account::Sync model and test fixture simplifications (#968)
* Add sync model * Fresh fixtures for sync tests * Sync tests overhaul * Fix entry tests * Complete remaining model test updates * Update system tests * Update demo data task * Add system tests back to PR checks * More simplifications, add empty family to fixtures for easier testing
This commit is contained in:
parent
de5a2e55b3
commit
c6bdf49f10
60 changed files with 929 additions and 1353 deletions
51
app/models/account/sync.rb
Normal file
51
app/models/account/sync.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
class Account::Sync < ApplicationRecord
|
||||
belongs_to :account
|
||||
|
||||
enum :status, { pending: "pending", syncing: "syncing", completed: "completed", failed: "failed" }
|
||||
|
||||
class << self
|
||||
def for(account, start_date: nil)
|
||||
create! account: account, start_date: start_date
|
||||
end
|
||||
|
||||
def latest
|
||||
order(created_at: :desc).first
|
||||
end
|
||||
end
|
||||
|
||||
def run
|
||||
start!
|
||||
|
||||
sync_balances
|
||||
|
||||
complete!
|
||||
rescue StandardError => error
|
||||
fail! error
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sync_balances
|
||||
syncer = Account::Balance::Syncer.new(account, start_date: start_date)
|
||||
|
||||
syncer.run
|
||||
|
||||
append_warnings(syncer.warnings)
|
||||
end
|
||||
|
||||
def append_warnings(new_warnings)
|
||||
update! warnings: warnings + new_warnings
|
||||
end
|
||||
|
||||
def start!
|
||||
update! status: "syncing", last_ran_at: Time.now
|
||||
end
|
||||
|
||||
def complete!
|
||||
update! status: "completed"
|
||||
end
|
||||
|
||||
def fail!(error)
|
||||
update! status: "failed", error: error.message
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue