package testdb

import (
	"testing"

	"github.com/user-management-system/internal/domain"
)

func TestOpen_WorksWithModernc(t *testing.T) {
	db := Open(t)

	// 迁移 user 表
	if err := db.AutoMigrate(&domain.User{}); err != nil {
		t.Fatalf("AutoMigrate 失败: %v", err)
	}

	// 插入一条记录
	user := &domain.User{Username: "testuser", Status: domain.UserStatusActive}
	if err := db.Create(user).Error; err != nil {
		t.Fatalf("Create 失败: %v", err)
	}
	if user.ID == 0 {
		t.Error("期望 ID > 0")
	}

	// 查询
	var found domain.User
	if err := db.First(&found, "username = ?", "testuser").Error; err != nil {
		t.Fatalf("查询失败: %v", err)
	}
	if found.Username != "testuser" {
		t.Errorf("期望 username=testuser, 实际 %s", found.Username)
	}
}
