business_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/job/main/vip/model"
  7. xtime "go-common/library/time"
  8. "github.com/smartystreets/goconvey/convey"
  9. gock "gopkg.in/h2non/gock.v1"
  10. )
  11. // go test -test.v -test.run TestDaoSalaryCoupon
  12. func TestDaoSalaryCoupon(t *testing.T) {
  13. convey.Convey("TestDaoSalaryCoupon salary coupon", t, func() {
  14. var (
  15. c = context.TODO()
  16. mid int64 = 123
  17. ct int8 = 2
  18. count int64 = 2
  19. err error
  20. )
  21. err = d.SalaryCoupon(c, mid, ct, count, "cartoon_1_2018_06")
  22. convey.So(err, convey.ShouldBeNil)
  23. })
  24. }
  25. func TestDao_SendMultipMsg(t *testing.T) {
  26. convey.Convey("send multipmsg", t, func() {
  27. defer gock.OffAll()
  28. httpMock("POST", _message).Reply(200).JSON(`{"code":0,"data":1}`)
  29. err := d.SendMultipMsg(context.TODO(), "27515256", "test", "test", "10_1_2", 4)
  30. convey.So(err, convey.ShouldBeNil)
  31. })
  32. }
  33. func TestDaoPushData(t *testing.T) {
  34. pushData := &model.VipPushData{
  35. Title: "TEST",
  36. PushStartTime: "15:04:05",
  37. PushEndTime: "15:04:05",
  38. }
  39. convey.Convey("PushData", t, func() {
  40. defer gock.OffAll()
  41. httpMock("POST", _pushData).Reply(200).JSON(`{"code":0,"data":1}`)
  42. rel, err := d.PushData(context.TODO(), []int64{7593623}, pushData, "2006-01-02")
  43. convey.So(err, convey.ShouldBeNil)
  44. convey.So(rel, convey.ShouldNotBeNil)
  45. })
  46. }
  47. func TestDaoSendMedal(t *testing.T) {
  48. convey.Convey("SendMedal", t, func() {
  49. defer gock.OffAll()
  50. httpMock("GET", _sendMedal).Reply(200).JSON(`{"code":0,"data":{"status":1}}`)
  51. status := d.SendMedal(context.TODO(), 0, 0)
  52. convey.So(status, convey.ShouldNotBeNil)
  53. })
  54. }
  55. func TestDaoSendCleanCache(t *testing.T) {
  56. hv := &model.HandlerVip{Mid: 7593623}
  57. convey.Convey("SendCleanCache", t, func() {
  58. defer gock.OffAll()
  59. httpMock("GET", _cleanCache).Reply(200).JSON(`{"code":0,"data":{"status":1}}`)
  60. err := d.SendCleanCache(context.TODO(), hv)
  61. convey.So(err, convey.ShouldBeNil)
  62. })
  63. }
  64. func TestDaoSendBcoin(t *testing.T) {
  65. convey.Convey("SendBcoin", t, func() {
  66. defer gock.OffAll()
  67. httpMock("POST", _addBcoin).Reply(200).JSON(`{"code":0,"data":{"status":1}}`)
  68. err := d.SendBcoin(context.TODO(), []int64{7593623}, 0, xtime.Time(time.Now().Unix()), "")
  69. convey.So(err, convey.ShouldBeNil)
  70. })
  71. }
  72. func TestDaoSendAppCleanCache(t *testing.T) {
  73. var (
  74. hv = &model.HandlerVip{Mid: 7593623}
  75. app = &model.VipAppInfo{
  76. PurgeURL: "http://bilibili.com/test",
  77. }
  78. )
  79. convey.Convey("SendAppCleanCache", t, func() {
  80. defer gock.OffAll()
  81. httpMock("GET", app.PurgeURL).Reply(200).JSON(`{"code":0}`)
  82. err := d.SendAppCleanCache(context.TODO(), hv, app)
  83. convey.So(err, convey.ShouldBeNil)
  84. })
  85. }
  86. func TestDaosortParamsKey(t *testing.T) {
  87. var v map[string]string
  88. convey.Convey("sortParamsKey", t, func() {
  89. p1 := d.sortParamsKey(v)
  90. convey.So(p1, convey.ShouldNotBeNil)
  91. })
  92. }
  93. func TestDaoPaySign(t *testing.T) {
  94. var params map[string]string
  95. convey.Convey("PaySign", t, func() {
  96. sign := d.PaySign(params, "test")
  97. convey.So(sign, convey.ShouldNotBeNil)
  98. })
  99. }
  100. func TestDaodoNomalSend(t *testing.T) {
  101. var path = "/x/internal/vip/user/info"
  102. convey.Convey("doNomalSend", t, func() {
  103. defer gock.OffAll()
  104. httpMock("POST", path).Reply(200).JSON(`{"code":0}`)
  105. err := d.doNomalSend(context.TODO(), "http://api.bilibili.com", path, "", nil, nil, new(model.VipPushResq))
  106. convey.So(err, convey.ShouldBeNil)
  107. })
  108. }