(t *testing.T)
| 252 | } |
| 253 | |
| 254 | func TestRecordMatches_Fail(t *testing.T) { |
| 255 | db, mock, err := sqlmock.New() |
| 256 | assert.NoError(t, err) |
| 257 | defer func() { _ = db.Close() }() |
| 258 | |
| 259 | ds := Datasource{Conn: db} |
| 260 | ctx := context.TODO() |
| 261 | |
| 262 | matches := []model.Match{ |
| 263 | { |
| 264 | ExternalTransactionID: "ext1", |
| 265 | InternalTransactionID: "int1", |
| 266 | ReconciliationID: "rec123", |
| 267 | Amount: 1000, |
| 268 | Date: time.Now(), |
| 269 | }, |
| 270 | } |
| 271 | |
| 272 | mock.ExpectBegin() |
| 273 | mock.ExpectExec("INSERT INTO ledgerforge.matches"). |
| 274 | WithArgs(matches[0].ExternalTransactionID, matches[0].InternalTransactionID, matches[0].ReconciliationID, matches[0].Amount, matches[0].Date). |
| 275 | WillReturnError(fmt.Errorf("failed to insert match")) |
| 276 | mock.ExpectRollback() |
| 277 | |
| 278 | err = ds.RecordMatches(ctx, "rec123", matches) |
| 279 | assert.Error(t, err) |
| 280 | assert.Equal(t, apierror.ErrInternalServer, err.(apierror.APIError).Code) |
| 281 | } |
| 282 | |
| 283 | func TestGetReconciliationsByUploadID_Success(t *testing.T) { |
| 284 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected