mid_info_test.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. "gopkg.in/h2non/gock.v1"
  7. )
  8. func TestDaoGetMidInfo(t *testing.T) {
  9. var (
  10. c = context.Background()
  11. qType = "1"
  12. qKey = "silg@yahoo.cn"
  13. )
  14. convey.Convey("GetMidInfo", t, func(ctx convey.C) {
  15. v, err := d.GetMidInfo(c, qType, qKey)
  16. ctx.Convey("Then err should be nil.v should not be nil.", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. ctx.So(v, convey.ShouldNotBeNil)
  19. })
  20. })
  21. }
  22. func TestDaoGetUserInfo(t *testing.T) {
  23. var (
  24. c = context.Background()
  25. mid = int64(1)
  26. )
  27. convey.Convey("GetUserInfo", t, func(ctx convey.C) {
  28. defer gock.OffAll()
  29. httpMock("GET", d.c.AccRecover.GetUserInfoURL).Reply(200).JSON(`{"code":0,"data":{"mid":21,"email":"raiden131@yahoo.cn","telphone":"","join_time":1245902140}}`)
  30. v, err := d.GetUserInfo(c, mid)
  31. ctx.Convey("Then err should be nil.v should not be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldBeNil)
  33. ctx.So(v, convey.ShouldNotBeNil)
  34. })
  35. })
  36. }
  37. func TestDaoUpdatePwd(t *testing.T) {
  38. var (
  39. c = context.Background()
  40. mid = int64(1)
  41. )
  42. convey.Convey("UpdatePwd", t, func(ctx convey.C) {
  43. defer gock.OffAll()
  44. httpMock("POST", d.c.AccRecover.UpPwdURL).Reply(200).JSON(`{"code": 0, "data":{"pwd":"d4txsunbb1","userid":"minorin"}}`)
  45. user, err := d.UpdatePwd(c, mid, "账号找回服务")
  46. ctx.So(err, convey.ShouldBeNil)
  47. ctx.So(user, convey.ShouldNotBeNil)
  48. })
  49. }
  50. func TestDaoCheckSafe(t *testing.T) {
  51. var (
  52. c = context.Background()
  53. mid = int64(1)
  54. question = int8(0)
  55. answer = "1"
  56. )
  57. convey.Convey("CheckSafe", t, func(ctx convey.C) {
  58. check, err := d.CheckSafe(c, mid, question, answer)
  59. ctx.Convey("Then err should be nil.check should not be nil.", func(ctx convey.C) {
  60. ctx.So(err, convey.ShouldBeNil)
  61. ctx.So(check, convey.ShouldNotBeNil)
  62. })
  63. })
  64. }
  65. //func httpMock(method, url string) *gock.Request {
  66. // r := gock.New(url)
  67. // r.Method = strings.ToUpper(method)
  68. // return r
  69. //}
  70. //func TestDaoGetUserType(t *testing.T) {
  71. // var (
  72. // c = context.Background()
  73. // mid = int64(2)
  74. // )
  75. // convey.Convey("When http request gets code != 0", t, func(ctx convey.C) {
  76. // defer gock.OffAll()
  77. // httpMock("GET", d.c.AccRecover.GameURL).Reply(0).JSON(`{"requestId":"0def8d70b7ef11e8a395fa163e01a2e9","ts":"1535440592","code":0,"items":[{"id":14,"name":"SDK测试2","lastLogin":"1500969010"}]}`)
  78. // games, err := d.GetUserType(c, mid)
  79. // ctx.So(err, convey.ShouldBeNil)
  80. // ctx.So(games, convey.ShouldNotBeNil)
  81. // })
  82. //}
  83. func TestDaoCheckReg(t *testing.T) {
  84. var (
  85. c = context.Background()
  86. mid = int64(1)
  87. regTime = int64(1532441644)
  88. regType = int8(0)
  89. regAddr = "中国_上海"
  90. )
  91. convey.Convey("CheckReg", t, func(ctx convey.C) {
  92. v, err := d.CheckReg(c, mid, regTime, regType, regAddr)
  93. ctx.Convey("Then err should be nil.v should not be nil.", func(ctx convey.C) {
  94. ctx.So(err, convey.ShouldBeNil)
  95. ctx.So(v, convey.ShouldNotBeNil)
  96. })
  97. })
  98. }
  99. func TestDaoUpdateBatchPwd(t *testing.T) {
  100. var (
  101. c = context.Background()
  102. mids = "1,2"
  103. )
  104. convey.Convey("UpdateBatchPwd", t, func(ctx convey.C) {
  105. defer gock.OffAll()
  106. httpMock("POST", d.c.AccRecover.UpBatchPwdURL).Reply(200).JSON(`{"code":0,"data":{"6":{"pwd":"tgs52r1st9","userid":"腹黑君"},"7":{"pwd":"g20ahzrf7j","userid":"Tzwcard"}}}`)
  107. userMap, err := d.UpdateBatchPwd(c, mids, "账号找回服务")
  108. ctx.So(err, convey.ShouldBeNil)
  109. ctx.So(userMap, convey.ShouldNotBeNil)
  110. })
  111. }
  112. func TestDaoCheckCard(t *testing.T) {
  113. var (
  114. c = context.Background()
  115. mid = int64(1)
  116. cardType = int8(1)
  117. cardCode = "123"
  118. )
  119. convey.Convey("CheckCard", t, func(ctx convey.C) {
  120. ok, err := d.CheckCard(c, mid, cardType, cardCode)
  121. ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. ctx.So(ok, convey.ShouldNotBeNil)
  124. })
  125. })
  126. }
  127. func TestDaoCheckPwds(t *testing.T) {
  128. var (
  129. c = context.Background()
  130. mid = int64(1)
  131. pwds = "123"
  132. )
  133. convey.Convey("CheckPwds", t, func(ctx convey.C) {
  134. v, err := d.CheckPwds(c, mid, pwds)
  135. ctx.Convey("Then err should be nil.v should not be nil.", func(ctx convey.C) {
  136. ctx.So(err, convey.ShouldBeNil)
  137. ctx.So(v, convey.ShouldNotBeNil)
  138. })
  139. })
  140. }
  141. func TestDaoGetLoginIPs(t *testing.T) {
  142. var (
  143. c = context.Background()
  144. mid = int64(2)
  145. limit = int64(10)
  146. )
  147. convey.Convey("GetLoginIPs", t, func(ctx convey.C) {
  148. ipInfo, err := d.GetLoginIPs(c, mid, limit)
  149. ctx.Convey("Then err should be nil.ipInfo should not be nil.", func(ctx convey.C) {
  150. ctx.So(err, convey.ShouldBeNil)
  151. ctx.So(ipInfo, convey.ShouldNotBeNil)
  152. })
  153. })
  154. }
  155. func TestDaoGetAddrByIP(t *testing.T) {
  156. var (
  157. c = context.Background()
  158. mid = int64(111001254)
  159. limit = int64(10)
  160. )
  161. convey.Convey("GetAddrByIP", t, func(ctx convey.C) {
  162. addrs, err := d.GetAddrByIP(c, mid, limit)
  163. ctx.Convey("Then err should be nil.addrs should not be nil.", func(ctx convey.C) {
  164. ctx.So(err, convey.ShouldBeNil)
  165. ctx.So(addrs, convey.ShouldNotBeNil)
  166. })
  167. })
  168. }