(t *testing.T)
| 305 | } |
| 306 | |
| 307 | func TestGetUserEmailByIdWithTransaction(t *testing.T) { |
| 308 | db, err := sqlx.Open("sqlite3", ":memory:") |
| 309 | if err != nil { |
| 310 | t.Fatalf("Failed to open db: %v", err) |
| 311 | } |
| 312 | defer db.Close() |
| 313 | |
| 314 | _, err = db.Exec( |
| 315 | "CREATE TABLE user_account (id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT, name TEXT, reference_id BLOB, permission INTEGER)", |
| 316 | ) |
| 317 | if err != nil { |
| 318 | t.Fatalf("Failed to create table: %v", err) |
| 319 | } |
| 320 | |
| 321 | refId, _ := uuid.NewV7() |
| 322 | _, err = db.Exec( |
| 323 | "INSERT INTO user_account (email, name, reference_id, permission) VALUES (?, ?, ?, ?)", |
| 324 | "testuser@example.com", "Test User", refId[:], 0, |
| 325 | ) |
| 326 | if err != nil { |
| 327 | t.Fatalf("Failed to insert test user: %v", err) |
| 328 | } |
| 329 | |
| 330 | // Create a minimal DbResource with just db access |
| 331 | dbResource := &resource.DbResource{} |
| 332 | |
| 333 | tx, err := db.Beginx() |
| 334 | if err != nil { |
| 335 | t.Fatalf("Failed to begin transaction: %v", err) |
| 336 | } |
| 337 | defer tx.Rollback() |
| 338 | |
| 339 | email := dbResource.GetUserEmailByIdWithTransaction(1, tx) |
| 340 | |
| 341 | if email != "testuser@example.com" { |
| 342 | t.Errorf("Expected testuser@example.com, got: %s", email) |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | func TestGetUserEmailByIdWithTransaction_NonExistentUser(t *testing.T) { |
| 347 | db, err := sqlx.Open("sqlite3", ":memory:") |
nothing calls this directly
no test coverage detected