Files
quyun/backend/app/model/users_test.go
2025-05-23 23:42:27 +08:00

60 lines
1.2 KiB
Go

package model
import (
"context"
"testing"
"time"
"quyun/app/service/testx"
"quyun/database/fields"
. "github.com/smartystreets/goconvey/convey"
"go.ipao.vip/atom/contracts"
// . "github.com/go-jet/jet/v2/postgres"
"github.com/stretchr/testify/suite"
"go.uber.org/dig"
)
type UsersInjectParams struct {
dig.In
Initials []contracts.Initial `group:"initials"`
}
type UsersTestSuite struct {
suite.Suite
UsersInjectParams
}
func Test_Users(t *testing.T) {
providers := testx.Default().With(Provide)
testx.Serve(providers, t, func(params UsersInjectParams) {
suite.Run(t, &UsersTestSuite{
UsersInjectParams: params,
})
})
}
func (s *UsersTestSuite) Test_Create() {
Convey("Test_Create", s.T(), func() {
user := &Users{
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
DeletedAt: nil,
Status: 1,
OpenID: "test_openid_123",
Username: "testuser",
Avatar: &[]string{"https://example.com/avatar.jpg"}[0],
Metas: fields.ToJson(fields.UserMetas{}),
AuthToken: fields.ToJson(fields.UserAuthToken{}),
Balance: 1000,
}
err := user.Create(context.TODO())
So(err, ShouldBeNil)
So(user, ShouldNotBeNil)
So(user.ID, ShouldNotBeZeroValue)
})
}