helper_test.go 973 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package product
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. deptModel "perms-system-server/internal/model/dept"
  7. "perms-system-server/internal/svc"
  8. "perms-system-server/internal/testutil"
  9. "github.com/stretchr/testify/require"
  10. )
  11. // seedAdminDept 插入一个启用状态的部门并登记 cleanup,返回 deptId。
  12. // 用于 L-R10-1 要求的 CreateProduct.AdminDeptId 入参,避免每个测试重复模板代码。
  13. func seedAdminDept(t *testing.T, ctx context.Context, svcCtx *svc.ServiceContext) int64 {
  14. t.Helper()
  15. conn := testutil.GetTestSqlConn()
  16. now := time.Now().Unix()
  17. res, err := svcCtx.SysDeptModel.Insert(ctx, &deptModel.SysDept{
  18. ParentId: 0,
  19. Name: "p_dept_" + testutil.UniqueId(),
  20. Path: "/",
  21. Sort: 0,
  22. DeptType: "NORMAL",
  23. Status: 1,
  24. CreateTime: now,
  25. UpdateTime: now,
  26. })
  27. require.NoError(t, err)
  28. id, _ := res.LastInsertId()
  29. t.Cleanup(func() {
  30. testutil.CleanTable(ctx, conn, "`sys_dept`", id)
  31. })
  32. return id
  33. }