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

Function TestGetTransaction_Mock

transaction_test.go:6090–6138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6088}
6089
6090func TestGetTransaction_Mock(t *testing.T) {
6091 cnf := &config.Configuration{
6092 Redis: config.RedisConfig{Dns: "localhost:6379"},
6093 Queue: config.QueueConfig{
6094 WebhookQueue: "webhook_queue",
6095 TransactionQueue: "transaction_queue",
6096 NumberOfQueues: 1,
6097 },
6098 }
6099 config.ConfigStore.Store(cnf)
6100
6101 t.Run("Success", func(t *testing.T) {
6102 mockDS := new(mocks.MockDataSource)
6103
6104 txnID := "txn_123"
6105 expectedTxn := &model.Transaction{
6106 TransactionID: txnID,
6107 Amount: 100.0,
6108 Reference: "ref_123",
6109 Status: "APPLIED",
6110 PreciseAmount: big.NewInt(10000),
6111 }
6112
6113 mockDS.On("GetTransaction", mock.Anything, txnID).Return(expectedTxn, nil)
6114
6115 ledgerforge := &LedgerForge{datasource: mockDS, config: cnf}
6116 result, err := ledgerforge.GetTransaction(context.Background(), txnID)
6117
6118 assert.NoError(t, err)
6119 assert.NotNil(t, result)
6120 assert.Equal(t, txnID, result.TransactionID)
6121 assert.Equal(t, "APPLIED", result.Status)
6122 mockDS.AssertExpectations(t)
6123 })
6124
6125 t.Run("Not Found", func(t *testing.T) {
6126 mockDS := new(mocks.MockDataSource)
6127
6128 txnID := "txn_nonexistent"
6129 mockDS.On("GetTransaction", mock.Anything, txnID).Return((*model.Transaction)(nil), fmt.Errorf("not found"))
6130
6131 ledgerforge := &LedgerForge{datasource: mockDS, config: cnf}
6132 result, err := ledgerforge.GetTransaction(context.Background(), txnID)
6133
6134 assert.Error(t, err)
6135 assert.Nil(t, result)
6136 mockDS.AssertExpectations(t)
6137 })
6138}
6139
6140func TestGetAllTransactions_Mock(t *testing.T) {
6141 cnf := &config.Configuration{

Callers

nothing calls this directly

Calls 2

GetTransactionMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected