feat: 更新服务方法,显式接受用户ID参数,简化上下文调用
This commit is contained in:
@@ -126,7 +126,7 @@ func (s *ContentTestSuite) Test_Get() {
|
||||
ctx = context.WithValue(ctx, consts.CtxKeyUser, author.ID)
|
||||
|
||||
Convey("should get detail with assets", func() {
|
||||
detail, err := Content.Get(ctx, cast.ToString(content.ID))
|
||||
detail, err := Content.Get(ctx, author.ID, cast.ToString(content.ID))
|
||||
So(err, ShouldBeNil)
|
||||
So(detail.Title, ShouldEqual, "Detail Content")
|
||||
So(detail.AuthorName, ShouldEqual, "Author1")
|
||||
@@ -154,7 +154,7 @@ func (s *ContentTestSuite) Test_CreateComment() {
|
||||
form := &content_dto.CommentCreateForm{
|
||||
Content: "Nice!",
|
||||
}
|
||||
err := Content.CreateComment(ctx, cast.ToString(c.ID), form)
|
||||
err := Content.CreateComment(ctx, u.ID, cast.ToString(c.ID), form)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
count, _ := models.CommentQuery.WithContext(ctx).Where(models.CommentQuery.ContentID.Eq(c.ID)).Count()
|
||||
@@ -193,7 +193,7 @@ func (s *ContentTestSuite) Test_Library() {
|
||||
})
|
||||
|
||||
Convey("should get library content with details", func() {
|
||||
list, err := Content.GetLibrary(ctx)
|
||||
list, err := Content.GetLibrary(ctx, u.ID)
|
||||
So(err, ShouldBeNil)
|
||||
So(len(list), ShouldEqual, 1)
|
||||
So(list[0].Title, ShouldEqual, "Paid Content")
|
||||
@@ -219,7 +219,7 @@ func (s *ContentTestSuite) Test_Interact() {
|
||||
|
||||
Convey("Like flow", func() {
|
||||
// Add Like
|
||||
err := Content.AddLike(ctx, cast.ToString(c.ID))
|
||||
err := Content.AddLike(ctx, u.ID, cast.ToString(c.ID))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Verify count
|
||||
@@ -227,13 +227,13 @@ func (s *ContentTestSuite) Test_Interact() {
|
||||
So(cReload.Likes, ShouldEqual, 1)
|
||||
|
||||
// Get Likes
|
||||
likes, err := Content.GetLikes(ctx)
|
||||
likes, err := Content.GetLikes(ctx, u.ID)
|
||||
So(err, ShouldBeNil)
|
||||
So(len(likes), ShouldEqual, 1)
|
||||
So(likes[0].ID, ShouldEqual, cast.ToString(c.ID))
|
||||
|
||||
// Remove Like
|
||||
err = Content.RemoveLike(ctx, cast.ToString(c.ID))
|
||||
err = Content.RemoveLike(ctx, u.ID, cast.ToString(c.ID))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Verify count
|
||||
@@ -243,21 +243,21 @@ func (s *ContentTestSuite) Test_Interact() {
|
||||
|
||||
Convey("Favorite flow", func() {
|
||||
// Add Favorite
|
||||
err := Content.AddFavorite(ctx, cast.ToString(c.ID))
|
||||
err := Content.AddFavorite(ctx, u.ID, cast.ToString(c.ID))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Get Favorites
|
||||
favs, err := Content.GetFavorites(ctx)
|
||||
favs, err := Content.GetFavorites(ctx, u.ID)
|
||||
So(err, ShouldBeNil)
|
||||
So(len(favs), ShouldEqual, 1)
|
||||
So(favs[0].ID, ShouldEqual, cast.ToString(c.ID))
|
||||
|
||||
// Remove Favorite
|
||||
err = Content.RemoveFavorite(ctx, cast.ToString(c.ID))
|
||||
err = Content.RemoveFavorite(ctx, u.ID, cast.ToString(c.ID))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Get Favorites
|
||||
favs, err = Content.GetFavorites(ctx)
|
||||
favs, err = Content.GetFavorites(ctx, u.ID)
|
||||
So(err, ShouldBeNil)
|
||||
So(len(favs), ShouldEqual, 0)
|
||||
})
|
||||
@@ -325,7 +325,7 @@ func (s *ContentTestSuite) Test_PreviewLogic() {
|
||||
models.UserQuery.WithContext(ctx).Create(guest)
|
||||
guestCtx := context.WithValue(ctx, consts.CtxKeyUser, guest.ID)
|
||||
|
||||
detail, err := Content.Get(guestCtx, cast.ToString(c.ID))
|
||||
detail, err := Content.Get(guestCtx, 0, cast.ToString(c.ID))
|
||||
So(err, ShouldBeNil)
|
||||
So(len(detail.MediaUrls), ShouldEqual, 1)
|
||||
So(detail.MediaUrls[0].URL, ShouldEndWith, "preview.mp4")
|
||||
@@ -334,7 +334,7 @@ func (s *ContentTestSuite) Test_PreviewLogic() {
|
||||
|
||||
Convey("owner should see all", func() {
|
||||
ownerCtx := context.WithValue(ctx, consts.CtxKeyUser, author.ID)
|
||||
detail, err := Content.Get(ownerCtx, cast.ToString(c.ID))
|
||||
detail, err := Content.Get(ownerCtx, author.ID, cast.ToString(c.ID))
|
||||
So(err, ShouldBeNil)
|
||||
So(len(detail.MediaUrls), ShouldEqual, 2)
|
||||
So(detail.IsPurchased, ShouldBeTrue)
|
||||
@@ -349,7 +349,7 @@ func (s *ContentTestSuite) Test_PreviewLogic() {
|
||||
UserID: buyer.ID, ContentID: c.ID, Status: consts.ContentAccessStatusActive,
|
||||
})
|
||||
|
||||
detail, err := Content.Get(buyerCtx, cast.ToString(c.ID))
|
||||
detail, err := Content.Get(buyerCtx, buyer.ID, cast.ToString(c.ID))
|
||||
So(err, ShouldBeNil)
|
||||
So(len(detail.MediaUrls), ShouldEqual, 2)
|
||||
So(detail.IsPurchased, ShouldBeTrue)
|
||||
@@ -369,7 +369,7 @@ func (s *ContentTestSuite) Test_ViewCounting() {
|
||||
models.ContentQuery.WithContext(ctx).Create(c)
|
||||
|
||||
Convey("should increment views", func() {
|
||||
_, err := Content.Get(ctx, cast.ToString(c.ID))
|
||||
_, err := Content.Get(ctx, 0, cast.ToString(c.ID))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cReload, _ := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(c.ID)).First()
|
||||
|
||||
Reference in New Issue
Block a user