workDesktop_test.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. package service
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "fmt"
  6. "log"
  7. "testing"
  8. "time"
  9. "app.yhyue.com/moapp/jybase/redis"
  10. "bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
  11. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
  12. )
  13. var (
  14. ctx, _ = context.WithTimeout(context.Background(), 2*time.Second)
  15. )
  16. //工作桌面菜单树 无缓存
  17. //go test -run=Test_WorkDesktopMenuTree
  18. func Test_WorkDesktopMenuTree(t *testing.T) {
  19. tests := []struct {
  20. name string //备注(表名)
  21. args *pb.WorkDesktopMenuInfoReq //参数
  22. want string //期望值
  23. }{
  24. //类似表格数据
  25. {
  26. name: "PC端无缓存菜单树接口",
  27. args: &pb.WorkDesktopMenuInfoReq{
  28. UserId: "61e7820581197c2e50af18df",
  29. AppId: "10000",
  30. Platform: "PC",
  31. },
  32. want: "",
  33. },
  34. {
  35. name: "PC端有缓存菜单树接口",
  36. args: &pb.WorkDesktopMenuInfoReq{
  37. UserId: "61e7820581197c2e50af18df",
  38. AppId: "10000",
  39. Platform: "PC",
  40. },
  41. want: "",
  42. },
  43. {
  44. name: "WX端无缓存菜单树接口",
  45. args: &pb.WorkDesktopMenuInfoReq{
  46. UserId: "61e7820581197c2e50af18df",
  47. AppId: "10000",
  48. Platform: "WX",
  49. },
  50. want: "",
  51. },
  52. {
  53. name: "APP端无缓存菜单树接口",
  54. args: &pb.WorkDesktopMenuInfoReq{
  55. UserId: "61e7820581197c2e50af18df",
  56. AppId: "10000",
  57. Platform: "APP",
  58. },
  59. want: "",
  60. },
  61. }
  62. var redisMap = map[string]bool{}
  63. for _, in := range tests {
  64. t.Run(in.name, func(t *testing.T) {
  65. if !redisMap[in.args.Platform] {
  66. RedisMenuKey := fmt.Sprintf(entity.RedisMenuKey, in.args.AppId, in.args.Platform, MC.If(in.args.PositionId != "", in.args.PositionId, in.args.UserId).(string))
  67. redis.Del(entity.RedisCode, RedisMenuKey)
  68. }
  69. res, err := GetWordDesktopMenuTree(in.args)
  70. log.Println("err:", err, "---res:", res)
  71. if len(res) == 0 {
  72. log.Println(in.args.Platform, "异常:")
  73. }
  74. })
  75. }
  76. }
  77. // 菜单模式插入
  78. // go test -v -run Test_MenuMode
  79. func Test_MenuMode(t *testing.T) {
  80. var tests = []struct {
  81. name string
  82. args *pb.WorkDesktopComprehensiveReq
  83. want string
  84. }{
  85. {
  86. name: "工作桌面菜单模式插入",
  87. args: &pb.WorkDesktopComprehensiveReq{
  88. UserId: "61e7820581197c2e50af18df",
  89. NewUserId: "61e7820581197c2e50af18df",
  90. AppId: "10000",
  91. Platform: "PC",
  92. ActionMode: "menuMode",
  93. MenuMode: "usable",
  94. },
  95. want: "",
  96. },
  97. {
  98. name: "工作桌面菜单模式异常",
  99. args: &pb.WorkDesktopComprehensiveReq{
  100. UserId: "61e7820581197c2e50af18df",
  101. NewUserId: "61e7820581197c2e50af18df",
  102. AppId: "10000",
  103. Platform: "PC",
  104. ActionMode: "menuMode",
  105. MenuMode: "allll",
  106. },
  107. want: "",
  108. },
  109. {
  110. name: "工作桌面菜单模式更新",
  111. args: &pb.WorkDesktopComprehensiveReq{
  112. UserId: "61e7820581197c2e50af18df",
  113. NewUserId: "61e7820581197c2e50af18df",
  114. AppId: "10000",
  115. Platform: "PC",
  116. ActionMode: "menuMode",
  117. MenuMode: "all",
  118. },
  119. want: "",
  120. },
  121. }
  122. for _, in := range tests {
  123. t.Run(in.name, func(t *testing.T) {
  124. res := RenewWorkDesktopMenuModeOrCommonly(in.args)
  125. log.Println("menuModeNew:", res, in.want)
  126. })
  127. }
  128. }
  129. //当前工作桌面菜单模式
  130. // go test -v -run Test_WorkMenuMode
  131. func Test_WorkMenuMode(t *testing.T) {
  132. var tests = []struct {
  133. name string
  134. args *pb.WorkDesktopMenuInfoReq
  135. want string
  136. }{
  137. {
  138. name: "获取当前工作桌面菜单模式",
  139. args: &pb.WorkDesktopMenuInfoReq{
  140. UserId: "61e7820581197c2e50af18df",
  141. NewUserId: "61e7820581197c2e50af18df",
  142. AppId: "10000",
  143. Platform: "PC",
  144. },
  145. want: "",
  146. },
  147. {
  148. name: "异常获取当前工作桌面菜单模式",
  149. args: &pb.WorkDesktopMenuInfoReq{
  150. UserId: "",
  151. NewUserId: "",
  152. AppId: "10000",
  153. Platform: "PC",
  154. },
  155. want: "",
  156. },
  157. }
  158. for _, in := range tests {
  159. t.Run(in.name, func(t *testing.T) {
  160. res, err := GetWorkDesktopMenuMode(in.args)
  161. log.Println("err:", err, "---res:", res, in.want)
  162. })
  163. }
  164. }
  165. // 常用功能更新新增
  166. // go test -v -run Test_CommonlyRenewWX
  167. func Test_CommonlyRenewWX(t *testing.T) {
  168. in := &pb.WorkDesktopComprehensiveReq{
  169. UserId: "61e7820581197c2e50af18df",
  170. NewUserId: "61e7820581197c2e50af18df",
  171. AppId: "10000",
  172. Platform: "WX",
  173. Phone: "",
  174. ActionMode: "commonlyRenew",
  175. MenuMode: "",
  176. MenuIds: "Q1o=,TF4=,TFw=,TFg=,Q1g=,RV9F,RV9J,RV5B,RV5H,RV5J,TVg=",
  177. }
  178. res := RenewWorkDesktopMenuModeOrCommonly(in)
  179. log.Println("res:", res)
  180. }
  181. // 常用功能更新新增
  182. // go test -v -run Test_CommonlyRenewAPP
  183. func Test_CommonlyRenewAPP(t *testing.T) {
  184. in := &pb.WorkDesktopComprehensiveReq{
  185. UserId: "61e7820581197c2e50af18df",
  186. NewUserId: "61e7820581197c2e50af18df",
  187. AppId: "10000",
  188. Platform: "APP",
  189. Phone: "",
  190. ActionMode: "commonlyRenew",
  191. MenuMode: "",
  192. MenuIds: "Q1o=,TF4=,TFw=,TFg=,Q1g=,RV9F,RV9J,RV5B,RV5H,RV5J,TVg=",
  193. }
  194. res := RenewWorkDesktopMenuModeOrCommonly(in)
  195. log.Println("res:", res)
  196. }
  197. // 常用功能更新新增
  198. // go test -v -run Test_CommonlyRenew
  199. func Test_CommonlyRenew(t *testing.T) {
  200. in := &pb.WorkDesktopComprehensiveReq{
  201. UserId: "61e7820581197c2e50af18df",
  202. NewUserId: "61e7820581197c2e50af18df",
  203. AppId: "10000",
  204. Platform: "PC",
  205. Phone: "",
  206. ActionMode: "commonlyRenew",
  207. MenuMode: "",
  208. MenuIds: "Q1o=,TF4=,TFw=,TFg=,Q1g=,RV9F,RV9J,RV5B,RV5H,RV5J,TVg=",
  209. }
  210. res := RenewWorkDesktopMenuModeOrCommonly(in)
  211. log.Println("res:", res)
  212. }
  213. // 常用功能列表
  214. // go test -v -run Test_CommonlyList
  215. func Test_CommonlyList(t *testing.T) {
  216. in := &pb.WorkDesktopComprehensiveReq{
  217. UserId: "61e7820581197c2e50af18df",
  218. NewUserId: "61e7820581197c2e50af18df",
  219. AppId: "10000",
  220. Platform: "PC",
  221. Phone: "",
  222. ActionMode: "commonlyList",
  223. MenuMode: "",
  224. MenuIds: "",
  225. }
  226. res := RenewWorkDesktopMenuModeOrCommonly(in)
  227. log.Println("res:", res)
  228. } // 常用功能列表
  229. // go test -v -run Test_CommonlyListWX
  230. func Test_CommonlyListWX(t *testing.T) {
  231. in := &pb.WorkDesktopComprehensiveReq{
  232. UserId: "61e7820581197c2e50af18df",
  233. NewUserId: "61e7820581197c2e50af18df",
  234. AppId: "10000",
  235. Platform: "WX",
  236. Phone: "",
  237. ActionMode: "commonlyList",
  238. MenuMode: "",
  239. MenuIds: "",
  240. }
  241. res := RenewWorkDesktopMenuModeOrCommonly(in)
  242. log.Println("res:", res)
  243. } // 常用功能列表
  244. // go test -v -run Test_CommonlyListAPP
  245. func Test_CommonlyListAPP(t *testing.T) {
  246. in := &pb.WorkDesktopComprehensiveReq{
  247. UserId: "61e7820581197c2e50af18df",
  248. NewUserId: "61e7820581197c2e50af18df",
  249. AppId: "10000",
  250. Platform: "APP",
  251. Phone: "",
  252. ActionMode: "commonlyList",
  253. MenuMode: "",
  254. MenuIds: "",
  255. }
  256. res := RenewWorkDesktopMenuModeOrCommonly(in)
  257. log.Println("res:", res)
  258. }
  259. // 常用功能更新清空
  260. // go test -v -run Test_CommonlyRenew
  261. func Test_CommonlyClear(t *testing.T) {
  262. in := &pb.WorkDesktopComprehensiveReq{
  263. UserId: "61e7820581197c2e50af18df",
  264. NewUserId: "61e7820581197c2e50af18df",
  265. AppId: "10000",
  266. Platform: "PC",
  267. Phone: "",
  268. ActionMode: "commonlyRenew",
  269. MenuMode: "",
  270. MenuIds: "",
  271. }
  272. res := RenewWorkDesktopMenuModeOrCommonly(in)
  273. log.Println("res:", res)
  274. }