(t *testing.T)
| 809 | } |
| 810 | |
| 811 | func TestGetBalancesByIDsLite_Success(t *testing.T) { |
| 812 | db, mock, err := sqlmock.New() |
| 813 | assert.NoError(t, err) |
| 814 | defer func() { _ = db.Close() }() |
| 815 | |
| 816 | ds := Datasource{Conn: db} |
| 817 | |
| 818 | query := ` |
| 819 | SELECT 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, COALESCE(allocation_strategy, 'FIFO') as allocation_strategy, COALESCE(identity_id, '') as identity_id |
| 820 | FROM ledgerforge.balances |
| 821 | WHERE balance_id = ANY($1) |
| 822 | ` |
| 823 | |
| 824 | mock.ExpectQuery(regexp.QuoteMeta(query)). |
| 825 | WithArgs(pq.Array([]string{"bln_123", "bln_456"})). |
| 826 | WillReturnRows(sqlmock.NewRows([]string{ |
| 827 | "balance_id", "indicator", "currency", "currency_multiplier", "ledger_id", |
| 828 | "balance", "credit_balance", "debit_balance", |
| 829 | "inflight_balance", "inflight_credit_balance", "inflight_debit_balance", |
| 830 | "created_at", "version", "track_fund_lineage", "allocation_strategy", "identity_id", |
| 831 | }).AddRow( |
| 832 | "bln_123", "ACC001", "USD", 100, "ldg_001", |
| 833 | "100000", "60000", "40000", |
| 834 | "5000", "3000", "2000", |
| 835 | time.Now(), 1, false, "FIFO", "", |
| 836 | ).AddRow( |
| 837 | "bln_456", "ACC002", "USD", 100, "ldg_001", |
| 838 | "200000", "120000", "80000", |
| 839 | "10000", "6000", "4000", |
| 840 | time.Now(), 2, true, "LIFO", "idt_001", |
| 841 | )) |
| 842 | |
| 843 | ctx := context.Background() |
| 844 | balances, err := ds.GetBalancesByIDsLite(ctx, []string{"bln_123", "bln_456"}) |
| 845 | assert.NoError(t, err) |
| 846 | assert.Len(t, balances, 2) |
| 847 | |
| 848 | // Verify first balance |
| 849 | assert.NotNil(t, balances["bln_123"]) |
| 850 | assert.Equal(t, "bln_123", balances["bln_123"].BalanceID) |
| 851 | assert.Equal(t, "ACC001", balances["bln_123"].Indicator) |
| 852 | assert.Equal(t, int64(100000), balances["bln_123"].Balance.Int64()) |
| 853 | |
| 854 | // Verify second balance |
| 855 | assert.NotNil(t, balances["bln_456"]) |
| 856 | assert.Equal(t, "bln_456", balances["bln_456"].BalanceID) |
| 857 | assert.Equal(t, "LIFO", balances["bln_456"].AllocationStrategy) |
| 858 | assert.True(t, balances["bln_456"].TrackFundLineage) |
| 859 | |
| 860 | err = mock.ExpectationsWereMet() |
| 861 | assert.NoError(t, err) |
| 862 | } |
| 863 | |
| 864 | func TestGetBalancesByIDsLite_EmptyInput(t *testing.T) { |
| 865 | db, _, err := sqlmock.New() |
nothing calls this directly
no test coverage detected