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

Function TestOneToManyReconciliationNoMatches

reconciliation_test.go:141–195  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

139}
140
141func TestOneToManyReconciliationNoMatches(t *testing.T) {
142 cnf := &config.Configuration{
143 Redis: config.RedisConfig{
144 Dns: "localhost:6379",
145 },
146 Transaction: config.TransactionConfig{
147 BatchSize: 100000,
148 MaxWorkers: 1,
149 },
150 Queue: config.QueueConfig{
151 WebhookQueue: "webhook_queue",
152 NumberOfQueues: 1,
153 },
154 }
155 config.ConfigStore.Store(cnf)
156 mockDS := new(mocks.MockDataSource)
157 ledgerforge := &LedgerForge{datasource: mockDS}
158
159 ctx := context.Background()
160 externalTxns := []*model.Transaction{
161 {TransactionID: "ext1", Amount: 300, CreatedAt: time.Now(), Description: "External 1 Internal 1 2 3", Reference: "REF1", Currency: "USD"},
162 }
163 internalTxns := []*model.Transaction{
164 {TransactionID: "int1", Amount: 100, CreatedAt: time.Now().Add(-1 * time.Hour), Description: "Internal 1", Reference: "REF1-A", Currency: "USD"},
165 {TransactionID: "int2", Amount: 150, CreatedAt: time.Now(), Description: "Internal 2", Reference: "REF1-B", Currency: "USD"},
166 {TransactionID: "int3", Amount: 54, CreatedAt: time.Now().Add(1 * time.Hour), Description: "Internal 3", Reference: "REF1-C", Currency: "USD"},
167 }
168
169 groupedInternalTxns := map[string][]*model.Transaction{
170 "parent_transaction": internalTxns,
171 }
172
173 emptyGroup := map[string][]*model.Transaction{}
174
175 mockDS.On("GroupTransactions", mock.Anything, mock.Anything, 100000, int64(0)).Return(groupedInternalTxns, nil)
176 mockDS.On("GroupTransactions", mock.Anything, mock.Anything, 100000, int64(100000)).Return(emptyGroup, nil)
177
178 matchingRules := []model.MatchingRule{
179 {
180 RuleID: "parent_transaction",
181 Criteria: []model.MatchingCriteria{
182 {Field: "amount", Operator: "equals", AllowableDrift: 0.01}, // 1% drift allowed
183 {Field: "description", Operator: "contains"},
184 {Field: "reference", Operator: "contains"},
185 {Field: "currency", Operator: "equals"},
186 },
187 },
188 }
189
190 matches, unmatched := ledgerforge.oneToManyReconciliation(ctx, externalTxns, "parent_transaction", matchingRules, false)
191
192 assert.Equal(t, 0, len(matches), "Expected 3 matches")
193 assert.Equal(t, 1, len(unmatched), "Expected 0 unmatched transactions")
194 mockDS.AssertExpectations(t)
195}
196
197func TestManyToOneReconciliationUsesUploadID(t *testing.T) {
198 cnf := &config.Configuration{

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected