mcn_recommend_test.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package up
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/mcn/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestUpAddMcnUpRecommend(t *testing.T) {
  9. convey.Convey("AddMcnUpRecommend", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. arg = &model.McnUpRecommendPool{}
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. rows, err := d.AddMcnUpRecommend(c, arg)
  16. d.db.Exec(c, "delete from mcn_up_recommend_pool where up_mid=0")
  17. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(rows, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestUpUpMcnUpsRecommendOP(t *testing.T) {
  25. convey.Convey("UpMcnUpsRecommendOP", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. upMids = []int64{1, 2}
  29. state = model.MCNUPRecommendState(2)
  30. )
  31. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  32. rows, err := d.UpMcnUpsRecommendOP(c, upMids, state)
  33. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  34. ctx.So(err, convey.ShouldBeNil)
  35. ctx.So(rows, convey.ShouldNotBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestUpMcnUpRecommends(t *testing.T) {
  41. convey.Convey("McnUpRecommends", t, func(ctx convey.C) {
  42. var (
  43. c = context.Background()
  44. arg = &model.MCNUPRecommendReq{}
  45. )
  46. arg.Order = "mtime"
  47. arg.Sort = "DESC"
  48. arg.Page = 1
  49. arg.Size = 10
  50. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  51. res, err := d.McnUpRecommends(c, arg)
  52. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. ctx.So(res, convey.ShouldNotBeNil)
  55. })
  56. })
  57. })
  58. }
  59. func TestUpMcnUpRecommendTotal(t *testing.T) {
  60. convey.Convey("McnUpRecommendTotal", t, func(ctx convey.C) {
  61. var (
  62. c = context.Background()
  63. arg = &model.MCNUPRecommendReq{}
  64. )
  65. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  66. count, err := d.McnUpRecommendTotal(c, arg)
  67. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  68. ctx.So(err, convey.ShouldBeNil)
  69. ctx.So(count, convey.ShouldNotBeNil)
  70. })
  71. })
  72. })
  73. }
  74. func TestUpMcnUpBindMids(t *testing.T) {
  75. convey.Convey("McnUpBindMids", t, func(ctx convey.C) {
  76. var (
  77. c = context.Background()
  78. mids = []int64{1, 2}
  79. )
  80. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  81. bmids, err := d.McnUpBindMids(c, mids)
  82. ctx.Convey("Then err should be nil.bmids should not be nil.", func(ctx convey.C) {
  83. ctx.So(err, convey.ShouldBeNil)
  84. if len(bmids) == 0 {
  85. ctx.So(bmids, convey.ShouldBeEmpty)
  86. } else {
  87. ctx.So(bmids, convey.ShouldNotBeNil)
  88. }
  89. })
  90. })
  91. })
  92. }
  93. func TestUpMcnUpRecommendMid(t *testing.T) {
  94. convey.Convey("McnUpRecommendMid", t, func(ctx convey.C) {
  95. var (
  96. c = context.Background()
  97. mid = int64(0)
  98. )
  99. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  100. m, err := d.McnUpRecommendMid(c, mid)
  101. ctx.Convey("Then err should be nil.m should not be nil.", func(ctx convey.C) {
  102. ctx.So(err, convey.ShouldBeNil)
  103. ctx.So(m, convey.ShouldBeNil)
  104. })
  105. })
  106. })
  107. }
  108. func TestUpbuildUpRecommendSQL(t *testing.T) {
  109. convey.Convey("buildUpRecommendSQL", t, func(ctx convey.C) {
  110. var (
  111. tp = ""
  112. arg = &model.MCNUPRecommendReq{}
  113. )
  114. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  115. sql, values := d.buildUpRecommendSQL(tp, arg)
  116. ctx.Convey("Then sql,values should not be nil.", func(ctx convey.C) {
  117. ctx.So(values, convey.ShouldNotBeNil)
  118. ctx.So(sql, convey.ShouldNotBeNil)
  119. })
  120. })
  121. })
  122. }
  123. func TestUpjoinStringSQL(t *testing.T) {
  124. convey.Convey("joinStringSQL", t, func(ctx convey.C) {
  125. var (
  126. is = []string{}
  127. )
  128. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  129. p1 := d.joinStringSQL(is)
  130. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  131. ctx.So(p1, convey.ShouldNotBeNil)
  132. })
  133. })
  134. })
  135. }