| 12345678910111213141516171819202122232425262728293031323334353637 |
- package product
- import (
- "context"
- "testing"
- "time"
- deptModel "perms-system-server/internal/model/dept"
- "perms-system-server/internal/svc"
- "perms-system-server/internal/testutil"
- "github.com/stretchr/testify/require"
- )
- // seedAdminDept 插入一个启用状态的部门并登记 cleanup,返回 deptId。
- // 用于 L-R10-1 要求的 CreateProduct.AdminDeptId 入参,避免每个测试重复模板代码。
- func seedAdminDept(t *testing.T, ctx context.Context, svcCtx *svc.ServiceContext) int64 {
- t.Helper()
- conn := testutil.GetTestSqlConn()
- now := time.Now().Unix()
- res, err := svcCtx.SysDeptModel.Insert(ctx, &deptModel.SysDept{
- ParentId: 0,
- Name: "p_dept_" + testutil.UniqueId(),
- Path: "/",
- Sort: 0,
- DeptType: "NORMAL",
- Status: 1,
- CreateTime: now,
- UpdateTime: now,
- })
- require.NoError(t, err)
- id, _ := res.LastInsertId()
- t.Cleanup(func() {
- testutil.CleanTable(ctx, conn, "`sys_dept`", id)
- })
- return id
- }
|