user_like_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/bbq/user/internal/model"
  5. xtime "go-common/library/time"
  6. "testing"
  7. "time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoTxAddUserLike(t *testing.T) {
  11. convey.Convey("TxAddUserLike", t, func(ctx convey.C) {
  12. var (
  13. c = context.Background()
  14. mid = int64(88895104)
  15. svid = int64(133)
  16. )
  17. tx, _ := d.BeginTran(c)
  18. defer func() {
  19. tx.Rollback()
  20. }()
  21. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  22. num, err := d.TxAddUserLike(tx, mid, svid)
  23. ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  24. ctx.So(err, convey.ShouldBeNil)
  25. ctx.So(num, convey.ShouldNotBeNil)
  26. })
  27. })
  28. })
  29. }
  30. func TestDaoTxCancelUserLike(t *testing.T) {
  31. convey.Convey("TxCancelUserLike", t, func(ctx convey.C) {
  32. var (
  33. c = context.Background()
  34. mid = int64(88895104)
  35. svid = int64(133)
  36. )
  37. tx, _ := d.BeginTran(c)
  38. defer func() {
  39. tx.Rollback()
  40. }()
  41. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  42. num, err := d.TxCancelUserLike(tx, mid, svid)
  43. ctx.Convey("Then err should be nil.num should not be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. ctx.So(num, convey.ShouldNotBeNil)
  46. })
  47. })
  48. })
  49. }
  50. func TestDaoGetUserLikeList(t *testing.T) {
  51. convey.Convey("GetUserLikeList", t, func(ctx convey.C) {
  52. var (
  53. c = context.Background()
  54. mid = int64(88895104)
  55. cursorNext bool
  56. cursor model.CursorValue
  57. size = int(10)
  58. )
  59. cursorNext = true
  60. cursor.CursorID = model.MaxInt64
  61. cursor.CursorTime = xtime.Time(time.Now().Unix())
  62. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  63. likeSvs, err := d.GetUserLikeList(c, mid, cursorNext, cursor, size)
  64. ctx.Convey("Then err should be nil.likeSvs should not be nil.", func(ctx convey.C) {
  65. ctx.So(err, convey.ShouldBeNil)
  66. ctx.So(likeSvs, convey.ShouldNotBeNil)
  67. })
  68. })
  69. })
  70. }