Merge branch 'main' into claude/sure-patrimonial-history-c8s7am

Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
Juan José Mata
2026-08-01 11:59:42 -07:00
committed by GitHub
7 changed files with 358 additions and 3 deletions

View File

@@ -0,0 +1,44 @@
require "test_helper"
class Assistant::Function::GetTransactionsTest < ActiveSupport::TestCase
setup do
@user = users(:family_admin)
@transaction = transactions(:one)
@function = Assistant::Function::GetTransactions.new(@user)
end
test "returns transaction ids and notes" do
@transaction.entry.update!(notes: "Visible note")
result = @function.call(
"page" => 1,
"order" => "asc",
"search" => @transaction.entry.name
)
transaction = result[:transactions].find { |item| item[:id] == @transaction.id }
assert_not_nil transaction
assert_equal @transaction.entry.notes, transaction[:notes]
end
test "excludes transactions from inaccessible accounts" do
hidden_entry = Entry.create!(
account: accounts(:investment),
name: "Private investment transaction",
date: Date.current,
amount: 100,
currency: "USD",
entryable: Transaction.new
)
hidden_entry.update!(notes: "Private note")
result = Assistant::Function::GetTransactions.new(users(:family_member)).call(
"page" => 1,
"order" => "asc",
"search" => hidden_entry.name
)
assert_empty result[:transactions]
end
end

View File

@@ -0,0 +1,93 @@
require "test_helper"
class Assistant::Function::UpdateTransactionTest < ActiveSupport::TestCase
setup do
@user = users(:family_admin)
@transaction = transactions(:one)
@function = Assistant::Function::UpdateTransaction.new(@user)
end
test "updates category notes and tags" do
category = categories(:subcategory)
tag = tags(:one)
result = @function.call(
"id" => @transaction.id,
"category_id" => category.id,
"notes" => "Updated by assistant",
"tag_ids" => [ tag.id ]
)
assert_equal true, result[:success]
@transaction.reload
assert_equal category, @transaction.category
assert_equal "Updated by assistant", @transaction.entry.notes
assert_equal [ tag.id ], @transaction.tag_ids
end
test "clears category merchant notes and tags when explicitly requested" do
@transaction.update!(category: categories(:food_and_drink), merchant: merchants(:amazon))
@transaction.tags = [ tags(:one) ]
result = @function.call(
"id" => @transaction.id,
"category_id" => nil,
"merchant_id" => nil,
"notes" => nil,
"tag_ids" => []
)
assert_equal true, result[:success]
@transaction.reload
assert_nil @transaction.category
assert_nil @transaction.merchant
assert_nil @transaction.entry.notes
assert_empty @transaction.tags
assert @transaction.locked?(:tag_ids)
end
test "rejects categories outside the family" do
other_category = Category.create!(
family: families(:empty),
name: "Other",
color: "#e99537",
lucide_icon: "tag"
)
result = @function.call(
"id" => @transaction.id,
"category_id" => other_category.id
)
assert_equal false, result[:success]
assert_equal "invalid_category", result[:error]
end
test "does not let read-only collaborators update transactions" do
transaction = transactions(:transfer_in)
function = Assistant::Function::UpdateTransaction.new(users(:family_member))
result = function.call("id" => transaction.id, "notes" => "Should not be saved")
assert_equal false, result[:success]
assert_equal "not_authorized", result[:error]
assert_nil transaction.reload.entry.notes
end
test "lets read-write collaborators update annotations but not names" do
transaction = transactions(:transfer_in)
transaction.entry.account.account_shares.find_by!(user: users(:family_member)).update!(permission: "read_write")
function = Assistant::Function::UpdateTransaction.new(users(:family_member))
annotation_result = function.call("id" => transaction.id, "notes" => "Shared note")
rename_result = function.call("id" => transaction.id, "name" => "Renamed transaction")
assert_equal true, annotation_result[:success]
assert_equal "Shared note", transaction.reload.entry.notes
assert_equal false, rename_result[:success]
assert_equal "not_authorized", rename_result[:error]
assert_equal "Payment received from checking account", transaction.reload.entry.name
end
end