(t *testing.T)
| 213 | } |
| 214 | |
| 215 | func TestRecordMatches_Success(t *testing.T) { |
| 216 | db, mock, err := sqlmock.New() |
| 217 | assert.NoError(t, err) |
| 218 | defer func() { _ = db.Close() }() |
| 219 | |
| 220 | ds := Datasource{Conn: db} |
| 221 | ctx := context.TODO() |
| 222 | |
| 223 | matches := []model.Match{ |
| 224 | { |
| 225 | ExternalTransactionID: "ext1", |
| 226 | InternalTransactionID: "int1", |
| 227 | ReconciliationID: "rec123", |
| 228 | Amount: 1000, |
| 229 | Date: time.Now(), |
| 230 | }, |
| 231 | { |
| 232 | ExternalTransactionID: "ext2", |
| 233 | InternalTransactionID: "int2", |
| 234 | ReconciliationID: "rec123", |
| 235 | Amount: 2000, |
| 236 | Date: time.Now(), |
| 237 | }, |
| 238 | } |
| 239 | |
| 240 | mock.ExpectBegin() |
| 241 | |
| 242 | for _, match := range matches { |
| 243 | mock.ExpectExec("INSERT INTO ledgerforge.matches"). |
| 244 | WithArgs(match.ExternalTransactionID, match.InternalTransactionID, match.ReconciliationID, match.Amount, match.Date). |
| 245 | WillReturnResult(sqlmock.NewResult(1, 1)) |
| 246 | } |
| 247 | |
| 248 | mock.ExpectCommit() |
| 249 | |
| 250 | err = ds.RecordMatches(ctx, "rec123", matches) |
| 251 | assert.NoError(t, err) |
| 252 | } |
| 253 | |
| 254 | func TestRecordMatches_Fail(t *testing.T) { |
| 255 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected