fix(backend): JWT config mapstructure tag 修复 + 模型从 hotel 重构为 shop
- 修复 JWTConfig 缺少 mapstructure tag 导致 access_expire_min 解析为 0, token 签发即过期,所有 API 请求返回 401 - 全部 config struct 补齐 mapstructure tag(secret/dsn/hmac_secret 等) - 模型层从 hotel/HotelID 统一重命名为 shop/ShopID - 删除旧 migrations(001-004),新增 001_init 综合迁移文件 - 更新 schema.sql、testutil、handler/service/model 相关引用 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
func TestAuthService_Login_Success(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
hotel := testutil.CreateTestHotel(db, "HOTEL001")
|
||||
testutil.CreateTestUser(db, hotel.ID, "admin", "password123", "admin")
|
||||
shop := testutil.CreateTestShop(db, "HOTEL001")
|
||||
testutil.CreateTestUser(db, shop.ID, "admin", "password123", "admin")
|
||||
|
||||
svc := NewAuthService(db)
|
||||
pair, user, err := svc.Login("HOTEL001", "admin", "password123")
|
||||
@@ -27,8 +27,8 @@ func TestAuthService_Login_Success(t *testing.T) {
|
||||
|
||||
func TestAuthService_Login_WrongPassword(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
hotel := testutil.CreateTestHotel(db, "HOTEL002")
|
||||
testutil.CreateTestUser(db, hotel.ID, "admin", "password123", "admin")
|
||||
shop := testutil.CreateTestShop(db, "HOTEL002")
|
||||
testutil.CreateTestUser(db, shop.ID, "admin", "password123", "admin")
|
||||
|
||||
svc := NewAuthService(db)
|
||||
pair, user, err := svc.Login("HOTEL002", "admin", "wrongpassword")
|
||||
@@ -41,7 +41,7 @@ func TestAuthService_Login_WrongPassword(t *testing.T) {
|
||||
|
||||
func TestAuthService_Login_WrongHotel(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
testutil.CreateTestHotel(db, "HOTEL003")
|
||||
testutil.CreateTestShop(db, "HOTEL003")
|
||||
|
||||
svc := NewAuthService(db)
|
||||
pair, user, err := svc.Login("NONEXISTENT", "admin", "password123")
|
||||
@@ -54,8 +54,8 @@ func TestAuthService_Login_WrongHotel(t *testing.T) {
|
||||
|
||||
func TestAuthService_Login_DisabledUser(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
hotel := testutil.CreateTestHotel(db, "HOTEL004")
|
||||
user := testutil.CreateTestUser(db, hotel.ID, "disabled", "password123", "operator")
|
||||
shop := testutil.CreateTestShop(db, "HOTEL004")
|
||||
user := testutil.CreateTestUser(db, shop.ID, "disabled", "password123", "operator")
|
||||
// 禁用用户
|
||||
db.Model(user).Update("is_active", false)
|
||||
|
||||
@@ -70,8 +70,8 @@ func TestAuthService_Login_DisabledUser(t *testing.T) {
|
||||
|
||||
func TestAuthService_Login_WrongUsername(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
hotel := testutil.CreateTestHotel(db, "HOTEL005")
|
||||
testutil.CreateTestUser(db, hotel.ID, "admin", "password123", "admin")
|
||||
shop := testutil.CreateTestShop(db, "HOTEL005")
|
||||
testutil.CreateTestUser(db, shop.ID, "admin", "password123", "admin")
|
||||
|
||||
svc := NewAuthService(db)
|
||||
pair, user, err := svc.Login("HOTEL005", "nonexistent", "password123")
|
||||
@@ -84,8 +84,8 @@ func TestAuthService_Login_WrongUsername(t *testing.T) {
|
||||
|
||||
func TestAuthService_RefreshTokens(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
hotel := testutil.CreateTestHotel(db, "HOTEL006")
|
||||
testutil.CreateTestUser(db, hotel.ID, "admin", "password123", "admin")
|
||||
shop := testutil.CreateTestShop(db, "HOTEL006")
|
||||
testutil.CreateTestUser(db, shop.ID, "admin", "password123", "admin")
|
||||
|
||||
svc := NewAuthService(db)
|
||||
pair, _, err := svc.Login("HOTEL006", "admin", "password123")
|
||||
|
||||
Reference in New Issue
Block a user