1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 21:29:38 +02:00
Maybe/test/models/rule/action_test.rb

37 lines
1.4 KiB
Ruby
Raw Normal View History

2025-04-02 12:47:07 -04:00
require "test_helper"
class Rule::ActionTest < ActiveSupport::TestCase
include Account::EntriesTestHelper
setup do
@family = families(:empty)
@transaction_rule = @family.rules.create!(resource_type: "transaction")
@account = @family.accounts.create!(name: "Rule test", balance: 1000, currency: "USD", accountable: Depository.new)
@shopping_category = @family.categories.create!(name: "Shopping")
2025-04-02 12:47:07 -04:00
# Some sample transactions to work with
create_transaction(date: Date.current, account: @account, amount: 100, name: "Rule test transaction1", merchant: merchants(:amazon))
2025-04-02 12:47:07 -04:00
create_transaction(date: Date.current, account: @account, amount: -200, name: "Rule test transaction2")
create_transaction(date: 1.day.ago.to_date, account: @account, amount: 50, name: "Rule test transaction3")
create_transaction(date: 1.year.ago.to_date, account: @account, amount: 10, name: "Rule test transaction4", merchant: merchants(:amazon))
2025-04-02 12:47:07 -04:00
create_transaction(date: 1.year.ago.to_date, account: @account, amount: 1000, name: "Rule test transaction5")
@rule_scope = @account.transactions
end
test "set_transaction_category" do
action = Rule::Action.new(
rule: @transaction_rule,
action_type: "set_transaction_category",
value: @shopping_category.id
2025-04-02 12:47:07 -04:00
)
action.apply(@rule_scope)
@rule_scope.reload.each do |transaction|
assert_equal @shopping_category.id, transaction.category_id
2025-04-02 12:47:07 -04:00
end
end
end