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

Function TestGetBalance

api/balance_api_test.go:116–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

114}
115
116func TestGetBalance(t *testing.T) {
117 router, b, _ := setupRouter(t)
118 newLedger, err := b.CreateLedger(model.Ledger{Name: gofakeit.Name()})
119 if err != nil {
120 return
121 }
122 newBalance, err := b.CreateBalance(context.Background(), model.Balance{LedgerID: newLedger.LedgerID, Currency: gofakeit.CurrencyShort()})
123 if err != nil {
124 return
125 }
126 var response model.Balance
127 testRequest := TestRequest{
128 Payload: nil,
129 Response: &response,
130 Method: "GET",
131 Route: fmt.Sprintf("/balances/%s", newBalance.BalanceID),
132 Auth: "",
133 Router: router,
134 }
135 resp, err := SetUpTestRequest(testRequest)
136 if err != nil {
137 t.Error(err)
138 return
139 }
140 assert.Equal(t, http.StatusOK, resp.Code)
141 assert.Equal(t, response.BalanceID, newBalance.BalanceID)
142 assert.Equal(t, response.LedgerID, newLedger.LedgerID)
143 assert.Equal(t, response.Currency, newBalance.Currency)
144 assert.Equal(t, big.NewInt(0), newBalance.Balance)
145 assert.Equal(t, big.NewInt(0), newBalance.DebitBalance)
146 assert.Equal(t, big.NewInt(0), newBalance.CreditBalance)
147 assert.Equal(t, big.NewInt(0), newBalance.InflightBalance)
148 assert.Equal(t, big.NewInt(0), newBalance.InflightCreditBalance)
149 assert.Equal(t, big.NewInt(0), newBalance.InflightDebitBalance)
150 assert.Equal(t, int64(0), newBalance.Version)
151}
152
153func TestGetBalances(t *testing.T) {
154 router, b, err := setupRouter(t)

Callers

nothing calls this directly

Calls 5

setupRouterFunction · 0.85
SetUpTestRequestFunction · 0.85
CreateLedgerMethod · 0.65
CreateBalanceMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected