depend_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/job/main/credit/model"
  6. . "github.com/smartystreets/goconvey/convey"
  7. "gopkg.in/h2non/gock.v1"
  8. )
  9. func Test_SendPendant(t *testing.T) {
  10. Convey("should return err be nil", t, func() {
  11. err := d.SendPendant(context.TODO(), 27515305, []int64{83, 84}, 30)
  12. So(err, ShouldBeNil)
  13. })
  14. }
  15. func Test_SendMedal(t *testing.T) {
  16. Convey("should return err be nil", t, func() {
  17. defer gock.OffAll()
  18. httpMock("POST", d.sendMedalURL).Reply(200).JSON(`{"code":0}`)
  19. err := d.SendMedal(context.TODO(), 27515305, 4)
  20. So(err, ShouldBeNil)
  21. })
  22. }
  23. func Test_DelTag(t *testing.T) {
  24. Convey("should return err be nil", t, func() {
  25. defer gock.OffAll()
  26. httpMock("POST", d.delTagURL).Reply(200).JSON(`{"code":0}`)
  27. err := d.DelTag(context.TODO(), "1", "4")
  28. So(err, ShouldBeNil)
  29. })
  30. }
  31. func Test_ReportDM(t *testing.T) {
  32. Convey("should return err be nil", t, func() {
  33. defer gock.OffAll()
  34. httpMock("POST", d.delDMURL).Reply(200).JSON(`{"code":0}`)
  35. err := d.ReportDM(context.TODO(), "1", "4", 1)
  36. So(err, ShouldBeNil)
  37. })
  38. }
  39. func Test_BlockAccount(t *testing.T) {
  40. var bi = &model.BlockedInfo{}
  41. bi.UID = 27515305
  42. Convey("should return err be nil", t, func() {
  43. err := d.BlockAccount(context.TODO(), bi)
  44. So(err, ShouldBeNil)
  45. })
  46. }
  47. func TestDaoUnBlockAccount(t *testing.T) {
  48. var bi = &model.BlockedInfo{}
  49. bi.UID = 27515305
  50. Convey("should return err be nil", t, func() {
  51. err := d.UnBlockAccount(context.TODO(), bi)
  52. So(err, ShouldBeNil)
  53. })
  54. }
  55. func Test_SendMsg(t *testing.T) {
  56. Convey("should return err be nil", t, func() {
  57. defer gock.OffAll()
  58. httpMock("POST", d.sendMsgURL).Reply(200).JSON(`{"code":0}`)
  59. err := d.SendMsg(context.TODO(), 88889017, "风纪委员任期结束", "您的风纪委员资格已到期,任职期间的总结报告已生成。感谢您对社区工作的大力支持!#{点击查看}{"+"\"http://www.bilibili.com/judgement/\""+"}")
  60. So(err, ShouldBeNil)
  61. })
  62. }
  63. func TestDaoSms(t *testing.T) {
  64. Convey("should return err be nil", t, func() {
  65. defer gock.OffAll()
  66. httpMock("GET", "http://ops-mng.bilibili.co/api/sendsms").Reply(200).JSON(`{"code":0}`)
  67. err := d.Sms(context.TODO(), "13888888888", "1232131", "hahh1")
  68. So(err, ShouldBeNil)
  69. })
  70. }
  71. func Test_AddMoral(t *testing.T) {
  72. Convey("should return err be nil", t, func() {
  73. err := d.AddMoral(context.TODO(), 27515305, -10, 1, "credit", "reason", "风纪委处罚", "")
  74. So(err, ShouldBeNil)
  75. })
  76. }
  77. func Test_AddMoney(t *testing.T) {
  78. Convey("should return err be nil", t, func() {
  79. err := d.AddMoney(context.TODO(), 27956255, 10, "风纪委奖励")
  80. So(err, ShouldBeNil)
  81. })
  82. }
  83. func TestDaoCheckFilter(t *testing.T) {
  84. Convey("should return err be nil", t, func() {
  85. res, err := d.CheckFilter(context.TODO(), "credit", "lalsdal1", "127.0.0.1")
  86. So(err, ShouldBeNil)
  87. So(res, ShouldNotBeNil)
  88. })
  89. }
  90. func TestDaoUpAppealState(t *testing.T) {
  91. Convey("UpAppealState", t, func(ctx C) {
  92. var (
  93. c = context.Background()
  94. bid = model.AppealBusinessID
  95. oid = int64(1)
  96. eid = int64(1)
  97. )
  98. ctx.Convey("When everything goes positive", func(ctx C) {
  99. defer gock.OffAll()
  100. httpMock("POST", d.upAppealStateURL).Reply(200).JSON(`{"code":0}`)
  101. err := d.UpAppealState(c, bid, oid, eid)
  102. ctx.Convey("Then err should be nil.", func(ctx C) {
  103. ctx.So(err, ShouldBeNil)
  104. })
  105. })
  106. })
  107. }