raw_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. mml "go-common/app/service/main/member/model"
  6. bml "go-common/app/service/main/member/model/block"
  7. "go-common/library/ecode"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoRawInfo(t *testing.T) {
  11. var (
  12. c = context.TODO()
  13. mid = int64(110016481)
  14. )
  15. convey.Convey("Get base-info from member-rpc", t, func(ctx convey.C) {
  16. res, err := d.RawInfo(c, mid)
  17. ctx.Convey("Then err should be nil and res should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(res, convey.ShouldNotBeNil)
  20. })
  21. })
  22. }
  23. func TestDaoRawInfos(t *testing.T) {
  24. var (
  25. c = context.TODO()
  26. mids = []int64{110016811, 110017441}
  27. )
  28. convey.Convey("Batch get base-info from member-rpc", t, func(ctx convey.C) {
  29. res, err := d.RawInfos(c, mids)
  30. ctx.Convey("Then err should be nil and res should not be nil.", func(ctx convey.C) {
  31. ctx.So(err, convey.ShouldBeNil)
  32. ctx.So(res, convey.ShouldNotBeNil)
  33. })
  34. })
  35. }
  36. func TestDaoRawCard(t *testing.T) {
  37. var (
  38. c = context.TODO()
  39. mid = int64(110018101)
  40. )
  41. convey.Convey("Get card-info from member-rpc", t, func(ctx convey.C) {
  42. res, err := d.RawCard(c, mid)
  43. ctx.Convey("Then err should be nil and res should not be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. ctx.So(res, convey.ShouldNotBeNil)
  46. })
  47. })
  48. }
  49. func TestDaoRawCards(t *testing.T) {
  50. var (
  51. c = context.TODO()
  52. mids = []int64{110019691, 110019241}
  53. )
  54. convey.Convey("Batch get card-info from member-rpc", t, func(ctx convey.C) {
  55. res, err := d.RawCards(c, mids)
  56. ctx.Convey("Then err should be nil and res should not be nil.", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. ctx.So(res, convey.ShouldNotBeNil)
  59. })
  60. })
  61. }
  62. func TestDaoRawProfile(t *testing.T) {
  63. var (
  64. c = context.TODO()
  65. mid = int64(110019691)
  66. )
  67. convey.Convey("Get profile-info from member-rpc", t, func(ctx convey.C) {
  68. res, err := d.RawProfile(c, mid)
  69. if err == ecode.Degrade {
  70. err = nil
  71. }
  72. ctx.Convey("Then err should be nil and res should not be nil.", func(ctx convey.C) {
  73. ctx.So(err, convey.ShouldBeNil)
  74. ctx.So(res, convey.ShouldNotBeNil)
  75. })
  76. })
  77. }
  78. func TestDaoblockStatusToSilence(t *testing.T) {
  79. var (
  80. status bml.BlockStatus
  81. )
  82. convey.Convey("Check whether member in block status ", t, func(ctx convey.C) {
  83. p1 := blockStatusToSilence(status)
  84. ctx.Convey("Then p1 should be 0 or 1.", func(ctx convey.C) {
  85. ctx.So(p1, convey.ShouldBeIn, []int32{0, 1})
  86. })
  87. })
  88. }
  89. func TestDaobindEmailStatus(t *testing.T) {
  90. var (
  91. email = "zxfd43622@qq.com"
  92. spacesta = int8(0)
  93. )
  94. convey.Convey("Get member bind-email status", t, func(ctx convey.C) {
  95. p1 := bindEmailStatus(email, spacesta)
  96. ctx.Convey("Then p1 should be 0 or 1.", func(ctx convey.C) {
  97. ctx.So(p1, convey.ShouldBeIn, []int32{0, 1})
  98. })
  99. })
  100. }
  101. func TestDaobindPhoneStatus(t *testing.T) {
  102. var (
  103. phone = "13849920122"
  104. )
  105. convey.Convey("Get member bind-phone status", t, func(ctx convey.C) {
  106. p1 := bindPhoneStatus(phone)
  107. ctx.Convey("Then p1 should be 0 or 1.", func(ctx convey.C) {
  108. ctx.So(p1, convey.ShouldBeIn, []int32{0, 1})
  109. })
  110. })
  111. }
  112. func TestDaoparseMoral(t *testing.T) {
  113. var (
  114. moral = &mml.Moral{
  115. Mid: 3441,
  116. Moral: 7100,
  117. Added: 100,
  118. Deducted: 0,
  119. }
  120. )
  121. convey.Convey("Parse moral value", t, func(ctx convey.C) {
  122. p1 := parseMoral(moral)
  123. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  124. ctx.So(p1, convey.ShouldNotBeNil)
  125. })
  126. })
  127. }
  128. func TestDaoidentificationStatus(t *testing.T) {
  129. var (
  130. realNameStatus = mml.RealnameStatusTrue
  131. )
  132. convey.Convey("Get identification status", t, func(ctx convey.C) {
  133. p1 := identificationStatus(realNameStatus)
  134. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  135. ctx.So(p1, convey.ShouldEqual, 1)
  136. })
  137. })
  138. }
  139. func TestDaoboolToInt32(t *testing.T) {
  140. var (
  141. b = true
  142. )
  143. convey.Convey("Convert true to int", t, func(ctx convey.C) {
  144. p1 := boolToInt32(b)
  145. ctx.Convey("Then p1 should be 1.", func(ctx convey.C) {
  146. ctx.So(p1, convey.ShouldEqual, 1)
  147. })
  148. })
  149. }