advertising_test.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package test
  2. import (
  3. "erpims/application/domain/advertising"
  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 TestAdvertising(t *testing.T) {
  13. Init()
  14. defer Destroy()
  15. var advertisingID string
  16. var totalCount int64
  17. advertisingInfo := new(advertising.Info)
  18. advertisingInfos := make([]advertising.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).CreateAdvertising(title, pageUrl, picUrl, status, createUserID, operatorUserName, &advertisingID).
  32. GetAdvertising(advertisingID, advertisingInfo).
  33. AssertEqual(advertisingID, advertisingInfo.ID, "广告配置ID不一致").
  34. AssertEqual(title, advertisingInfo.Title, "广告配置标题不一致").
  35. AssertEqual(pageUrl, advertisingInfo.PageUrl, "广告配置页面路径不一致").
  36. AssertEqual(picUrl, advertisingInfo.PicUrl, "广告配置图片地址不一致").
  37. AssertEqual(status, advertisingInfo.Status, "广告配置状态 1隐藏,2显示不一致").
  38. AssertEqual(createUserID, advertisingInfo.CreateUserID, "创建用户ID不一致").
  39. AssertEqual(createUserID, advertisingInfo.LastUpdateUserID, "最近更新用户ID不一致").
  40. AssertNotEmpty(advertisingInfo.CreatedTime, "创建时间为空").
  41. AssertNotEmpty(advertisingInfo.LastUpdatedTime, "最近更新时间为空").
  42. GetAdvertisings(title, pageUrl, picUrl, status, "1", "1", &advertisingInfos, &totalCount).
  43. AssertEqual(int(totalCount), len(advertisingInfos), "总数不一致").
  44. AssertEqual(advertisingID, advertisingInfos[0].ID, "广告配置ID不一致").
  45. AssertEqual(title, advertisingInfos[0].Title, "广告配置标题不一致").
  46. AssertEqual(pageUrl, advertisingInfos[0].PageUrl, "广告配置页面路径不一致").
  47. AssertEqual(picUrl, advertisingInfos[0].PicUrl, "广告配置图片地址不一致").
  48. AssertEqual(status, advertisingInfos[0].Status, "广告配置状态 1隐藏,2显示不一致").
  49. AssertEqual(createUserID, advertisingInfos[0].CreateUserID, "创建用户ID不一致").
  50. AssertEqual(createUserID, advertisingInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  51. AssertNotEmpty(advertisingInfos[0].CreatedTime, "创建时间为空").
  52. AssertNotEmpty(advertisingInfos[0].LastUpdatedTime, "最近更新时间为空").
  53. GetAdvertisings(title, pageUrl, picUrl, status, "0", "0", &advertisingInfos, &totalCount).
  54. AssertEqual(int(totalCount), len(advertisingInfos), "总数不一致").
  55. AssertEqual(1, len(advertisingInfos), "广告配置数应当为1").
  56. AssertEqual(advertisingID, advertisingInfos[0].ID, "广告配置ID不一致").
  57. AssertEqual(title, advertisingInfos[0].Title, "广告配置标题不一致").
  58. AssertEqual(pageUrl, advertisingInfos[0].PageUrl, "广告配置页面路径不一致").
  59. AssertEqual(picUrl, advertisingInfos[0].PicUrl, "广告配置图片地址不一致").
  60. AssertEqual(status, advertisingInfos[0].Status, "广告配置状态 1隐藏,2显示不一致").
  61. AssertEqual(createUserID, advertisingInfos[0].CreateUserID, "创建用户ID不一致").
  62. AssertEqual(createUserID, advertisingInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  63. AssertNotEmpty(advertisingInfos[0].CreatedTime, "创建时间为空").
  64. AssertNotEmpty(advertisingInfos[0].LastUpdatedTime, "最近更新时间为空").
  65. UpdateAdvertising(advertisingID, newTitle, newPageUrl, newPicUrl, newStatus, updateUserID, operatorUserName).
  66. GetAdvertisings(newTitle, newPageUrl, newPicUrl, newStatus, "1", "1", &advertisingInfos, &totalCount).
  67. AssertEqual(int(totalCount), len(advertisingInfos), "总数不一致").
  68. AssertEqual(advertisingID, advertisingInfos[0].ID, "广告配置ID不一致").
  69. AssertEqual(newTitle, advertisingInfos[0].Title, "广告配置标题不一致").
  70. AssertEqual(newPageUrl, advertisingInfos[0].PageUrl, "广告配置页面路径不一致").
  71. AssertEqual(newPicUrl, advertisingInfos[0].PicUrl, "广告配置图片地址不一致").
  72. AssertEqual(newStatus, advertisingInfos[0].Status, "广告配置状态 1隐藏,2显示不一致").
  73. AssertEqual(createUserID, advertisingInfos[0].CreateUserID, "创建用户ID不一致").
  74. AssertEqual(updateUserID, advertisingInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  75. AssertNotEmpty(advertisingInfos[0].CreatedTime, "创建时间为空").
  76. AssertNotEmpty(advertisingInfos[0].LastUpdatedTime, "最近更新时间为空").
  77. DeleteAdvertising(advertisingID, deleteUserID, operatorUserName).
  78. GetAdvertisings(newTitle, newPageUrl, newPicUrl, newStatus, "1", "1", &advertisingInfos, &totalCount).
  79. AssertEqual(int(totalCount), len(advertisingInfos), "总数不一致").
  80. AssertEqual(0, len(advertisingInfos), "删除广告配置失败")
  81. }
  82. /* HAC: TEST RELATION FUNCTIONS */
  83. /* HAC: END TEST RELATION FUNCTIONS */
  84. func (toolKit *ToolKit) CreateAdvertising(title string, pageUrl string, picUrl string, status int, createUserID string, operatorUserName string, advertisingID *string) *ToolKit {
  85. idResponse := new(response.IDResponse)
  86. toolKit.SetHeader("Content-Type", "application/json").
  87. SetJsonBody(&advertising.CreateAdvertisingJsonBody{
  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/advertising/create", http.MethodPost).
  94. AssertStatusCode(http.StatusOK).
  95. AssertEqual(true, idResponse.Success, idResponse.Msg).
  96. AssertNotEmpty(idResponse.ID, "广告配置ID为空")
  97. if advertisingID != nil {
  98. *advertisingID = idResponse.ID
  99. }
  100. return toolKit
  101. }
  102. func (toolKit *ToolKit) DeleteAdvertising(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/advertising/delete", http.MethodDelete).
  110. AssertStatusCode(http.StatusOK).
  111. AssertEqual(true, msgResponse.Success, msgResponse.Msg)
  112. return toolKit
  113. }
  114. func (toolKit *ToolKit) UpdateAdvertising(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(&advertising.UpdateAdvertisingJsonBody{
  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/advertising/update", http.MethodPut).
  128. AssertStatusCode(http.StatusOK).
  129. AssertEqual(true, msgResponse.Success, msgResponse.Msg)
  130. return toolKit
  131. }
  132. func (toolKit *ToolKit) GetAdvertisings(title string, pageUrl string, picUrl string, status int, pageNo string, pageSize string, retInfos *[]advertising.Info, retTotalCount *int64) *ToolKit {
  133. infosResponse := new(response.InfosResponse[advertising.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/advertising/query", http.MethodGet).
  143. AssertStatusCode(http.StatusOK).
  144. AssertEqual(true, infosResponse.Success, infosResponse.Msg)
  145. if retInfos != nil {
  146. *retInfos = make([]advertising.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) GetAdvertising(id string, retInfo *advertising.Info) *ToolKit {
  155. infoResponse := new(response.InfoResponse[*advertising.Info])
  156. toolKit.SetHeader("Content-Type", "application/json").
  157. SetJsonResponse(infoResponse).
  158. SetQueryParams("id", id).
  159. Request("/erpims/api/v1/advertising/get", http.MethodGet).
  160. AssertStatusCode(http.StatusOK).
  161. AssertEqual(true, infoResponse.Success, infoResponse.Msg)
  162. if retInfo != nil {
  163. *retInfo = advertising.Info{}
  164. *retInfo = *infoResponse.Info
  165. }
  166. return toolKit
  167. }
  168. /* HAC: TEST RELATION METHODS */
  169. /* HAC: END TEST RELATION METHODS */