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

Function TestRecordTransaction

api/transaction_api_test.go:168–320  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

166}
167
168func TestRecordTransaction(t *testing.T) {
169 router, b, err := setupRouter(t)
170 if err != nil {
171 t.Fatalf("Failed to setup router: %v", err)
172 }
173
174 // Create ledger and balances for testing
175 newLedger, err := b.CreateLedger(model.Ledger{Name: gofakeit.Name()})
176 if err != nil {
177 t.Fatalf("Failed to create ledger: %v", err)
178 }
179
180 newSourceBalance, err := b.CreateBalance(context.Background(), model.Balance{LedgerID: newLedger.LedgerID, Currency: "NGN"})
181 if err != nil {
182 t.Fatalf("Failed to create source balance: %v", err)
183 }
184
185 newDestinationBalance, err := b.CreateBalance(context.Background(), model.Balance{LedgerID: newLedger.LedgerID, Currency: "NGN"})
186 if err != nil {
187 t.Fatalf("Failed to create destination balance: %v", err)
188 }
189
190 tests := []struct {
191 name string
192 payload model2.RecordTransaction
193 expectedCode int
194 wantErr bool
195 }{
196 {
197 name: "Valid Transaction",
198 payload: model2.RecordTransaction{
199 Amount: 922337203.6854,
200 Precision: 10000000000,
201 Reference: "ref_001adcfgf",
202 Description: "For fees",
203 Currency: "NGN",
204 Source: newSourceBalance.BalanceID,
205 Destination: newDestinationBalance.BalanceID,
206 },
207 expectedCode: http.StatusCreated,
208 wantErr: false,
209 },
210 {
211 name: "Valid Transaction With precision 100",
212 payload: model2.RecordTransaction{
213 Amount: 100.68,
214 Precision: 100,
215 Reference: "ref_001adcfgf",
216 Description: "For fees",
217 Currency: "NGN",
218 Source: newSourceBalance.BalanceID,
219 Destination: newDestinationBalance.BalanceID,
220 },
221 expectedCode: http.StatusCreated,
222 wantErr: false,
223 },
224 {
225 name: "Missing Amount",

Callers

nothing calls this directly

Calls 6

ToJsonReqFunction · 0.92
ApplyPrecisionFunction · 0.92
setupRouterFunction · 0.85
SetUpTestRequestFunction · 0.85
CreateLedgerMethod · 0.65
CreateBalanceMethod · 0.65

Tested by

no test coverage detected