chore: update auth and portal

This commit is contained in:
2026-01-14 11:29:17 +08:00
parent fb0a1c2f84
commit 3bcee7efc2
42 changed files with 5969 additions and 3014 deletions

View File

@@ -16,6 +16,7 @@ import (
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/suite"
"go.ipao.vip/atom/contracts"
"go.ipao.vip/gen/types"
"go.uber.org/dig"
)
@@ -74,6 +75,60 @@ func (s *SuperTestSuite) Test_ListUsers() {
})
}
func (s *SuperTestSuite) Test_LoginAndCheckToken() {
Convey("Login and CheckToken", s.T(), func() {
ctx := s.T().Context()
database.Truncate(ctx, s.DB, models.TableNameUser)
admin := &models.User{
Username: "super_admin",
Password: "pass123",
Roles: types.Array[consts.Role]{consts.RoleSuperAdmin},
Status: consts.UserStatusVerified,
}
normal := &models.User{
Username: "normal_user",
Password: "pass123",
Status: consts.UserStatusVerified,
}
models.UserQuery.WithContext(ctx).Create(admin, normal)
Convey("should login as super admin", func() {
res, err := Super.Login(ctx, &super_dto.LoginForm{
Username: admin.Username,
Password: admin.Password,
})
So(err, ShouldBeNil)
So(res, ShouldNotBeNil)
So(res.Token, ShouldNotBeBlank)
So(res.User.ID, ShouldEqual, admin.ID)
})
Convey("should reject non-super admin", func() {
_, err := Super.Login(ctx, &super_dto.LoginForm{
Username: normal.Username,
Password: normal.Password,
})
So(err, ShouldNotBeNil)
})
Convey("should refresh token", func() {
loginRes, err := Super.Login(ctx, &super_dto.LoginForm{
Username: admin.Username,
Password: admin.Password,
})
So(err, ShouldBeNil)
token := "Bearer " + loginRes.Token
checkRes, err := Super.CheckToken(ctx, token)
So(err, ShouldBeNil)
So(checkRes, ShouldNotBeNil)
So(checkRes.Token, ShouldNotBeBlank)
So(checkRes.User.ID, ShouldEqual, admin.ID)
})
})
}
func (s *SuperTestSuite) Test_CreateTenant() {
Convey("CreateTenant", s.T(), func() {
ctx := s.T().Context()