AuthService_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package service
  2. import (
  3. quitl "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/mysql"
  5. "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
  6. "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
  7. "fmt"
  8. "math/rand"
  9. "reflect"
  10. "testing"
  11. )
  12. func init() {
  13. entity.BaseMysql = &mysql.Mysql{
  14. Address: "192.168.3.217:4000",
  15. UserName: "root",
  16. PassWord: "=PDT49#80Z!RVv52_z",
  17. DBName: "base_service",
  18. MaxOpenConns: 5,
  19. MaxIdleConns: 5,
  20. }
  21. entity.BaseMysql.Init()
  22. }
  23. func TestAuthService_UserAuthInfo(t *testing.T) {
  24. type args struct {
  25. in *medical.CommonReq
  26. }
  27. tests := []struct {
  28. name string
  29. args args
  30. want *map[string]interface{}
  31. }{
  32. // TODO: Add test cases.
  33. {
  34. name: "用户认证信息-认证",
  35. args: args{
  36. &medical.CommonReq{
  37. UserId: "123",
  38. Appid: "10000",
  39. },
  40. },
  41. },
  42. {
  43. name: "用户认证信息-未认证",
  44. args: args{
  45. &medical.CommonReq{
  46. UserId: quitl.InterfaceToStr(rand.Int63n(100000000000)),
  47. },
  48. },
  49. },
  50. }
  51. for _, tt := range tests {
  52. t.Run(tt.name, func(t *testing.T) {
  53. b := AuthService{}
  54. if got := b.UserAuthInfo(tt.args.in); !reflect.DeepEqual(got, tt.want) {
  55. t.Errorf("UserAuthInfo() = %v, want %v", got, tt.want)
  56. }
  57. })
  58. }
  59. }
  60. func TestAuthService_UserAuthInfoSave(t *testing.T) {
  61. type args struct {
  62. in *medical.UserInfo
  63. }
  64. tests := []struct {
  65. name string
  66. args args
  67. want bool
  68. want1 string
  69. }{
  70. // TODO: Add test cases.
  71. {
  72. name: "用户认证信息保存",
  73. args: args{
  74. &medical.UserInfo{
  75. UserId: quitl.InterfaceToStr(rand.Int63n(100000000000)),
  76. Mail: "qqq.com",
  77. Phone: "13111111111",
  78. Name: fmt.Sprintf("用户%d", rand.Int63n(1000)),
  79. Position: "经理",
  80. Department: "公关",
  81. EntCode: "11111",
  82. EntName: "测试企业",
  83. OperationType: "add",
  84. Appid: "10000",
  85. },
  86. }},
  87. {
  88. name: "用户认证信息保存-用户已认证",
  89. args: args{
  90. &medical.UserInfo{
  91. UserId: "36685456029",
  92. Mail: "qqq.com",
  93. Phone: "13111111111",
  94. Name: fmt.Sprintf("用户%d", rand.Int63n(1000)),
  95. Position: "经理",
  96. Department: "公关",
  97. EntCode: "11111",
  98. EntName: "测试企业",
  99. OperationType: "add",
  100. Appid: "10000",
  101. },
  102. }},
  103. {
  104. name: "用户认证信息修改",
  105. args: args{
  106. &medical.UserInfo{
  107. UserId: "36685456029",
  108. Mail: "qqq.com",
  109. Phone: "13111111111",
  110. Name: fmt.Sprintf("用户%d", rand.Int63n(1000)),
  111. Position: "经理",
  112. Department: "公关",
  113. EntCode: "11111",
  114. EntName: "测试企业",
  115. OperationType: "update",
  116. Appid: "10000",
  117. },
  118. },
  119. },
  120. {
  121. name: "用户认证信息修改-未认证",
  122. args: args{
  123. &medical.UserInfo{
  124. UserId: "11111",
  125. Mail: "qqq.com",
  126. Phone: "13111111111",
  127. Name: fmt.Sprintf("用户%d", rand.Int63n(1000)),
  128. Position: "经理",
  129. Department: "公关",
  130. EntCode: "11111",
  131. EntName: "测试企业",
  132. OperationType: "update",
  133. Appid: "10000",
  134. },
  135. },
  136. },
  137. }
  138. for _, tt := range tests {
  139. t.Run(tt.name, func(t *testing.T) {
  140. b := AuthService{}
  141. got, got1 := b.UserAuthInfoSave(tt.args.in)
  142. if got != tt.want {
  143. t.Errorf("UserAuthInfoSave() got = %v, want %v", got, tt.want)
  144. }
  145. if got1 != tt.want1 {
  146. t.Errorf("UserAuthInfoSave() got1 = %v, want %v", got1, tt.want1)
  147. }
  148. })
  149. }
  150. }