feat: complete charge
This commit is contained in:
@@ -4,64 +4,56 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"backend/fixtures"
|
||||
dbUtil "backend/pkg/db"
|
||||
"backend/pkg/pg"
|
||||
"backend/pkg/service/testx"
|
||||
"backend/providers/hashids"
|
||||
"backend/providers/jwt"
|
||||
"backend/providers/postgres"
|
||||
"backend/providers/storage"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.uber.org/dig"
|
||||
)
|
||||
|
||||
func TestService_GetOrNew(t *testing.T) {
|
||||
FocusConvey("Test GetOrNew", t, func() {
|
||||
// So(dbUtil.TruncateAllTables(context.TODO(), db, "users", "users_tenants"), ShouldBeNil)
|
||||
db, err := fixtures.GetDB()
|
||||
So(err, ShouldBeNil)
|
||||
defer db.Close()
|
||||
type ServiceInjectParams struct {
|
||||
dig.In
|
||||
Svc *Service
|
||||
}
|
||||
|
||||
Convey("Test GetOrNew", func() {
|
||||
svc := &Service{db: db}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
type ServiceTestSuite struct {
|
||||
suite.Suite
|
||||
ServiceInjectParams
|
||||
}
|
||||
|
||||
user, err := svc.GetByOpenID(context.Background(), "hello")
|
||||
So(err, ShouldBeNil)
|
||||
func Test_DiscoverMedias(t *testing.T) {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
So(user, ShouldNotBeNil)
|
||||
So(user.OpenID, ShouldEqual, "hello")
|
||||
})
|
||||
providers := testx.Default(
|
||||
postgres.DefaultProvider(),
|
||||
storage.DefaultProvider(),
|
||||
hashids.DefaultProvider(),
|
||||
).With(
|
||||
Provide,
|
||||
)
|
||||
|
||||
FocusConvey("Test GetOrNew", func() {
|
||||
svc := &Service{db: db}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
|
||||
openid := "test_openid"
|
||||
authInfo := pg.UserOAuth{
|
||||
AccessToken: "test_access_token",
|
||||
}
|
||||
|
||||
user, err := svc.GetOrNew(context.Background(), 1, openid, authInfo)
|
||||
So(err, ShouldBeNil)
|
||||
So(user.OpenID, ShouldEqual, openid)
|
||||
})
|
||||
testx.Serve(providers, t, func(params ServiceInjectParams) {
|
||||
suite.Run(t, &ServiceTestSuite{ServiceInjectParams: params})
|
||||
})
|
||||
}
|
||||
|
||||
func TestService_CreateTenantUser(t *testing.T) {
|
||||
FocusConvey("Test CreateTenantUser", t, func() {
|
||||
db, err := fixtures.GetDB()
|
||||
func (t *ServiceTestSuite) Test_Charge() {
|
||||
Convey("Charge", t.T(), func() {
|
||||
code, err := t.Svc.GenerateChargeCode(context.Background(), 1, 100)
|
||||
So(err, ShouldBeNil)
|
||||
defer db.Close()
|
||||
code = "b8TDWf59wvPw"
|
||||
|
||||
So(dbUtil.TruncateAllTables(context.TODO(), db, "users", "users_tenants"), ShouldBeNil)
|
||||
|
||||
FocusConvey("Test Create", func() {
|
||||
svc := &Service{db: db}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
|
||||
err := svc.CreateTenantUser(context.Background(), 1, 1)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = svc.CreateTenantUser(context.Background(), 1, 1)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
err = t.Svc.Charge(context.Background(), &jwt.Claims{
|
||||
BaseClaims: jwt.BaseClaims{
|
||||
TenantID: 1,
|
||||
UserID: 1,
|
||||
},
|
||||
}, code)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user