少提交的东西
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
||||
"gorm.io/gorm/logger"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
accountService "github.com/break/junhong_cmp_fiber/internal/service/account"
|
||||
@@ -107,7 +107,7 @@ func setupTestEnv(t *testing.T) *testEnv {
|
||||
accService := accountService.New(accountStore, roleStore, accountRoleStore)
|
||||
|
||||
// 初始化 Handler
|
||||
accountHandler := handler.NewAccountHandler(accService)
|
||||
accountHandler := admin.NewAccountHandler(accService)
|
||||
|
||||
// 创建 Fiber App
|
||||
app := fiber.New(fiber.Config{
|
||||
@@ -191,7 +191,7 @@ func TestAccountAPI_Create(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("POST", "/api/v1/accounts", bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("POST", "/api/admin/accounts", bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -231,7 +231,7 @@ func TestAccountAPI_Create(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("POST", "/api/v1/accounts", bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("POST", "/api/admin/accounts", bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -253,7 +253,7 @@ func TestAccountAPI_Create(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("POST", "/api/v1/accounts", bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("POST", "/api/admin/accounts", bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -290,7 +290,7 @@ func TestAccountAPI_Get(t *testing.T) {
|
||||
createTestAccount(t, env.db, testAccount)
|
||||
|
||||
t.Run("成功获取账号详情", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/accounts/%d", testAccount.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/accounts/%d", testAccount.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -302,7 +302,7 @@ func TestAccountAPI_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("账号不存在时返回错误", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts/99999", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts/99999", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -313,7 +313,7 @@ func TestAccountAPI_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("无效ID返回错误", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts/invalid", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts/invalid", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -354,7 +354,7 @@ func TestAccountAPI_Update(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("PUT", fmt.Sprintf("/api/v1/accounts/%d", testAccount.ID), bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("PUT", fmt.Sprintf("/api/admin/accounts/%d", testAccount.ID), bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -392,7 +392,7 @@ func TestAccountAPI_Delete(t *testing.T) {
|
||||
}
|
||||
createTestAccount(t, env.db, testAccount)
|
||||
|
||||
req := httptest.NewRequest("DELETE", fmt.Sprintf("/api/v1/accounts/%d", testAccount.ID), nil)
|
||||
req := httptest.NewRequest("DELETE", fmt.Sprintf("/api/admin/accounts/%d", testAccount.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -431,7 +431,7 @@ func TestAccountAPI_List(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("成功获取账号列表", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts?page=1&page_size=10", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts?page=1&page_size=10", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -443,7 +443,7 @@ func TestAccountAPI_List(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("分页功能正常", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts?page=1&page_size=2", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts?page=1&page_size=2", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -487,7 +487,7 @@ func TestAccountAPI_AssignRoles(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("POST", fmt.Sprintf("/api/v1/accounts/%d/roles", testAccount.ID), bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("POST", fmt.Sprintf("/api/admin/accounts/%d/roles", testAccount.ID), bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -542,7 +542,7 @@ func TestAccountAPI_GetRoles(t *testing.T) {
|
||||
env.db.Create(accountRole)
|
||||
|
||||
t.Run("成功获取账号角色", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/accounts/%d/roles", testAccount.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/accounts/%d/roles", testAccount.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -595,7 +595,7 @@ func TestAccountAPI_RemoveRole(t *testing.T) {
|
||||
env.db.Create(accountRole)
|
||||
|
||||
t.Run("成功移除角色", func(t *testing.T) {
|
||||
req := httptest.NewRequest("DELETE", fmt.Sprintf("/api/v1/accounts/%d/roles/%d", testAccount.ID, testRole.ID), nil)
|
||||
req := httptest.NewRequest("DELETE", fmt.Sprintf("/api/admin/accounts/%d/roles/%d", testAccount.ID, testRole.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"gorm.io/gorm/logger"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
accountService "github.com/break/junhong_cmp_fiber/internal/service/account"
|
||||
@@ -108,9 +108,9 @@ func setupRegressionTestEnv(t *testing.T) *regressionTestEnv {
|
||||
permSvc := permissionService.New(permStore)
|
||||
|
||||
// 初始化所有 Handler
|
||||
accountHandler := handler.NewAccountHandler(accService)
|
||||
roleHandler := handler.NewRoleHandler(roleSvc)
|
||||
permHandler := handler.NewPermissionHandler(permSvc)
|
||||
accountHandler := admin.NewAccountHandler(accService)
|
||||
roleHandler := admin.NewRoleHandler(roleSvc)
|
||||
permHandler := admin.NewPermissionHandler(permSvc)
|
||||
|
||||
// 创建 Fiber App
|
||||
app := fiber.New(fiber.Config{
|
||||
@@ -168,17 +168,17 @@ func TestAPIRegression_AllEndpointsAccessible(t *testing.T) {
|
||||
{"GET", "/health/ready", "Readiness check"},
|
||||
|
||||
// Account endpoints
|
||||
{"GET", "/api/v1/accounts", "List accounts"},
|
||||
{"GET", "/api/v1/accounts/1", "Get account"},
|
||||
{"GET", "/api/admin/accounts", "List accounts"},
|
||||
{"GET", "/api/admin/accounts/1", "Get account"},
|
||||
|
||||
// Role endpoints
|
||||
{"GET", "/api/v1/roles", "List roles"},
|
||||
{"GET", "/api/v1/roles/1", "Get role"},
|
||||
{"GET", "/api/admin/roles", "List roles"},
|
||||
{"GET", "/api/admin/roles/1", "Get role"},
|
||||
|
||||
// Permission endpoints
|
||||
{"GET", "/api/v1/permissions", "List permissions"},
|
||||
{"GET", "/api/v1/permissions/1", "Get permission"},
|
||||
{"GET", "/api/v1/permissions/tree", "Get permission tree"},
|
||||
{"GET", "/api/admin/permissions", "List permissions"},
|
||||
{"GET", "/api/admin/permissions/1", "Get permission"},
|
||||
{"GET", "/api/admin/permissions/tree", "Get permission tree"},
|
||||
}
|
||||
|
||||
for _, ep := range endpoints {
|
||||
@@ -214,13 +214,13 @@ func TestAPIRegression_RouteModularization(t *testing.T) {
|
||||
env.db.Create(account)
|
||||
|
||||
// 测试获取账号
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/accounts/%d", account.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/accounts/%d", account.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
// 测试获取角色列表
|
||||
req = httptest.NewRequest("GET", fmt.Sprintf("/api/v1/accounts/%d/roles", account.ID), nil)
|
||||
req = httptest.NewRequest("GET", fmt.Sprintf("/api/admin/accounts/%d/roles", account.ID), nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -236,13 +236,13 @@ func TestAPIRegression_RouteModularization(t *testing.T) {
|
||||
env.db.Create(role)
|
||||
|
||||
// 测试获取角色
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/roles/%d", role.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/roles/%d", role.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
// 测试获取权限列表
|
||||
req = httptest.NewRequest("GET", fmt.Sprintf("/api/v1/roles/%d/permissions", role.ID), nil)
|
||||
req = httptest.NewRequest("GET", fmt.Sprintf("/api/admin/roles/%d/permissions", role.ID), nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -259,13 +259,13 @@ func TestAPIRegression_RouteModularization(t *testing.T) {
|
||||
env.db.Create(perm)
|
||||
|
||||
// 测试获取权限
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/permissions/%d", perm.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/permissions/%d", perm.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
// 测试获取权限树
|
||||
req = httptest.NewRequest("GET", "/api/v1/permissions/tree", nil)
|
||||
req = httptest.NewRequest("GET", "/api/admin/permissions/tree", nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -280,20 +280,20 @@ func TestAPIRegression_ErrorHandling(t *testing.T) {
|
||||
|
||||
t.Run("资源不存在返回正确错误码", func(t *testing.T) {
|
||||
// 账号不存在
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts/99999", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts/99999", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
// 应该返回业务错误,不是 404
|
||||
assert.NotEqual(t, fiber.StatusNotFound, resp.StatusCode)
|
||||
|
||||
// 角色不存在
|
||||
req = httptest.NewRequest("GET", "/api/v1/roles/99999", nil)
|
||||
req = httptest.NewRequest("GET", "/api/admin/roles/99999", nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, fiber.StatusNotFound, resp.StatusCode)
|
||||
|
||||
// 权限不存在
|
||||
req = httptest.NewRequest("GET", "/api/v1/permissions/99999", nil)
|
||||
req = httptest.NewRequest("GET", "/api/admin/permissions/99999", nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, fiber.StatusNotFound, resp.StatusCode)
|
||||
@@ -301,7 +301,7 @@ func TestAPIRegression_ErrorHandling(t *testing.T) {
|
||||
|
||||
t.Run("无效参数返回正确错误码", func(t *testing.T) {
|
||||
// 无效账号 ID
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts/invalid", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts/invalid", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, fiber.StatusInternalServerError, resp.StatusCode)
|
||||
@@ -328,20 +328,20 @@ func TestAPIRegression_Pagination(t *testing.T) {
|
||||
|
||||
t.Run("分页参数正常工作", func(t *testing.T) {
|
||||
// 第一页
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts?page=1&page_size=10", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts?page=1&page_size=10", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
// 第二页
|
||||
req = httptest.NewRequest("GET", "/api/v1/accounts?page=2&page_size=10", nil)
|
||||
req = httptest.NewRequest("GET", "/api/admin/accounts?page=2&page_size=10", nil)
|
||||
resp, err = env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("默认分页参数工作", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -355,7 +355,7 @@ func TestAPIRegression_ResponseFormat(t *testing.T) {
|
||||
defer env.redisCleanup()
|
||||
|
||||
t.Run("成功响应包含正确字段", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/accounts", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/accounts", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -382,9 +382,9 @@ func TestAPIRegression_ServicesIntegration(t *testing.T) {
|
||||
// 验证所有模块路由都已注册
|
||||
endpoints := []string{
|
||||
"/health",
|
||||
"/api/v1/accounts",
|
||||
"/api/v1/roles",
|
||||
"/api/v1/permissions",
|
||||
"/api/admin/accounts",
|
||||
"/api/admin/roles",
|
||||
"/api/admin/permissions",
|
||||
}
|
||||
|
||||
for _, ep := range endpoints {
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"gorm.io/gorm/logger"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
permissionService "github.com/break/junhong_cmp_fiber/internal/service/permission"
|
||||
@@ -81,7 +81,7 @@ func setupPermTestEnv(t *testing.T) *permTestEnv {
|
||||
permSvc := permissionService.New(permStore)
|
||||
|
||||
// 初始化 Handler
|
||||
permHandler := handler.NewPermissionHandler(permSvc)
|
||||
permHandler := admin.NewPermissionHandler(permSvc)
|
||||
|
||||
// 创建 Fiber App
|
||||
app := fiber.New(fiber.Config{
|
||||
@@ -130,7 +130,7 @@ func TestPermissionAPI_Create(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("POST", "/api/v1/permissions", bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("POST", "/api/admin/permissions", bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -166,7 +166,7 @@ func TestPermissionAPI_Create(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("POST", "/api/v1/permissions", bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("POST", "/api/admin/permissions", bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -197,7 +197,7 @@ func TestPermissionAPI_Create(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("POST", "/api/v1/permissions", bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("POST", "/api/admin/permissions", bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -235,7 +235,7 @@ func TestPermissionAPI_Get(t *testing.T) {
|
||||
env.db.Create(testPerm)
|
||||
|
||||
t.Run("成功获取权限详情", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/permissions/%d", testPerm.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/permissions/%d", testPerm.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -247,7 +247,7 @@ func TestPermissionAPI_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("权限不存在时返回错误", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/permissions/99999", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/permissions/99999", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -287,7 +287,7 @@ func TestPermissionAPI_Update(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("PUT", fmt.Sprintf("/api/v1/permissions/%d", testPerm.ID), bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("PUT", fmt.Sprintf("/api/admin/permissions/%d", testPerm.ID), bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -324,7 +324,7 @@ func TestPermissionAPI_Delete(t *testing.T) {
|
||||
}
|
||||
env.db.Create(testPerm)
|
||||
|
||||
req := httptest.NewRequest("DELETE", fmt.Sprintf("/api/v1/permissions/%d", testPerm.ID), nil)
|
||||
req := httptest.NewRequest("DELETE", fmt.Sprintf("/api/admin/permissions/%d", testPerm.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -362,7 +362,7 @@ func TestPermissionAPI_List(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("成功获取权限列表", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/permissions?page=1&page_size=10", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/permissions?page=1&page_size=10", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -374,7 +374,7 @@ func TestPermissionAPI_List(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("按类型过滤权限", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/permissions?perm_type=%d", constants.PermissionTypeMenu), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/permissions?perm_type=%d", constants.PermissionTypeMenu), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -425,7 +425,7 @@ func TestPermissionAPI_GetTree(t *testing.T) {
|
||||
env.db.Create(grandchildPerm)
|
||||
|
||||
t.Run("成功获取权限树", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/permissions/tree", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/permissions/tree", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"gorm.io/gorm/logger"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
roleService "github.com/break/junhong_cmp_fiber/internal/service/role"
|
||||
@@ -107,7 +107,7 @@ func setupRoleTestEnv(t *testing.T) *roleTestEnv {
|
||||
roleSvc := roleService.New(roleStore, permissionStore, rolePermissionStore)
|
||||
|
||||
// 初始化 Handler
|
||||
roleHandler := handler.NewRoleHandler(roleSvc)
|
||||
roleHandler := admin.NewRoleHandler(roleSvc)
|
||||
|
||||
// 创建 Fiber App
|
||||
app := fiber.New(fiber.Config{
|
||||
@@ -171,7 +171,7 @@ func TestRoleAPI_Create(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("POST", "/api/v1/roles", bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("POST", "/api/admin/roles", bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -195,7 +195,7 @@ func TestRoleAPI_Create(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("POST", "/api/v1/roles", bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("POST", "/api/admin/roles", bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -230,7 +230,7 @@ func TestRoleAPI_Get(t *testing.T) {
|
||||
env.db.Create(testRole)
|
||||
|
||||
t.Run("成功获取角色详情", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/roles/%d", testRole.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/roles/%d", testRole.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -242,7 +242,7 @@ func TestRoleAPI_Get(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("角色不存在时返回错误", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/roles/99999", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/roles/99999", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -281,7 +281,7 @@ func TestRoleAPI_Update(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("PUT", fmt.Sprintf("/api/v1/roles/%d", testRole.ID), bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("PUT", fmt.Sprintf("/api/admin/roles/%d", testRole.ID), bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -317,7 +317,7 @@ func TestRoleAPI_Delete(t *testing.T) {
|
||||
}
|
||||
env.db.Create(testRole)
|
||||
|
||||
req := httptest.NewRequest("DELETE", fmt.Sprintf("/api/v1/roles/%d", testRole.ID), nil)
|
||||
req := httptest.NewRequest("DELETE", fmt.Sprintf("/api/admin/roles/%d", testRole.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -354,7 +354,7 @@ func TestRoleAPI_List(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("成功获取角色列表", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/v1/roles?page=1&page_size=10", nil)
|
||||
req := httptest.NewRequest("GET", "/api/admin/roles?page=1&page_size=10", nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -402,7 +402,7 @@ func TestRoleAPI_AssignPermissions(t *testing.T) {
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
req := httptest.NewRequest("POST", fmt.Sprintf("/api/v1/roles/%d/permissions", testRole.ID), bytes.NewReader(jsonBody))
|
||||
req := httptest.NewRequest("POST", fmt.Sprintf("/api/admin/roles/%d/permissions", testRole.ID), bytes.NewReader(jsonBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := env.app.Test(req)
|
||||
@@ -454,7 +454,7 @@ func TestRoleAPI_GetPermissions(t *testing.T) {
|
||||
env.db.Create(rolePerm)
|
||||
|
||||
t.Run("成功获取角色权限", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/v1/roles/%d/permissions", testRole.ID), nil)
|
||||
req := httptest.NewRequest("GET", fmt.Sprintf("/api/admin/roles/%d/permissions", testRole.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
@@ -504,7 +504,7 @@ func TestRoleAPI_RemovePermission(t *testing.T) {
|
||||
env.db.Create(rolePerm)
|
||||
|
||||
t.Run("成功移除权限", func(t *testing.T) {
|
||||
req := httptest.NewRequest("DELETE", fmt.Sprintf("/api/v1/roles/%d/permissions/%d", testRole.ID, testPerm.ID), nil)
|
||||
req := httptest.NewRequest("DELETE", fmt.Sprintf("/api/admin/roles/%d/permissions/%d", testRole.ID, testPerm.ID), nil)
|
||||
resp, err := env.app.Test(req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
|
||||
|
||||
Reference in New Issue
Block a user