mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
Add "Transaction account" as rule condition filter (#1186)
* feat: Add transaction account as rule condition filter * Update app/models/rule/condition_filter/transaction_account.rb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Alessio Cappa <104093777+alessiocappa@users.noreply.github.com> --------- Signed-off-by: Alessio Cappa <104093777+alessiocappa@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -294,4 +294,58 @@ class RuleTest < ActiveSupport::TestCase
|
||||
test "total_affected_resource_count returns zero for empty rules" do
|
||||
assert_equal 0, Rule.total_affected_resource_count([])
|
||||
end
|
||||
|
||||
test "rule matching on transaction account" do
|
||||
# Create a second account
|
||||
other_account = @family.accounts.create!(
|
||||
name: "Other account",
|
||||
balance: 500,
|
||||
currency: "USD",
|
||||
accountable: Depository.new
|
||||
)
|
||||
|
||||
# Transaction on the target account
|
||||
transaction_entry1 = create_transaction(
|
||||
date: Date.current,
|
||||
account: @account,
|
||||
amount: 50
|
||||
)
|
||||
|
||||
# Transaction on another account
|
||||
transaction_entry2 = create_transaction(
|
||||
date: Date.current,
|
||||
account: other_account,
|
||||
amount: 75
|
||||
)
|
||||
|
||||
rule = Rule.create!(
|
||||
family: @family,
|
||||
resource_type: "transaction",
|
||||
effective_date: 1.day.ago.to_date,
|
||||
conditions: [
|
||||
Rule::Condition.new(
|
||||
condition_type: "transaction_account",
|
||||
operator: "=",
|
||||
value: @account.id
|
||||
)
|
||||
],
|
||||
actions: [
|
||||
Rule::Action.new(
|
||||
action_type: "set_transaction_category",
|
||||
value: @groceries_category.id
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
rule.apply
|
||||
|
||||
transaction_entry1.reload
|
||||
transaction_entry2.reload
|
||||
|
||||
assert_equal @groceries_category, transaction_entry1.transaction.category,
|
||||
"Transaction on selected account should be categorized"
|
||||
|
||||
assert_nil transaction_entry2.transaction.category,
|
||||
"Transaction on other account should not be categorized"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user