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

Function TestCreateAccount_Success

database/account_test.go:15–45  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestCreateAccount_Success(t *testing.T) {
16 db, mock, err := sqlmock.New()
17 assert.NoError(t, err)
18 defer func() { _ = db.Close() }()
19
20 ds := Datasource{Conn: db}
21
22 account := model.Account{
23 Name: "Test Account",
24 Number: "1234567890",
25 BankName: "Test Bank",
26 Currency: "USD",
27 LedgerID: "ldg1",
28 IdentityID: "idt1",
29 BalanceID: "bal1",
30 MetaData: map[string]interface{}{
31 "key": "value",
32 },
33 }
34
35 metaDataJSON, err := json.Marshal(account.MetaData)
36 assert.NoError(t, err)
37
38 mock.ExpectExec("INSERT INTO ledgerforge.accounts").
39 WithArgs(sqlmock.AnyArg(), account.Name, account.Number, account.BankName, account.Currency, account.LedgerID, account.IdentityID, account.BalanceID, sqlmock.AnyArg(), metaDataJSON).
40 WillReturnResult(sqlmock.NewResult(1, 1))
41
42 createdAccount, err := ds.CreateAccount(account)
43 assert.NoError(t, err)
44 assert.NotEmpty(t, createdAccount.AccountID)
45}
46
47func TestGetAccountByID_Success(t *testing.T) {
48 db, mock, err := sqlmock.New()

Callers

nothing calls this directly

Calls 2

CreateAccountMethod · 0.95
CloseMethod · 0.45

Tested by

no test coverage detected