workDesktop_test.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/redis"
  4. "context"
  5. "fmt"
  6. "log"
  7. "testing"
  8. "time"
  9. "userCenter/entity"
  10. "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. AppId: "10000",
  101. Platform: "PC",
  102. ActionMode: "menuMode",
  103. MenuMode: "usable",
  104. BigMemberOff: true,
  105. CommonlySize: 10,
  106. RedisOutTime: 1200,
  107. },
  108. want: "",
  109. },
  110. {
  111. name: "工作桌面菜单模式异常",
  112. args: &pb.WorkDesktopComprehensiveReq{
  113. UserId: "61e7820581197c2e50af18df",
  114. AppId: "10000",
  115. Platform: "PC",
  116. ActionMode: "menuMode",
  117. MenuMode: "allll",
  118. BigMemberOff: true,
  119. CommonlySize: 10,
  120. RedisOutTime: 1200,
  121. },
  122. want: "",
  123. },
  124. {
  125. name: "工作桌面菜单模式更新",
  126. args: &pb.WorkDesktopComprehensiveReq{
  127. UserId: "61e7820581197c2e50af18df",
  128. AppId: "10000",
  129. Platform: "PC",
  130. ActionMode: "menuMode",
  131. MenuMode: "all",
  132. BigMemberOff: true,
  133. CommonlySize: 10,
  134. RedisOutTime: 1200,
  135. },
  136. want: "",
  137. },
  138. }
  139. for _, in := range tests {
  140. t.Run(in.name, func(t *testing.T) {
  141. res := RenewWorkDesktopMenuModeOrCommonly(in.args)
  142. log.Println("menuModeNew:", res, in.want)
  143. })
  144. }
  145. }
  146. //当前工作桌面菜单模式
  147. // go test -v -run Test_WorkMenuMode
  148. func Test_WorkMenuMode(t *testing.T) {
  149. var tests = []struct {
  150. name string
  151. args *pb.WorkDesktopMenuInfoReq
  152. want string
  153. }{
  154. {
  155. name: "获取当前工作桌面菜单模式",
  156. args: &pb.WorkDesktopMenuInfoReq{
  157. UserId: "61e7820581197c2e50af18df",
  158. AppId: "10000",
  159. Platform: "PC",
  160. BigMemberOff: true,
  161. InternalTime: 1200,
  162. RedisOutTime: 1200,
  163. },
  164. want: "",
  165. },
  166. {
  167. name: "异常获取当前工作桌面菜单模式",
  168. args: &pb.WorkDesktopMenuInfoReq{
  169. UserId: "",
  170. AppId: "10000",
  171. Platform: "PC",
  172. BigMemberOff: true,
  173. InternalTime: 1200,
  174. RedisOutTime: 1200,
  175. },
  176. want: "",
  177. },
  178. }
  179. for _, in := range tests {
  180. t.Run(in.name, func(t *testing.T) {
  181. res, err := GetWorkDesktopMenuMode(in.args)
  182. log.Println("err:", err, "---res:", res, in.want)
  183. })
  184. }
  185. }
  186. // 常用功能更新新增
  187. // go test -v -run Test_CommonlyRenewWX
  188. func Test_CommonlyRenewWX(t *testing.T) {
  189. in := &pb.WorkDesktopComprehensiveReq{
  190. UserId: "61e7820581197c2e50af18df",
  191. AppId: "10000",
  192. Platform: "WX",
  193. Phone: "",
  194. ActionMode: "commonlyRenew",
  195. MenuMode: "",
  196. MenuIds: "Q1o=,TF4=,TFw=,TFg=,Q1g=,RV9F,RV9J,RV5B,RV5H,RV5J,TVg=",
  197. }
  198. res := RenewWorkDesktopMenuModeOrCommonly(in)
  199. log.Println("res:", res)
  200. }
  201. // 常用功能更新新增
  202. // go test -v -run Test_CommonlyRenewAPP
  203. func Test_CommonlyRenewAPP(t *testing.T) {
  204. in := &pb.WorkDesktopComprehensiveReq{
  205. UserId: "61e7820581197c2e50af18df",
  206. AppId: "10000",
  207. Platform: "APP",
  208. Phone: "",
  209. ActionMode: "commonlyRenew",
  210. MenuMode: "",
  211. MenuIds: "Q1o=,TF4=,TFw=,TFg=,Q1g=,RV9F,RV9J,RV5B,RV5H,RV5J,TVg=",
  212. }
  213. res := RenewWorkDesktopMenuModeOrCommonly(in)
  214. log.Println("res:", res)
  215. }
  216. // 常用功能更新新增
  217. // go test -v -run Test_CommonlyRenew
  218. func Test_CommonlyRenew(t *testing.T) {
  219. in := &pb.WorkDesktopComprehensiveReq{
  220. UserId: "61e7820581197c2e50af18df",
  221. AppId: "10000",
  222. Platform: "PC",
  223. Phone: "",
  224. ActionMode: "commonlyRenew",
  225. MenuMode: "",
  226. MenuIds: "Q1o=,TF4=,TFw=,TFg=,Q1g=,RV9F,RV9J,RV5B,RV5H,RV5J,TVg=",
  227. }
  228. res := RenewWorkDesktopMenuModeOrCommonly(in)
  229. log.Println("res:", res)
  230. }
  231. // 常用功能列表
  232. // go test -v -run Test_CommonlyList
  233. func Test_CommonlyList(t *testing.T) {
  234. in := &pb.WorkDesktopComprehensiveReq{
  235. UserId: "61e7820581197c2e50af18df",
  236. AppId: "10000",
  237. Platform: "PC",
  238. Phone: "",
  239. ActionMode: "commonlyList",
  240. MenuMode: "",
  241. MenuIds: "",
  242. }
  243. res := RenewWorkDesktopMenuModeOrCommonly(in)
  244. log.Println("res:", res)
  245. } // 常用功能列表
  246. // go test -v -run Test_CommonlyListWX
  247. func Test_CommonlyListWX(t *testing.T) {
  248. in := &pb.WorkDesktopComprehensiveReq{
  249. UserId: "61e7820581197c2e50af18df",
  250. AppId: "10000",
  251. Platform: "WX",
  252. Phone: "",
  253. ActionMode: "commonlyList",
  254. MenuMode: "",
  255. MenuIds: "",
  256. }
  257. res := RenewWorkDesktopMenuModeOrCommonly(in)
  258. log.Println("res:", res)
  259. } // 常用功能列表
  260. // go test -v -run Test_CommonlyListAPP
  261. func Test_CommonlyListAPP(t *testing.T) {
  262. in := &pb.WorkDesktopComprehensiveReq{
  263. UserId: "61e7820581197c2e50af18df",
  264. AppId: "10000",
  265. Platform: "APP",
  266. Phone: "",
  267. ActionMode: "commonlyList",
  268. MenuMode: "",
  269. MenuIds: "",
  270. }
  271. res := RenewWorkDesktopMenuModeOrCommonly(in)
  272. log.Println("res:", res)
  273. }
  274. // 常用功能更新清空
  275. // go test -v -run Test_CommonlyRenew
  276. func Test_CommonlyClear(t *testing.T) {
  277. in := &pb.WorkDesktopComprehensiveReq{
  278. UserId: "61e7820581197c2e50af18df",
  279. AppId: "10000",
  280. Platform: "PC",
  281. Phone: "",
  282. ActionMode: "commonlyRenew",
  283. MenuMode: "",
  284. MenuIds: "",
  285. }
  286. res := RenewWorkDesktopMenuModeOrCommonly(in)
  287. log.Println("res:", res)
  288. }