banner_test.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package test
  2. import (
  3. "erpims/application/domain/banner"
  4. "git.sxidc.com/go-framework/baize/framework/core/api/request"
  5. "git.sxidc.com/go-framework/baize/framework/core/api/response"
  6. "git.sxidc.com/go-tools/utils/strutils"
  7. "math/rand"
  8. "net/http"
  9. "strconv"
  10. "testing"
  11. )
  12. func TestBanner(t *testing.T) {
  13. Init()
  14. defer Destroy()
  15. var bannerID string
  16. var totalCount int64
  17. bannerInfo := new(banner.Info)
  18. bannerInfos := make([]banner.Info, 0)
  19. createUserID := strutils.SimpleUUID()
  20. updateUserID := strutils.SimpleUUID()
  21. deleteUserID := strutils.SimpleUUID()
  22. operatorUserName := strutils.SimpleUUID()
  23. title := strutils.SimpleUUID()
  24. pageUrl := strutils.SimpleUUID()
  25. picUrl := strutils.SimpleUUID()
  26. status := int(rand.Int())
  27. newTitle := strutils.SimpleUUID()
  28. newPageUrl := strutils.SimpleUUID()
  29. newPicUrl := strutils.SimpleUUID()
  30. newStatus := int(rand.Int())
  31. NewToolKit(t).CreateBanner(title, pageUrl, picUrl, status, createUserID, operatorUserName, &bannerID).
  32. GetBanner(bannerID, bannerInfo).
  33. AssertEqual(bannerID, bannerInfo.ID, "宣传图ID不一致").
  34. AssertEqual(title, bannerInfo.Title, "宣传图标题不一致").
  35. AssertEqual(pageUrl, bannerInfo.PageUrl, "宣传图页面路径不一致").
  36. AssertEqual(picUrl, bannerInfo.PicUrl, "宣传图图片地址不一致").
  37. AssertEqual(status, bannerInfo.Status, "宣传图状态 1隐藏,2显示不一致").
  38. AssertEqual(createUserID, bannerInfo.CreateUserID, "创建用户ID不一致").
  39. AssertEqual(createUserID, bannerInfo.LastUpdateUserID, "最近更新用户ID不一致").
  40. AssertNotEmpty(bannerInfo.CreatedTime, "创建时间为空").
  41. AssertNotEmpty(bannerInfo.LastUpdatedTime, "最近更新时间为空").
  42. GetBanners(title, pageUrl, picUrl, status, "1", "1", &bannerInfos, &totalCount).
  43. AssertEqual(int(totalCount), len(bannerInfos), "总数不一致").
  44. AssertEqual(bannerID, bannerInfos[0].ID, "宣传图ID不一致").
  45. AssertEqual(title, bannerInfos[0].Title, "宣传图标题不一致").
  46. AssertEqual(pageUrl, bannerInfos[0].PageUrl, "宣传图页面路径不一致").
  47. AssertEqual(picUrl, bannerInfos[0].PicUrl, "宣传图图片地址不一致").
  48. AssertEqual(status, bannerInfos[0].Status, "宣传图状态 1隐藏,2显示不一致").
  49. AssertEqual(createUserID, bannerInfos[0].CreateUserID, "创建用户ID不一致").
  50. AssertEqual(createUserID, bannerInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  51. AssertNotEmpty(bannerInfos[0].CreatedTime, "创建时间为空").
  52. AssertNotEmpty(bannerInfos[0].LastUpdatedTime, "最近更新时间为空").
  53. GetBanners(title, pageUrl, picUrl, status, "0", "0", &bannerInfos, &totalCount).
  54. AssertEqual(int(totalCount), len(bannerInfos), "总数不一致").
  55. AssertEqual(1, len(bannerInfos), "宣传图数应当为1").
  56. AssertEqual(bannerID, bannerInfos[0].ID, "宣传图ID不一致").
  57. AssertEqual(title, bannerInfos[0].Title, "宣传图标题不一致").
  58. AssertEqual(pageUrl, bannerInfos[0].PageUrl, "宣传图页面路径不一致").
  59. AssertEqual(picUrl, bannerInfos[0].PicUrl, "宣传图图片地址不一致").
  60. AssertEqual(status, bannerInfos[0].Status, "宣传图状态 1隐藏,2显示不一致").
  61. AssertEqual(createUserID, bannerInfos[0].CreateUserID, "创建用户ID不一致").
  62. AssertEqual(createUserID, bannerInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  63. AssertNotEmpty(bannerInfos[0].CreatedTime, "创建时间为空").
  64. AssertNotEmpty(bannerInfos[0].LastUpdatedTime, "最近更新时间为空").
  65. UpdateBanner(bannerID, newTitle, newPageUrl, newPicUrl, newStatus, updateUserID, operatorUserName).
  66. GetBanners(newTitle, newPageUrl, newPicUrl, newStatus, "1", "1", &bannerInfos, &totalCount).
  67. AssertEqual(int(totalCount), len(bannerInfos), "总数不一致").
  68. AssertEqual(bannerID, bannerInfos[0].ID, "宣传图ID不一致").
  69. AssertEqual(newTitle, bannerInfos[0].Title, "宣传图标题不一致").
  70. AssertEqual(newPageUrl, bannerInfos[0].PageUrl, "宣传图页面路径不一致").
  71. AssertEqual(newPicUrl, bannerInfos[0].PicUrl, "宣传图图片地址不一致").
  72. AssertEqual(newStatus, bannerInfos[0].Status, "宣传图状态 1隐藏,2显示不一致").
  73. AssertEqual(createUserID, bannerInfos[0].CreateUserID, "创建用户ID不一致").
  74. AssertEqual(updateUserID, bannerInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  75. AssertNotEmpty(bannerInfos[0].CreatedTime, "创建时间为空").
  76. AssertNotEmpty(bannerInfos[0].LastUpdatedTime, "最近更新时间为空").
  77. DeleteBanner(bannerID, deleteUserID, operatorUserName).
  78. GetBanners(newTitle, newPageUrl, newPicUrl, newStatus, "1", "1", &bannerInfos, &totalCount).
  79. AssertEqual(int(totalCount), len(bannerInfos), "总数不一致").
  80. AssertEqual(0, len(bannerInfos), "删除宣传图失败")
  81. }
  82. /* HAC: TEST RELATION FUNCTIONS */
  83. /* HAC: END TEST RELATION FUNCTIONS */
  84. func (toolKit *ToolKit) CreateBanner(title string, pageUrl string, picUrl string, status int, createUserID string, operatorUserName string, bannerID *string) *ToolKit {
  85. idResponse := new(response.IDResponse)
  86. toolKit.SetHeader("Content-Type", "application/json").
  87. SetJsonBody(&banner.CreateBannerJsonBody{
  88. Title: title, PageUrl: pageUrl, PicUrl: picUrl, Status: status,
  89. CreateUserIDJsonBody: request.CreateUserIDJsonBody{CreateUserID: createUserID},
  90. OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName},
  91. }).
  92. SetJsonResponse(idResponse).
  93. Request("/erpims/api/v1/banner/create", http.MethodPost).
  94. AssertStatusCode(http.StatusOK).
  95. AssertEqual(true, idResponse.Success, idResponse.Msg).
  96. AssertNotEmpty(idResponse.ID, "宣传图ID为空")
  97. if bannerID != nil {
  98. *bannerID = idResponse.ID
  99. }
  100. return toolKit
  101. }
  102. func (toolKit *ToolKit) DeleteBanner(id string, deleteUserID string, operatorUserName string) *ToolKit {
  103. msgResponse := new(response.MsgResponse)
  104. toolKit.SetHeader("Content-Type", "application/json").
  105. SetJsonResponse(msgResponse).
  106. SetQueryParams("id", id).
  107. SetQueryParams("deleteUserId", deleteUserID).
  108. SetQueryParams("operatorUserName", operatorUserName).
  109. Request("/erpims/api/v1/banner/delete", http.MethodDelete).
  110. AssertStatusCode(http.StatusOK).
  111. AssertEqual(true, msgResponse.Success, msgResponse.Msg)
  112. return toolKit
  113. }
  114. func (toolKit *ToolKit) UpdateBanner(id string, title string, pageUrl string, picUrl string, status int, updateUserID string, operatorUserName string) *ToolKit {
  115. msgResponse := new(response.MsgResponse)
  116. toolKit.SetHeader("Content-Type", "application/json").
  117. SetJsonBody(&banner.UpdateBannerJsonBody{
  118. IDJsonBody: request.IDJsonBody{ID: id},
  119. Title: title,
  120. PageUrl: pageUrl,
  121. PicUrl: picUrl,
  122. Status: status,
  123. UpdateUserIDJsonBody: request.UpdateUserIDJsonBody{UpdateUserID: updateUserID},
  124. OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName},
  125. }).
  126. SetJsonResponse(msgResponse).
  127. Request("/erpims/api/v1/banner/update", http.MethodPut).
  128. AssertStatusCode(http.StatusOK).
  129. AssertEqual(true, msgResponse.Success, msgResponse.Msg)
  130. return toolKit
  131. }
  132. func (toolKit *ToolKit) GetBanners(title string, pageUrl string, picUrl string, status int, pageNo string, pageSize string, retInfos *[]banner.Info, retTotalCount *int64) *ToolKit {
  133. infosResponse := new(response.InfosResponse[banner.Info])
  134. toolKit.SetHeader("Content-Type", "application/json").
  135. SetJsonResponse(infosResponse).
  136. SetQueryParams("title", title).
  137. SetQueryParams("pageUrl", pageUrl).
  138. SetQueryParams("picUrl", picUrl).
  139. SetQueryParams("status", strconv.FormatInt(int64(status), 10)).
  140. SetQueryParams("pageNo", pageNo).
  141. SetQueryParams("pageSize", pageSize).
  142. Request("/erpims/api/v1/banner/query", http.MethodGet).
  143. AssertStatusCode(http.StatusOK).
  144. AssertEqual(true, infosResponse.Success, infosResponse.Msg)
  145. if retInfos != nil {
  146. *retInfos = make([]banner.Info, 0)
  147. *retInfos = append(*retInfos, infosResponse.Infos...)
  148. }
  149. if retTotalCount != nil {
  150. *retTotalCount = infosResponse.TotalCount
  151. }
  152. return toolKit
  153. }
  154. func (toolKit *ToolKit) GetBanner(id string, retInfo *banner.Info) *ToolKit {
  155. infoResponse := new(response.InfoResponse[*banner.Info])
  156. toolKit.SetHeader("Content-Type", "application/json").
  157. SetJsonResponse(infoResponse).
  158. SetQueryParams("id", id).
  159. Request("/erpims/api/v1/banner/get", http.MethodGet).
  160. AssertStatusCode(http.StatusOK).
  161. AssertEqual(true, infoResponse.Success, infoResponse.Msg)
  162. if retInfo != nil {
  163. *retInfo = banner.Info{}
  164. *retInfo = *infoResponse.Info
  165. }
  166. return toolKit
  167. }
  168. /* HAC: TEST RELATION METHODS */
  169. /* HAC: END TEST RELATION METHODS */