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

Function TestCreateAccount

account_test.go:34–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32)
33
34func TestCreateAccount(t *testing.T) {
35 datasource, mock, err := newTestDataSource()
36 assert.NoError(t, err)
37
38 d, err := NewLedgerForge(datasource)
39 if err != nil {
40 return
41 }
42 assert.NoError(t, err)
43
44 account := model.Account{
45 Name: "Test Account",
46 Number: "123456789",
47 BankName: "Test Bank",
48 Currency: "NGN",
49 LedgerID: gofakeit.UUID(),
50 IdentityID: "identity_123",
51 BalanceID: gofakeit.UUID(),
52 MetaData: map[string]interface{}{"key": "value"},
53 }
54 metaDataJSON, _ := json.Marshal(account.MetaData)
55
56 rows := sqlmock.NewRows([]string{"balance_id", "indicator", "currency", "currency_multiplier", "ledger_id", "balance", "credit_balance", "debit_balance", "inflight_balance", "inflight_credit_balance", "inflight_debit_balance", "created_at", "version", "track_fund_lineage", "allocation_strategy", "identity_id"}).
57 AddRow(account.BalanceID, "", "NGN", 1, account.LedgerID, 100, 50, 50, 0, 0, 0, time.Now(), 0, false, "FIFO", "")
58
59 mock.ExpectQuery("SELECT .* FROM ledgerforge.balances WHERE balance_id =").
60 WithArgs(account.BalanceID).
61 WillReturnRows(rows)
62
63 mock.ExpectExec("INSERT INTO ledgerforge.accounts").
64 WithArgs(sqlmock.AnyArg(), account.Name, account.Number, account.BankName, account.Currency, account.LedgerID, account.IdentityID, account.BalanceID, sqlmock.AnyArg(), metaDataJSON).
65 WillReturnResult(sqlmock.NewResult(1, 1))
66
67 config.MockConfig(&config.Configuration{Server: config.ServerConfig{SecretKey: "some-secret"}, AccountNumberGeneration: config.AccountNumberGenerationConfig{HttpService: config.AccountGenerationHttpService{}}})
68
69 result, err := d.CreateAccount(account)
70 assert.NoError(t, err)
71 assert.Equal(t, account.Name, result.Name)
72 assert.Equal(t, account.Number, result.Number)
73 assert.WithinDuration(t, time.Now(), result.CreatedAt, time.Second)
74
75 if err := mock.ExpectationsWereMet(); err != nil {
76 t.Errorf("there were unfulfilled expectations: %s", err)
77 }
78}
79
80func TestCreateAccountWithExternalGenerator(t *testing.T) {
81 // Initialize the mock HTTP responder

Callers

nothing calls this directly

Calls 4

CreateAccountMethod · 0.95
MockConfigFunction · 0.92
newTestDataSourceFunction · 0.85
NewLedgerForgeFunction · 0.85

Tested by

no test coverage detected