mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Add exclude transaction rule action (#437)
* Initial plan * Add ExcludeTransaction rule action executor with tests Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> * Copy clarification --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
@@ -55,6 +55,45 @@ class RuleTest < ActiveSupport::TestCase
|
||||
assert_equal @groceries_category, transaction_entry2.transaction.category
|
||||
end
|
||||
|
||||
test "exclude transaction rule" do
|
||||
transaction_entry = create_transaction(date: Date.current, account: @account, merchant: @whole_foods_merchant)
|
||||
|
||||
assert_not transaction_entry.excluded, "Transaction should not be excluded initially"
|
||||
|
||||
rule = Rule.create!(
|
||||
family: @family,
|
||||
resource_type: "transaction",
|
||||
effective_date: 1.day.ago.to_date,
|
||||
conditions: [ Rule::Condition.new(condition_type: "transaction_merchant", operator: "=", value: @whole_foods_merchant.id) ],
|
||||
actions: [ Rule::Action.new(action_type: "exclude_transaction") ]
|
||||
)
|
||||
|
||||
rule.apply
|
||||
|
||||
transaction_entry.reload
|
||||
|
||||
assert transaction_entry.excluded, "Transaction should be excluded after rule applies"
|
||||
end
|
||||
|
||||
test "exclude transaction rule respects attribute locks" do
|
||||
transaction_entry = create_transaction(date: Date.current, account: @account, merchant: @whole_foods_merchant)
|
||||
transaction_entry.lock_attr!(:excluded)
|
||||
|
||||
rule = Rule.create!(
|
||||
family: @family,
|
||||
resource_type: "transaction",
|
||||
effective_date: 1.day.ago.to_date,
|
||||
conditions: [ Rule::Condition.new(condition_type: "transaction_merchant", operator: "=", value: @whole_foods_merchant.id) ],
|
||||
actions: [ Rule::Action.new(action_type: "exclude_transaction") ]
|
||||
)
|
||||
|
||||
rule.apply
|
||||
|
||||
transaction_entry.reload
|
||||
|
||||
assert_not transaction_entry.excluded, "Transaction should not be excluded when attribute is locked"
|
||||
end
|
||||
|
||||
# Artificial limitation put in place to prevent users from creating overly complex rules
|
||||
# Rules should be shallow and wide
|
||||
test "no nested compound conditions" do
|
||||
|
||||
Reference in New Issue
Block a user