income_test.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoGetUpDailyCharge(t *testing.T) {
  8. convey.Convey("GetUpDailyCharge", t, func(ctx convey.C) {
  9. var (
  10. c = context.Background()
  11. mid = int64(1001)
  12. begin = "2018-01-01"
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. Exec(c, "INSERT INTO up_daily_charge(mid, date, inc_charge) VALUES(1001, '2018-06-01', 100)")
  16. incs, err := d.GetUpDailyCharge(c, mid, begin)
  17. ctx.Convey("Then err should be nil.incs should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(incs, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoListAvIncome(t *testing.T) {
  25. convey.Convey("ListAvIncome", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. mid = int64(1001)
  29. startTime = "2018-01-01"
  30. endTime = "2019-01-01"
  31. )
  32. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  33. Exec(c, "INSERT INTO av_income(av_id, mid, date, income) VALUES(1000, 1001, '2018-06-01', 100)")
  34. avs, err := d.ListAvIncome(c, mid, startTime, endTime)
  35. ctx.Convey("Then err should be nil.avs should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(avs, convey.ShouldNotBeNil)
  38. })
  39. })
  40. })
  41. }
  42. func TestDaoListAvIncomeByID(t *testing.T) {
  43. convey.Convey("ListAvIncomeByID", t, func(ctx convey.C) {
  44. var (
  45. c = context.Background()
  46. avID = int64(1000)
  47. endTime = "2019-01-01"
  48. )
  49. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  50. Exec(c, "INSERT INTO av_income(av_id, mid, date, income) VALUES(1000, 1001, '2018-06-01', 100)")
  51. avs, err := d.ListAvIncomeByID(c, avID, endTime)
  52. ctx.Convey("Then err should be nil.avs should not be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. ctx.So(avs, convey.ShouldNotBeNil)
  55. })
  56. })
  57. })
  58. }
  59. func TestDaoListAvBlackList(t *testing.T) {
  60. convey.Convey("ListAvBlackList", t, func(ctx convey.C) {
  61. var (
  62. c = context.Background()
  63. avIds = []int64{1000}
  64. typ = int(0)
  65. )
  66. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  67. Exec(c, "INSERT INTO av_black_list(av_id, ctype) VALUES(1000, 0) ON DUPLICATE KEY UPDATE ctype = 0")
  68. avb, err := d.ListAvBlackList(c, avIds, typ)
  69. ctx.Convey("Then err should be nil.avb should not be nil.", func(ctx convey.C) {
  70. ctx.So(err, convey.ShouldBeNil)
  71. ctx.So(avb, convey.ShouldNotBeNil)
  72. })
  73. })
  74. })
  75. }
  76. func TestDaoListActiveInfo(t *testing.T) {
  77. convey.Convey("ListActiveInfo", t, func(ctx convey.C) {
  78. var (
  79. c = context.Background()
  80. avIds = []int64{1000}
  81. )
  82. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  83. Exec(c, "INSERT INTO activity_info(archive_id, tag_id) VALUES(1000, 1)")
  84. acM, err := d.ListActiveInfo(c, avIds)
  85. ctx.Convey("Then err should be nil.acM should not be nil.", func(ctx convey.C) {
  86. ctx.So(err, convey.ShouldBeNil)
  87. ctx.So(acM, convey.ShouldNotBeNil)
  88. })
  89. })
  90. })
  91. }
  92. func TestDaoListTagInfo(t *testing.T) {
  93. convey.Convey("ListTagInfo", t, func(ctx convey.C) {
  94. var (
  95. c = context.Background()
  96. tagIds = []int64{1000}
  97. )
  98. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  99. Exec(c, "INSERT INTO tag_info(id, ratio, icon) VALUES(1000, 10, 'aaaaaa')")
  100. tagM, err := d.ListTagInfo(c, tagIds)
  101. ctx.Convey("Then err should be nil.tagM should not be nil.", func(ctx convey.C) {
  102. ctx.So(err, convey.ShouldBeNil)
  103. ctx.So(tagM, convey.ShouldNotBeNil)
  104. })
  105. })
  106. })
  107. }
  108. func TestDaoListUpIncome(t *testing.T) {
  109. convey.Convey("ListUpIncome", t, func(ctx convey.C) {
  110. var (
  111. c = context.Background()
  112. mid = int64(1001)
  113. table = "up_income"
  114. startTime = "2018-01-01"
  115. endTime = "2019-01-01"
  116. )
  117. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  118. Exec(c, "INSERT INTO up_income(mid, date) VALUES(1001, '2018-06-01')")
  119. ups, err := d.ListUpIncome(c, mid, table, startTime, endTime)
  120. ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
  121. ctx.So(err, convey.ShouldBeNil)
  122. ctx.So(ups, convey.ShouldNotBeNil)
  123. })
  124. })
  125. })
  126. }
  127. func TestDaoListUpAccount(t *testing.T) {
  128. convey.Convey("ListUpAccount", t, func(ctx convey.C) {
  129. var (
  130. c = context.Background()
  131. mid = int64(1001)
  132. )
  133. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  134. Exec(c, "INSERT INTO up_account(mid, is_deleted) VALUES(1001, 0) ON DUPLICATE KEY UPDATE is_deleted = 0")
  135. up, err := d.ListUpAccount(c, mid)
  136. ctx.Convey("Then err should be nil.up should not be nil.", func(ctx convey.C) {
  137. ctx.So(err, convey.ShouldBeNil)
  138. ctx.So(up, convey.ShouldNotBeNil)
  139. })
  140. })
  141. })
  142. }
  143. func TestDaoGetUpIncome(t *testing.T) {
  144. convey.Convey("GetUpIncome", t, func(ctx convey.C) {
  145. var (
  146. c = context.Background()
  147. mid = int64(1001)
  148. begin = "2018-01-01"
  149. end = "2019-01-01"
  150. )
  151. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  152. Exec(c, "INSERT INTO up_income(mid, date) VALUES(1001, '2018-06-01')")
  153. result, err := d.GetUpIncome(c, mid, begin, end)
  154. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  155. ctx.So(err, convey.ShouldBeNil)
  156. ctx.So(result, convey.ShouldNotBeNil)
  157. })
  158. })
  159. })
  160. }
  161. func TestDaoGetUpIncomeCount(t *testing.T) {
  162. convey.Convey("GetUpIncomeCount", t, func(ctx convey.C) {
  163. var (
  164. c = context.Background()
  165. date = "2018-06-01"
  166. )
  167. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  168. Exec(c, "INSERT INTO up_income(mid, date) VALUES(1001, '2018-06-01')")
  169. count, err := d.GetUpIncomeCount(c, date)
  170. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  171. ctx.So(err, convey.ShouldBeNil)
  172. ctx.So(count, convey.ShouldNotBeNil)
  173. })
  174. })
  175. })
  176. }