fix: issues
This commit is contained in:
@@ -4,48 +4,65 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"backend/database/models/qvyun/public/model"
|
||||
"backend/database/models/qvyun/public/table"
|
||||
"backend/fixtures"
|
||||
dbUtil "backend/pkg/db"
|
||||
"backend/pkg/path"
|
||||
"backend/pkg/pg"
|
||||
"backend/pkg/service/testx"
|
||||
"backend/providers/hashids"
|
||||
"backend/providers/postgres"
|
||||
"backend/providers/storage"
|
||||
|
||||
"github.com/samber/lo"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.uber.org/dig"
|
||||
)
|
||||
|
||||
func TestService_GetUserBoughtMedias(t *testing.T) {
|
||||
Convey("TestService_GetUserBoughtMedias", t, func() {
|
||||
db, err := fixtures.GetDB()
|
||||
So(err, ShouldBeNil)
|
||||
defer db.Close()
|
||||
type ServiceInjectParams struct {
|
||||
dig.In
|
||||
Svc *Service
|
||||
}
|
||||
|
||||
So(dbUtil.TruncateAllTables(context.TODO(), db, "user_medias"), ShouldBeNil)
|
||||
type ServiceTestSuite struct {
|
||||
suite.Suite
|
||||
ServiceInjectParams
|
||||
}
|
||||
|
||||
Convey("insert some data", func() {
|
||||
items := []model.UserMedias{
|
||||
{UserID: 1, TenantID: 1, MediaID: 1, Price: 10},
|
||||
{UserID: 1, TenantID: 1, MediaID: 2, Price: 10},
|
||||
{UserID: 1, TenantID: 1, MediaID: 3, Price: 10},
|
||||
}
|
||||
func Test_DiscoverMedias(t *testing.T) {
|
||||
providers := testx.Default(
|
||||
postgres.DefaultProvider(),
|
||||
storage.DefaultProvider(),
|
||||
hashids.DefaultProvider(),
|
||||
).With(
|
||||
Provide,
|
||||
)
|
||||
|
||||
tbl := table.UserMedias
|
||||
stmt := tbl.INSERT(tbl.UserID, tbl.TenantID, tbl.MediaID, tbl.Price).MODELS(items)
|
||||
t.Log(stmt.DebugSql())
|
||||
testx.Serve(providers, t, func(params ServiceInjectParams) {
|
||||
suite.Run(t, &ServiceTestSuite{ServiceInjectParams: params})
|
||||
})
|
||||
}
|
||||
|
||||
_, err := stmt.Exec(db)
|
||||
func (t *ServiceTestSuite) Test_getM3U8() {
|
||||
FocusConvey("Test_ffmpegVideoToM3U8", t.T(), func() {
|
||||
Convey("Bought", func() {
|
||||
hash := "f464a6641a60e2722e4042db8fad2813"
|
||||
media, err := t.Svc.GetM3U8(context.Background(), 1, pg.MediaTypeVideo, hash, true)
|
||||
So(err, ShouldBeNil)
|
||||
t.T().Logf("%+v", media)
|
||||
})
|
||||
|
||||
Convey("get user bought medias", func() {
|
||||
svc := &Service{db: db}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
|
||||
ids, err := svc.GetUserBoughtMedias(context.TODO(), 1, 1)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
for _, id := range ids {
|
||||
So(lo.Contains([]int64{1, 2, 3}, id), ShouldBeTrue)
|
||||
}
|
||||
})
|
||||
FocusConvey("Not Bought", func() {
|
||||
hash := "f464a6641a60e2722e4042db8fad2813"
|
||||
media, err := t.Svc.GetM3U8(context.Background(), 1, pg.MediaTypeVideo, hash, false)
|
||||
So(err, ShouldBeNil)
|
||||
t.T().Logf("%+v", media)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (t *ServiceTestSuite) Test_getMediaByHash() {
|
||||
Convey("Test_getMediaByHash", t.T(), func() {
|
||||
name, ext := path.SplitNameExt("0.ts")
|
||||
|
||||
So(name, ShouldEqual, "0")
|
||||
So(ext, ShouldEqual, "ts")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user