(t *testing.T)
| 31 | } |
| 32 | |
| 33 | func 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 | |
| 57 | func TestUpdateBalanceMetadata(t *testing.T) { |
| 58 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected