1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-20 13:49:39 +02:00
Maybe/test/models/rule/action_test.rb

38 lines
1.5 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)
@grocery_category = @family.categories.create!(name: "Grocery")
@whole_foods_merchant = @family.merchants.create!(name: "Whole Foods")
# Some sample transactions to work with
create_transaction(date: Date.current, account: @account, amount: 100, name: "Rule test transaction1", merchant: @whole_foods_merchant)
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: @whole_foods_merchant)
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: @grocery_category.id
)
action.apply(@rule_scope)
@rule_scope.reload.each do |transaction|
assert_equal @grocery_category.id, transaction.category_id
end
end
end