db_wechat_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package dao
  2. import (
  3. "testing"
  4. "go-common/app/admin/ep/saga/model"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestQueryUserByUserName(t *testing.T) {
  8. convey.Convey("Test QueryUserByUserName", t, func(ctx convey.C) {
  9. contactInfo, err := d.QueryUserByUserName("zhanglin")
  10. ctx.Convey("The err should be nil.", func(ctx convey.C) {
  11. ctx.So(err, convey.ShouldBeNil)
  12. ctx.So(contactInfo.NickName, convey.ShouldEqual, "木木哥")
  13. ctx.So(contactInfo.UserID, convey.ShouldEqual, "003207")
  14. })
  15. })
  16. }
  17. func TestQueryUserByID(t *testing.T) {
  18. convey.Convey("Test QueryUserByID", t, func(ctx convey.C) {
  19. contactInfo, err := d.QueryUserByID("003207")
  20. ctx.Convey("The err should be nil.", func(ctx convey.C) {
  21. ctx.So(err, convey.ShouldBeNil)
  22. ctx.So(contactInfo.UserName, convey.ShouldEqual, "zhanglin")
  23. ctx.So(contactInfo.NickName, convey.ShouldEqual, "木木哥")
  24. })
  25. })
  26. }
  27. func TestUserIds(t *testing.T) {
  28. convey.Convey("Test UserIds", t, func(ctx convey.C) {
  29. var (
  30. userNames = []string{"zhanglin", "wuwei"}
  31. )
  32. userIds, err := d.UserIds(userNames)
  33. ctx.Convey("The err should be nil.", func(ctx convey.C) {
  34. ctx.So(err, convey.ShouldBeNil)
  35. ctx.So(userIds, convey.ShouldEqual, "003207|001396")
  36. })
  37. })
  38. }
  39. func TestWechatContact(t *testing.T) {
  40. convey.Convey("test wechat contact", t, func(ctx convey.C) {
  41. var (
  42. ID = "111"
  43. )
  44. contact := &model.ContactInfo{
  45. ID: ID,
  46. UserName: "lisi",
  47. UserID: "222",
  48. NickName: "sansan",
  49. VisibleSaga: true,
  50. }
  51. contactUpdate := &model.ContactInfo{
  52. ID: ID,
  53. UserName: "zhan",
  54. UserID: "333",
  55. NickName: "sansan",
  56. VisibleSaga: true,
  57. }
  58. ctx.Convey("set contact", func(ctx convey.C) {
  59. err := d.CreateContact(contact)
  60. ctx.Convey("set err should be nil.", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. })
  63. })
  64. ctx.Convey("update contact", func(ctx convey.C) {
  65. err := d.UptContact(contactUpdate)
  66. ctx.Convey("get err should be nil.", func(ctx convey.C) {
  67. ctx.So(err, convey.ShouldBeNil)
  68. })
  69. })
  70. ctx.Convey("delete contact", func(ctx convey.C) {
  71. err := d.DelContact(contactUpdate)
  72. ctx.Convey("get err should be nil.", func(ctx convey.C) {
  73. ctx.So(err, convey.ShouldBeNil)
  74. })
  75. })
  76. })
  77. }
  78. func TestWechatCreateLog(t *testing.T) {
  79. convey.Convey("test wechat create log", t, func(ctx convey.C) {
  80. info := &model.WechatCreateLog{
  81. Name: "lisi",
  82. Owner: "zhanglin",
  83. ChatID: "333",
  84. Cuser: "333",
  85. }
  86. info1 := &model.WechatCreateLog{
  87. Name: "lisi",
  88. }
  89. ctx.Convey("set wechat log", func(ctx convey.C) {
  90. err := d.AddWechatCreateLog(info)
  91. ctx.Convey("set err should be nil.", func(ctx convey.C) {
  92. ctx.So(err, convey.ShouldBeNil)
  93. })
  94. })
  95. ctx.Convey("query wechat log", func(ctx convey.C) {
  96. infos, total, err := d.QueryWechatCreateLog(false, nil, info1)
  97. ctx.Convey("query err should be nil.", func(ctx convey.C) {
  98. ctx.So(err, convey.ShouldBeNil)
  99. ctx.So(total, convey.ShouldBeGreaterThanOrEqualTo, 1)
  100. ctx.So(infos[0].Name, convey.ShouldEqual, "lisi")
  101. })
  102. })
  103. })
  104. }