offlineactivity_test.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/growup/dao/shell"
  5. "go-common/app/admin/main/growup/model/offlineactivity"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaogenerateDelimiter(t *testing.T) {
  10. convey.Convey("generateDelimiter", t, func(ctx convey.C) {
  11. var (
  12. delimiter = "test"
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. p1 := generateDelimiter(delimiter)
  16. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  17. ctx.So(p1, convey.ShouldNotBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestDaostrlistToInt64List(t *testing.T) {
  23. convey.Convey("strlistToInt64List", t, func(ctx convey.C) {
  24. var (
  25. list = []string{"11", "22 ", "vv ", "33 "}
  26. trimSet = " "
  27. )
  28. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  29. result := strlistToInt64List(list, trimSet)
  30. ctx.Convey("Then result should not be nil.", func(ctx convey.C) {
  31. ctx.So(result, convey.ShouldNotBeNil)
  32. })
  33. })
  34. })
  35. }
  36. func TestDaotrimString(t *testing.T) {
  37. convey.Convey("trimString", t, func(ctx convey.C) {
  38. var (
  39. strlist = []string{"11", "22 ", "vv ", "33 "}
  40. trimset = " "
  41. )
  42. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  43. result := trimString(strlist, trimset)
  44. ctx.Convey("Then result should not be nil.", func(ctx convey.C) {
  45. ctx.So(result, convey.ShouldNotBeNil)
  46. })
  47. })
  48. })
  49. }
  50. func TestDaoParseMidsFromString(t *testing.T) {
  51. convey.Convey("ParseMidsFromString", t, func(ctx convey.C) {
  52. var (
  53. str = "123"
  54. )
  55. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  56. result := ParseMidsFromString(str)
  57. ctx.Convey("Then result should not be nil.", func(ctx convey.C) {
  58. ctx.So(result, convey.ShouldNotBeNil)
  59. })
  60. })
  61. })
  62. }
  63. func TestDaoOfflineActivityAddActivity(t *testing.T) {
  64. convey.Convey("OfflineActivityAddActivity", t, func(ctx convey.C) {
  65. var (
  66. c = context.Background()
  67. arg = &offlineactivity.AddActivityArg{
  68. Title: "test",
  69. BonusType: 0,
  70. Memo: "memo test",
  71. Link: "http://12345.com",
  72. BonusList: []*offlineactivity.BonusInfo{{TotalMoney: 100, Mids: "1,2,3,"}},
  73. }
  74. )
  75. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  76. err := d.OfflineActivityAddActivity(c, arg)
  77. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  78. ctx.So(err, convey.ShouldBeNil)
  79. })
  80. })
  81. })
  82. }
  83. func TestDaoShellCallbackUpdate(t *testing.T) {
  84. convey.Convey("ShellCallbackUpdate", t, func(ctx convey.C) {
  85. var (
  86. c = context.Background()
  87. result = &shell.OrderCallbackJSON{
  88. ThirdOrderNo: "1001",
  89. Status: "SUCCESS",
  90. }
  91. msgid = ""
  92. )
  93. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  94. Exec(c, "INSERT INTO offline_activity_shell_order(id, result_id, order_id, order_status) VALUES(1000, '1001', '1001', 'SUCCESS')")
  95. orderInfo, err := d.ShellCallbackUpdate(c, result, msgid)
  96. ctx.Convey("Then err should be nil.orderInfo should not be nil.", func(ctx convey.C) {
  97. ctx.So(err, convey.ShouldBeNil)
  98. ctx.So(orderInfo, convey.ShouldNotBeNil)
  99. })
  100. })
  101. })
  102. }
  103. func TestDaoOfflineActivityGetUpBonusResult(t *testing.T) {
  104. convey.Convey("OfflineActivityGetUpBonusResult", t, func(ctx convey.C) {
  105. var (
  106. c = context.Background()
  107. needCount bool
  108. limit = int(10)
  109. offset = int(1)
  110. query = "id>?"
  111. args = "0"
  112. )
  113. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  114. upResult, totalCount, err := d.OfflineActivityGetUpBonusResult(c, needCount, limit, offset, query, args)
  115. ctx.Convey("Then err should be nil.upResult,totalCount should not be nil.", func(ctx convey.C) {
  116. ctx.So(err, convey.ShouldBeNil)
  117. ctx.So(totalCount, convey.ShouldNotBeNil)
  118. ctx.So(upResult, convey.ShouldNotBeNil)
  119. })
  120. })
  121. })
  122. }
  123. func TestDaoOfflineActivityGetUpBonusResultSelect(t *testing.T) {
  124. convey.Convey("OfflineActivityGetUpBonusResultSelect", t, func(ctx convey.C) {
  125. var (
  126. c = context.Background()
  127. selectQuery = "activity_id"
  128. query = "id>?"
  129. args = "0"
  130. )
  131. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  132. upResult, err := d.OfflineActivityGetUpBonusResultSelect(c, selectQuery, query, args)
  133. ctx.Convey("Then err should be nil.upResult should not be nil.", func(ctx convey.C) {
  134. ctx.So(err, convey.ShouldBeNil)
  135. ctx.So(upResult, convey.ShouldNotBeNil)
  136. })
  137. })
  138. })
  139. }
  140. func TestDaoOfflineActivityGetUpBonusByActivityResult(t *testing.T) {
  141. convey.Convey("OfflineActivityGetUpBonusByActivityResult", t, func(ctx convey.C) {
  142. var (
  143. c = context.Background()
  144. limit = int(10)
  145. offset = int(0)
  146. mid = int64(0)
  147. )
  148. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  149. upResult, totalCount, err := d.OfflineActivityGetUpBonusByActivityResult(c, limit, offset, mid)
  150. ctx.Convey("Then err should be nil.upResult,totalCount should not be nil.", func(ctx convey.C) {
  151. ctx.So(err, convey.ShouldBeNil)
  152. ctx.So(totalCount, convey.ShouldNotBeNil)
  153. ctx.So(upResult, convey.ShouldNotBeNil)
  154. })
  155. })
  156. })
  157. }
  158. func TestDaoOfflineActivityGetDB(t *testing.T) {
  159. convey.Convey("OfflineActivityGetDB", t, func(ctx convey.C) {
  160. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  161. p1 := d.OfflineActivityGetDB()
  162. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  163. ctx.So(p1, convey.ShouldNotBeNil)
  164. })
  165. })
  166. })
  167. }
  168. func TestDaoUpdateActivityState(t *testing.T) {
  169. convey.Convey("UpdateActivityState", t, func(ctx convey.C) {
  170. var (
  171. c = context.Background()
  172. activityID = int64(10)
  173. )
  174. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  175. affectedRow, err := d.UpdateActivityState(c, activityID)
  176. ctx.Convey("Then err should be nil.affectedRow should not be nil.", func(ctx convey.C) {
  177. ctx.So(err, convey.ShouldBeNil)
  178. ctx.So(affectedRow, convey.ShouldNotBeNil)
  179. })
  180. })
  181. })
  182. }