workDesktop_test.go 7.7 KB

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