60 lines
1.2 KiB
Go
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,
|
|
}
|
|
|
|
u, err := user.Create(context.TODO())
|
|
So(err, ShouldBeNil)
|
|
So(u, ShouldNotBeNil)
|
|
So(u.ID, ShouldNotBeZeroValue)
|
|
})
|
|
}
|