fix: issues
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"backend/database/models/qvyun/public/table"
|
||||
"backend/fixtures"
|
||||
dbUtil "backend/pkg/db"
|
||||
"backend/pkg/pg"
|
||||
"backend/providers/storage"
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/google/uuid"
|
||||
@@ -118,59 +118,6 @@ func TestService_List(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
|
||||
Convey("create media's resources", func() {
|
||||
items := []model.MediaResources{
|
||||
{
|
||||
MediaID: 1,
|
||||
Type: pg.MediaTypeVideo,
|
||||
Size: 100,
|
||||
Publish: true,
|
||||
},
|
||||
{
|
||||
MediaID: 1,
|
||||
Type: pg.MediaTypeAudio,
|
||||
Size: 100,
|
||||
Publish: true,
|
||||
},
|
||||
{
|
||||
MediaID: 2,
|
||||
Type: pg.MediaTypeVideo,
|
||||
Size: 100,
|
||||
Publish: true,
|
||||
},
|
||||
{
|
||||
MediaID: 2,
|
||||
Type: pg.MediaTypeAudio,
|
||||
Size: 100,
|
||||
Publish: true,
|
||||
},
|
||||
{
|
||||
MediaID: 3,
|
||||
Type: pg.MediaTypeVideo,
|
||||
Size: 100,
|
||||
Publish: true,
|
||||
},
|
||||
{
|
||||
MediaID: 3,
|
||||
Type: pg.MediaTypeAudio,
|
||||
Size: 100,
|
||||
Publish: true,
|
||||
},
|
||||
}
|
||||
|
||||
tbl := table.MediaResources
|
||||
stmt := tbl.INSERT(
|
||||
tbl.MediaID,
|
||||
tbl.Type,
|
||||
tbl.Size,
|
||||
tbl.Publish,
|
||||
).MODELS(items)
|
||||
t.Log(stmt.DebugSql())
|
||||
|
||||
_, err := stmt.Exec(db)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
|
||||
Convey("get list", func() {
|
||||
svc := &Service{db: db}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
@@ -213,61 +160,50 @@ func TestService_List1(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestService_DecorateListResources(t *testing.T) {
|
||||
Convey("TestService_DecorateListResources", t, func() {
|
||||
func TestService_PublishTenant(t *testing.T) {
|
||||
Convey("TestService_PublishTenant", t, func() {
|
||||
db, err := fixtures.GetDB()
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
defer db.Close()
|
||||
|
||||
Convey("truncate all tables", func() {
|
||||
So(dbUtil.TruncateAllTables(context.TODO(), db, "medias", "media_resources"), ShouldBeNil)
|
||||
So(dbUtil.TruncateAllTables(context.TODO(), db, "medias"), ShouldBeNil)
|
||||
})
|
||||
|
||||
Convey("create media's resources", func() {
|
||||
items := []model.MediaResources{
|
||||
{
|
||||
MediaID: 1,
|
||||
Type: pg.MediaTypeVideo,
|
||||
Size: 100,
|
||||
Publish: true,
|
||||
},
|
||||
{
|
||||
MediaID: 2,
|
||||
Type: pg.MediaTypeAudio,
|
||||
Size: 100,
|
||||
Publish: true,
|
||||
},
|
||||
u1, err := uuid.Parse("6c63c4d8-b2cb-4588-8dd3-9a2276918d17")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
u2, err := uuid.Parse("8c183427-02b1-4426-ad65-18c6e7735072")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
u3, err := uuid.Parse("24aa56a1-a85b-4a03-9a1b-c39a36103ddf")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("insert some data", func() {
|
||||
items := []model.Medias{
|
||||
{UUID: u1, TenantID: 1, Title: "title1", Description: "hello", Price: 100, Publish: true},
|
||||
{UUID: u2, TenantID: 1, Title: "title2", Description: "hello", Price: 100, Publish: true},
|
||||
{UUID: u3, TenantID: 1, Title: "title3", Description: "hello", Price: 100, Publish: true},
|
||||
}
|
||||
|
||||
tbl := table.MediaResources
|
||||
stmt := tbl.INSERT(
|
||||
tbl.MediaID,
|
||||
tbl.Type,
|
||||
tbl.Size,
|
||||
tbl.Publish,
|
||||
).MODELS(items)
|
||||
t.Log(stmt.DebugSql())
|
||||
Convey("publish tenant", func() {
|
||||
svc := &Service{
|
||||
db: db,
|
||||
storageConfig: &storage.Config{
|
||||
Path: "/projects/mp-qvyun/backend/fixtures/medias",
|
||||
},
|
||||
}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
|
||||
_, err := stmt.Exec(db)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
err := svc.PublishTenantMedia(context.TODO(), 1, items[0].UUID, items[0].Title)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("decorate list resources", func() {
|
||||
items := []ListItem{
|
||||
{Medias: model.Medias{ID: 1}},
|
||||
{Medias: model.Medias{ID: 2}},
|
||||
}
|
||||
err = svc.PublishTenantMedia(context.TODO(), 1, items[1].UUID, items[1].Title)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
svc := &Service{db: db}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
|
||||
items, err := svc.DecorateListResources(context.TODO(), 1, 1, items)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
for _, item := range items {
|
||||
So(item.MediaResources, ShouldHaveLength, 1)
|
||||
}
|
||||
err = svc.PublishTenantMedia(context.TODO(), 1, items[2].UUID, items[2].Title)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user