common_use_website_test.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package test
  2. import (
  3. "erpims/application/domain/common_use_website"
  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 TestCommonUseWebsite(t *testing.T) {
  13. Init()
  14. defer Destroy()
  15. var commonUseWebsiteID string
  16. var totalCount int64
  17. commonUseWebsiteInfo := new(common_use_website.Info)
  18. commonUseWebsiteInfos := make([]common_use_website.Info, 0)
  19. createUserID := strutils.SimpleUUID()
  20. updateUserID := strutils.SimpleUUID()
  21. deleteUserID := strutils.SimpleUUID()
  22. operatorUserName := strutils.SimpleUUID()
  23. title := strutils.SimpleUUID()
  24. iconUrl := strutils.SimpleUUID()
  25. accessUrl := strutils.SimpleUUID()
  26. sort := int(rand.Int())
  27. newTitle := strutils.SimpleUUID()
  28. newIconUrl := strutils.SimpleUUID()
  29. newAccessUrl := strutils.SimpleUUID()
  30. newSort := int(rand.Int())
  31. NewToolKit(t).CreateCommonUseWebsite(title, iconUrl, accessUrl, sort, createUserID, operatorUserName, &commonUseWebsiteID).
  32. GetCommonUseWebsite(commonUseWebsiteID, commonUseWebsiteInfo).
  33. AssertEqual(commonUseWebsiteID, commonUseWebsiteInfo.ID, "常用网站ID不一致").
  34. AssertEqual(title, commonUseWebsiteInfo.Title, "常用网站标题不一致").
  35. AssertEqual(iconUrl, commonUseWebsiteInfo.IconUrl, "常用网站图标路径不一致").
  36. AssertEqual(accessUrl, commonUseWebsiteInfo.AccessUrl, "常用网站访问路径不一致").
  37. AssertEqual(sort, commonUseWebsiteInfo.Sort, "常用网站排序不一致").
  38. AssertEqual(createUserID, commonUseWebsiteInfo.CreateUserID, "创建用户ID不一致").
  39. AssertEqual(createUserID, commonUseWebsiteInfo.LastUpdateUserID, "最近更新用户ID不一致").
  40. AssertNotEmpty(commonUseWebsiteInfo.CreatedTime, "创建时间为空").
  41. AssertNotEmpty(commonUseWebsiteInfo.LastUpdatedTime, "最近更新时间为空").
  42. GetCommonUseWebsites(title, iconUrl, accessUrl, sort, "1", "1", &commonUseWebsiteInfos, &totalCount).
  43. AssertEqual(int(totalCount), len(commonUseWebsiteInfos), "总数不一致").
  44. AssertEqual(commonUseWebsiteID, commonUseWebsiteInfos[0].ID, "常用网站ID不一致").
  45. AssertEqual(title, commonUseWebsiteInfos[0].Title, "常用网站标题不一致").
  46. AssertEqual(iconUrl, commonUseWebsiteInfos[0].IconUrl, "常用网站图标路径不一致").
  47. AssertEqual(accessUrl, commonUseWebsiteInfos[0].AccessUrl, "常用网站访问路径不一致").
  48. AssertEqual(sort, commonUseWebsiteInfos[0].Sort, "常用网站排序不一致").
  49. AssertEqual(createUserID, commonUseWebsiteInfos[0].CreateUserID, "创建用户ID不一致").
  50. AssertEqual(createUserID, commonUseWebsiteInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  51. AssertNotEmpty(commonUseWebsiteInfos[0].CreatedTime, "创建时间为空").
  52. AssertNotEmpty(commonUseWebsiteInfos[0].LastUpdatedTime, "最近更新时间为空").
  53. GetCommonUseWebsites(title, iconUrl, accessUrl, sort, "0", "0", &commonUseWebsiteInfos, &totalCount).
  54. AssertEqual(int(totalCount), len(commonUseWebsiteInfos), "总数不一致").
  55. AssertEqual(1, len(commonUseWebsiteInfos), "常用网站数应当为1").
  56. AssertEqual(commonUseWebsiteID, commonUseWebsiteInfos[0].ID, "常用网站ID不一致").
  57. AssertEqual(title, commonUseWebsiteInfos[0].Title, "常用网站标题不一致").
  58. AssertEqual(iconUrl, commonUseWebsiteInfos[0].IconUrl, "常用网站图标路径不一致").
  59. AssertEqual(accessUrl, commonUseWebsiteInfos[0].AccessUrl, "常用网站访问路径不一致").
  60. AssertEqual(sort, commonUseWebsiteInfos[0].Sort, "常用网站排序不一致").
  61. AssertEqual(createUserID, commonUseWebsiteInfos[0].CreateUserID, "创建用户ID不一致").
  62. AssertEqual(createUserID, commonUseWebsiteInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  63. AssertNotEmpty(commonUseWebsiteInfos[0].CreatedTime, "创建时间为空").
  64. AssertNotEmpty(commonUseWebsiteInfos[0].LastUpdatedTime, "最近更新时间为空").
  65. UpdateCommonUseWebsite(commonUseWebsiteID, newTitle, newIconUrl, newAccessUrl, newSort, updateUserID, operatorUserName).
  66. GetCommonUseWebsites(newTitle, newIconUrl, newAccessUrl, newSort, "1", "1", &commonUseWebsiteInfos, &totalCount).
  67. AssertEqual(int(totalCount), len(commonUseWebsiteInfos), "总数不一致").
  68. AssertEqual(commonUseWebsiteID, commonUseWebsiteInfos[0].ID, "常用网站ID不一致").
  69. AssertEqual(newTitle, commonUseWebsiteInfos[0].Title, "常用网站标题不一致").
  70. AssertEqual(newIconUrl, commonUseWebsiteInfos[0].IconUrl, "常用网站图标路径不一致").
  71. AssertEqual(newAccessUrl, commonUseWebsiteInfos[0].AccessUrl, "常用网站访问路径不一致").
  72. AssertEqual(newSort, commonUseWebsiteInfos[0].Sort, "常用网站排序不一致").
  73. AssertEqual(createUserID, commonUseWebsiteInfos[0].CreateUserID, "创建用户ID不一致").
  74. AssertEqual(updateUserID, commonUseWebsiteInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  75. AssertNotEmpty(commonUseWebsiteInfos[0].CreatedTime, "创建时间为空").
  76. AssertNotEmpty(commonUseWebsiteInfos[0].LastUpdatedTime, "最近更新时间为空").
  77. DeleteCommonUseWebsite(commonUseWebsiteID, deleteUserID, operatorUserName).
  78. GetCommonUseWebsites(newTitle, newIconUrl, newAccessUrl, newSort, "1", "1", &commonUseWebsiteInfos, &totalCount).
  79. AssertEqual(int(totalCount), len(commonUseWebsiteInfos), "总数不一致").
  80. AssertEqual(0, len(commonUseWebsiteInfos), "删除常用网站失败")
  81. }
  82. /* HAC: TEST RELATION FUNCTIONS */
  83. /* HAC: END TEST RELATION FUNCTIONS */
  84. func (toolKit *ToolKit) CreateCommonUseWebsite(title string, iconUrl string, accessUrl string, sort int, createUserID string, operatorUserName string, commonUseWebsiteID *string) *ToolKit {
  85. idResponse := new(response.IDResponse)
  86. toolKit.SetHeader("Content-Type", "application/json").
  87. SetJsonBody(&common_use_website.CreateCommonUseWebsiteJsonBody{
  88. Title: title, IconUrl: iconUrl, AccessUrl: accessUrl, Sort: sort,
  89. CreateUserIDJsonBody: request.CreateUserIDJsonBody{CreateUserID: createUserID},
  90. OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName},
  91. }).
  92. SetJsonResponse(idResponse).
  93. Request("/erpims/api/v1/commonUseWebsite/create", http.MethodPost).
  94. AssertStatusCode(http.StatusOK).
  95. AssertEqual(true, idResponse.Success, idResponse.Msg).
  96. AssertNotEmpty(idResponse.ID, "常用网站ID为空")
  97. if commonUseWebsiteID != nil {
  98. *commonUseWebsiteID = idResponse.ID
  99. }
  100. return toolKit
  101. }
  102. func (toolKit *ToolKit) DeleteCommonUseWebsite(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/commonUseWebsite/delete", http.MethodDelete).
  110. AssertStatusCode(http.StatusOK).
  111. AssertEqual(true, msgResponse.Success, msgResponse.Msg)
  112. return toolKit
  113. }
  114. func (toolKit *ToolKit) UpdateCommonUseWebsite(id string, title string, iconUrl string, accessUrl string, sort int, updateUserID string, operatorUserName string) *ToolKit {
  115. msgResponse := new(response.MsgResponse)
  116. toolKit.SetHeader("Content-Type", "application/json").
  117. SetJsonBody(&common_use_website.UpdateCommonUseWebsiteJsonBody{
  118. IDJsonBody: request.IDJsonBody{ID: id},
  119. Title: title,
  120. IconUrl: iconUrl,
  121. AccessUrl: accessUrl,
  122. Sort: sort,
  123. UpdateUserIDJsonBody: request.UpdateUserIDJsonBody{UpdateUserID: updateUserID},
  124. OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName},
  125. }).
  126. SetJsonResponse(msgResponse).
  127. Request("/erpims/api/v1/commonUseWebsite/update", http.MethodPut).
  128. AssertStatusCode(http.StatusOK).
  129. AssertEqual(true, msgResponse.Success, msgResponse.Msg)
  130. return toolKit
  131. }
  132. func (toolKit *ToolKit) GetCommonUseWebsites(title string, iconUrl string, accessUrl string, sort int, pageNo string, pageSize string, retInfos *[]common_use_website.Info, retTotalCount *int64) *ToolKit {
  133. infosResponse := new(response.InfosResponse[common_use_website.Info])
  134. toolKit.SetHeader("Content-Type", "application/json").
  135. SetJsonResponse(infosResponse).
  136. SetQueryParams("title", title).
  137. SetQueryParams("iconUrl", iconUrl).
  138. SetQueryParams("accessUrl", accessUrl).
  139. SetQueryParams("sort", strconv.FormatInt(int64(sort), 10)).
  140. SetQueryParams("pageNo", pageNo).
  141. SetQueryParams("pageSize", pageSize).
  142. Request("/erpims/api/v1/commonUseWebsite/query", http.MethodGet).
  143. AssertStatusCode(http.StatusOK).
  144. AssertEqual(true, infosResponse.Success, infosResponse.Msg)
  145. if retInfos != nil {
  146. *retInfos = make([]common_use_website.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) GetCommonUseWebsite(id string, retInfo *common_use_website.Info) *ToolKit {
  155. infoResponse := new(response.InfoResponse[*common_use_website.Info])
  156. toolKit.SetHeader("Content-Type", "application/json").
  157. SetJsonResponse(infoResponse).
  158. SetQueryParams("id", id).
  159. Request("/erpims/api/v1/commonUseWebsite/get", http.MethodGet).
  160. AssertStatusCode(http.StatusOK).
  161. AssertEqual(true, infoResponse.Success, infoResponse.Msg)
  162. if retInfo != nil {
  163. *retInfo = common_use_website.Info{}
  164. *retInfo = *infoResponse.Info
  165. }
  166. return toolKit
  167. }
  168. /* HAC: TEST RELATION METHODS */
  169. /* HAC: END TEST RELATION METHODS */