add: 提交部分表设计
update: 1.所有model嵌入gorm公用model 2.所有model嵌入BaseModel
This commit is contained in:
@@ -28,8 +28,6 @@ func TestAccountModel_Create(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypeRoot,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
|
||||
err := store.Create(ctx, account)
|
||||
@@ -47,8 +45,6 @@ func TestAccountModel_Create(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, parent)
|
||||
require.NoError(t, err)
|
||||
@@ -61,8 +57,6 @@ func TestAccountModel_Create(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &parent.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err = store.Create(ctx, child)
|
||||
require.NoError(t, err)
|
||||
@@ -79,8 +73,6 @@ func TestAccountModel_Create(t *testing.T) {
|
||||
UserType: constants.UserTypePlatform,
|
||||
ShopID: &shopID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
|
||||
err := store.Create(ctx, account)
|
||||
@@ -105,8 +97,6 @@ func TestAccountModel_GetByID(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, account)
|
||||
require.NoError(t, err)
|
||||
@@ -140,8 +130,6 @@ func TestAccountModel_GetByUsername(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, account)
|
||||
require.NoError(t, err)
|
||||
@@ -173,8 +161,6 @@ func TestAccountModel_GetByPhone(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, account)
|
||||
require.NoError(t, err)
|
||||
@@ -206,8 +192,6 @@ func TestAccountModel_Update(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, account)
|
||||
require.NoError(t, err)
|
||||
@@ -242,8 +226,6 @@ func TestAccountModel_List(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, account)
|
||||
require.NoError(t, err)
|
||||
@@ -283,8 +265,6 @@ func TestAccountModel_UniqueConstraints(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, account)
|
||||
require.NoError(t, err)
|
||||
@@ -296,8 +276,6 @@ func TestAccountModel_UniqueConstraints(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, duplicate)
|
||||
assert.Error(t, err)
|
||||
@@ -310,8 +288,6 @@ func TestAccountModel_UniqueConstraints(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, duplicate)
|
||||
assert.Error(t, err)
|
||||
|
||||
@@ -29,8 +29,6 @@ func TestAccountSoftDelete(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, account)
|
||||
require.NoError(t, err)
|
||||
@@ -61,8 +59,6 @@ func TestAccountSoftDelete(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := store.Create(ctx, newAccount)
|
||||
require.NoError(t, err)
|
||||
@@ -84,8 +80,6 @@ func TestRoleSoftDelete(t *testing.T) {
|
||||
RoleDesc: "测试角色",
|
||||
RoleType: constants.RoleTypeSuper,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := roleStore.Create(ctx, role)
|
||||
require.NoError(t, err)
|
||||
@@ -123,8 +117,6 @@ func TestPermissionSoftDelete(t *testing.T) {
|
||||
PermCode: "test:permission",
|
||||
PermType: constants.PermissionTypeMenu,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := permissionStore.Create(ctx, permission)
|
||||
require.NoError(t, err)
|
||||
@@ -145,8 +137,6 @@ func TestPermissionSoftDelete(t *testing.T) {
|
||||
PermCode: "test:permission", // 重用已删除权限的 perm_code
|
||||
PermType: constants.PermissionTypeMenu,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := permissionStore.Create(ctx, newPermission)
|
||||
require.NoError(t, err)
|
||||
@@ -171,8 +161,6 @@ func TestAccountRoleSoftDelete(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := accountStore.Create(ctx, account)
|
||||
require.NoError(t, err)
|
||||
@@ -183,8 +171,6 @@ func TestAccountRoleSoftDelete(t *testing.T) {
|
||||
RoleDesc: "测试角色",
|
||||
RoleType: constants.RoleTypeSuper,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err = roleStore.Create(ctx, role)
|
||||
require.NoError(t, err)
|
||||
@@ -244,8 +230,6 @@ func TestRolePermissionSoftDelete(t *testing.T) {
|
||||
RoleDesc: "测试角色",
|
||||
RoleType: constants.RoleTypeSuper,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err := roleStore.Create(ctx, role)
|
||||
require.NoError(t, err)
|
||||
@@ -256,19 +240,15 @@ func TestRolePermissionSoftDelete(t *testing.T) {
|
||||
PermCode: "rp:permission",
|
||||
PermType: constants.PermissionTypeMenu,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
err = permissionStore.Create(ctx, permission)
|
||||
require.NoError(t, err)
|
||||
|
||||
// 创建关联
|
||||
rolePermission := &model.RolePermission{
|
||||
RoleID: role.ID,
|
||||
PermID: permission.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
RoleID: role.ID,
|
||||
PermID: permission.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
}
|
||||
err = rolePermissionStore.Create(ctx, rolePermission)
|
||||
require.NoError(t, err)
|
||||
@@ -285,11 +265,9 @@ func TestRolePermissionSoftDelete(t *testing.T) {
|
||||
|
||||
t.Run("软删除后可以重新关联", func(t *testing.T) {
|
||||
newRolePermission := &model.RolePermission{
|
||||
RoleID: role.ID,
|
||||
PermID: permission.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
RoleID: role.ID,
|
||||
PermID: permission.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
}
|
||||
err := rolePermissionStore.Create(ctx, newRolePermission)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -30,8 +30,6 @@ func TestGetSubordinateIDs_CacheHit(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountA).Error)
|
||||
|
||||
@@ -42,8 +40,6 @@ func TestGetSubordinateIDs_CacheHit(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &accountA.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountB).Error)
|
||||
|
||||
@@ -85,8 +81,6 @@ func TestGetSubordinateIDs_CacheExpiry(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountA).Error)
|
||||
|
||||
@@ -132,8 +126,6 @@ func TestClearSubordinatesCache(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountA).Error)
|
||||
|
||||
@@ -172,8 +164,6 @@ func TestClearSubordinatesCacheForParents(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountA).Error)
|
||||
|
||||
@@ -184,8 +174,6 @@ func TestClearSubordinatesCacheForParents(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &accountA.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountB).Error)
|
||||
|
||||
@@ -196,8 +184,6 @@ func TestClearSubordinatesCacheForParents(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &accountB.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountC).Error)
|
||||
|
||||
@@ -249,8 +235,6 @@ func TestCacheInvalidationOnCreate(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountA).Error)
|
||||
|
||||
@@ -272,8 +256,6 @@ func TestCacheInvalidationOnCreate(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &accountA.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountB).Error)
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@ func TestGetSubordinateIDs_SingleLevel(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountA).Error)
|
||||
|
||||
@@ -40,8 +38,6 @@ func TestGetSubordinateIDs_SingleLevel(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &accountA.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountB).Error)
|
||||
|
||||
@@ -52,8 +48,6 @@ func TestGetSubordinateIDs_SingleLevel(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &accountA.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountC).Error)
|
||||
|
||||
@@ -81,8 +75,6 @@ func TestGetSubordinateIDs_MultiLevel(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountA).Error)
|
||||
|
||||
@@ -93,8 +85,6 @@ func TestGetSubordinateIDs_MultiLevel(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &accountA.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountB).Error)
|
||||
|
||||
@@ -105,8 +95,6 @@ func TestGetSubordinateIDs_MultiLevel(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &accountB.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountC).Error)
|
||||
|
||||
@@ -117,8 +105,6 @@ func TestGetSubordinateIDs_MultiLevel(t *testing.T) {
|
||||
UserType: constants.UserTypeEnterprise,
|
||||
ParentID: &accountC.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountD).Error)
|
||||
|
||||
@@ -129,8 +115,6 @@ func TestGetSubordinateIDs_MultiLevel(t *testing.T) {
|
||||
UserType: constants.UserTypeEnterprise,
|
||||
ParentID: &accountD.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountE).Error)
|
||||
|
||||
@@ -166,8 +150,6 @@ func TestGetSubordinateIDs_WithSoftDeleted(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypePlatform,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountA).Error)
|
||||
|
||||
@@ -178,8 +160,6 @@ func TestGetSubordinateIDs_WithSoftDeleted(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &accountA.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountB).Error)
|
||||
|
||||
@@ -190,8 +170,6 @@ func TestGetSubordinateIDs_WithSoftDeleted(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &accountB.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountC).Error)
|
||||
|
||||
@@ -226,8 +204,6 @@ func TestGetSubordinateIDs_Performance(t *testing.T) {
|
||||
Password: "hashed_password",
|
||||
UserType: constants.UserTypeRoot,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(accountA).Error)
|
||||
|
||||
@@ -241,8 +217,6 @@ func TestGetSubordinateIDs_Performance(t *testing.T) {
|
||||
UserType: constants.UserTypePlatform,
|
||||
ParentID: &accountA.ID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(acc).Error)
|
||||
level2IDs = append(level2IDs, acc.ID)
|
||||
@@ -259,8 +233,6 @@ func TestGetSubordinateIDs_Performance(t *testing.T) {
|
||||
UserType: constants.UserTypeAgent,
|
||||
ParentID: &parentID,
|
||||
Status: constants.StatusEnabled,
|
||||
Creator: 1,
|
||||
Updater: 1,
|
||||
}
|
||||
require.NoError(t, db.Create(acc).Error)
|
||||
level3IDs = append(level3IDs, acc.ID)
|
||||
|
||||
Reference in New Issue
Block a user