69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package users
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"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"
|
|
)
|
|
|
|
type ServiceInjectParams struct {
|
|
dig.In
|
|
Svc *Service
|
|
}
|
|
|
|
type ServiceTestSuite struct {
|
|
suite.Suite
|
|
ServiceInjectParams
|
|
}
|
|
|
|
func Test_DiscoverMedias(t *testing.T) {
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
providers := testx.Default(
|
|
postgres.DefaultProvider(),
|
|
storage.DefaultProvider(),
|
|
hashids.DefaultProvider(),
|
|
).With(
|
|
Provide,
|
|
)
|
|
|
|
testx.Serve(providers, t, func(params ServiceInjectParams) {
|
|
suite.Run(t, &ServiceTestSuite{ServiceInjectParams: params})
|
|
})
|
|
}
|
|
|
|
func (t *ServiceTestSuite) Test_Charge() {
|
|
Convey("Charge", t.T(), func() {
|
|
code, err := t.Svc.GenerateChargeCode(context.Background(), 2, 100)
|
|
So(err, ShouldBeNil)
|
|
code = "b8TDWf59wvPw"
|
|
|
|
err = t.Svc.Charge(context.Background(), &jwt.Claims{
|
|
BaseClaims: jwt.BaseClaims{
|
|
TenantID: 1,
|
|
UserID: 1,
|
|
},
|
|
}, code)
|
|
So(err, ShouldBeNil)
|
|
})
|
|
}
|
|
|
|
// Test_GetTenantUserBalance
|
|
func (t *ServiceTestSuite) Test_GetTenantUserBalance() {
|
|
Convey("GetTenantUserBalance", t.T(), func() {
|
|
balance, err := t.Svc.GetTenantUserBalance(context.Background(), 1, 1)
|
|
So(err, ShouldBeNil)
|
|
So(balance, ShouldNotEqual, 0)
|
|
})
|
|
}
|