52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package medias
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"backend/database/models/qvyun/public/model"
|
|
"backend/database/models/qvyun/public/table"
|
|
"backend/fixtures"
|
|
dbUtil "backend/pkg/db"
|
|
|
|
"github.com/samber/lo"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
func TestService_GetUserBoughtMedias(t *testing.T) {
|
|
Convey("TestService_GetUserBoughtMedias", t, func() {
|
|
db, err := fixtures.GetDB()
|
|
So(err, ShouldBeNil)
|
|
defer db.Close()
|
|
|
|
So(dbUtil.TruncateAllTables(context.TODO(), db, "user_medias"), ShouldBeNil)
|
|
|
|
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},
|
|
}
|
|
|
|
tbl := table.UserMedias
|
|
stmt := tbl.INSERT(tbl.UserID, tbl.TenantID, tbl.MediaID, tbl.Price).MODELS(items)
|
|
t.Log(stmt.DebugSql())
|
|
|
|
_, err := stmt.Exec(db)
|
|
So(err, ShouldBeNil)
|
|
|
|
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)
|
|
}
|
|
})
|
|
})
|
|
})
|
|
}
|