少提交的东西
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"
|
||||
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