MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestUpdateTransactionMetadata

Function TestUpdateTransactionMetadata

database/metadata_test.go:33–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestUpdateTransactionMetadata(t *testing.T) {
34 db, mock, err := sqlmock.New()
35 assert.NoError(t, err)
36 defer func() { _ = db.Close() }()
37
38 ds := Datasource{Conn: db}
39 ctx := context.Background()
40 metadata := map[string]interface{}{
41 "status": "completed",
42 "ref": "TX123",
43 }
44
45 metadataJSON, _ := json.Marshal(metadata)
46
47 // Verify the SQL uses jsonb merge operator and updates both direct and parent matches
48 mock.ExpectExec(`UPDATE ledgerforge\.transactions SET meta_data = meta_data \|\| \$1::jsonb WHERE transaction_id = \$2 OR parent_transaction = \$2`).
49 WithArgs(metadataJSON, "txn_123").
50 WillReturnResult(sqlmock.NewResult(1, 2)) // 2 rows affected (1 direct + 1 parent match)
51
52 err = ds.UpdateTransactionMetadata(ctx, "txn_123", metadata)
53 assert.NoError(t, err)
54 assert.NoError(t, mock.ExpectationsWereMet())
55}
56
57func TestUpdateBalanceMetadata(t *testing.T) {
58 db, mock, err := sqlmock.New()

Callers

nothing calls this directly

Calls 2

CloseMethod · 0.45

Tested by

no test coverage detected