announcement_policy_info_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package test
  2. import (
  3. "erpims/application/domain/announcement_policy_info"
  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 TestAnnouncementPolicyInfo(t *testing.T) {
  13. Init()
  14. defer Destroy()
  15. var announcementPolicyInfoID string
  16. var totalCount int64
  17. announcementPolicyInfoInfo := new(announcement_policy_info.Info)
  18. announcementPolicyInfoInfos := make([]announcement_policy_info.Info, 0)
  19. createUserID := strutils.SimpleUUID()
  20. updateUserID := strutils.SimpleUUID()
  21. deleteUserID := strutils.SimpleUUID()
  22. operatorUserName := strutils.SimpleUUID()
  23. title := strutils.SimpleUUID()
  24. announcementPolicyType := int(rand.Int())
  25. enterpriseAnnouncementType := int(rand.Int())
  26. releaseDate := "2999-01-01 00:00:00"
  27. titleImgUrl := strutils.SimpleUUID()
  28. content := strutils.SimpleUUID()
  29. newTitle := strutils.SimpleUUID()
  30. newAnnouncementPolicyType := int(rand.Int())
  31. newEnterpriseAnnouncementType := int(rand.Int())
  32. newReleaseDate := "3000-01-01 00:00:00"
  33. newTitleImgUrl := strutils.SimpleUUID()
  34. newContent := strutils.SimpleUUID()
  35. NewToolKit(t).CreateAnnouncementPolicyInfo(title, announcementPolicyType, enterpriseAnnouncementType, releaseDate, titleImgUrl, content, createUserID, operatorUserName, &announcementPolicyInfoID).
  36. GetAnnouncementPolicyInfo(announcementPolicyInfoID, announcementPolicyInfoInfo).
  37. AssertEqual(announcementPolicyInfoID, announcementPolicyInfoInfo.ID, "公告政策信息ID不一致").
  38. AssertEqual(title, announcementPolicyInfoInfo.Title, "公告政策信息标题不一致").
  39. AssertEqual(announcementPolicyType, announcementPolicyInfoInfo.AnnouncementPolicyType, "公告政策信息类型 1:企业公告 2:采购公告 3:经销政策不一致").
  40. AssertEqual(enterpriseAnnouncementType, announcementPolicyInfoInfo.EnterpriseAnnouncementType, "公告政策信息企业公告类型 1:规章制度 2:企业动态不一致").
  41. AssertEqual(releaseDate, announcementPolicyInfoInfo.ReleaseDate, "公告政策信息发布日期不一致").
  42. AssertEqual(titleImgUrl, announcementPolicyInfoInfo.TitleImgUrl, "公告政策信息标题图片引用路径不一致").
  43. AssertEqual(content, announcementPolicyInfoInfo.Content, "公告政策信息内容不一致").
  44. AssertEqual(createUserID, announcementPolicyInfoInfo.CreateUserID, "创建用户ID不一致").
  45. AssertEqual(createUserID, announcementPolicyInfoInfo.LastUpdateUserID, "最近更新用户ID不一致").
  46. AssertNotEmpty(announcementPolicyInfoInfo.CreatedTime, "创建时间为空").
  47. AssertNotEmpty(announcementPolicyInfoInfo.LastUpdatedTime, "最近更新时间为空").
  48. GetAnnouncementPolicyInfos(title, announcementPolicyType, enterpriseAnnouncementType, releaseDate, titleImgUrl, content, "1", "1", &announcementPolicyInfoInfos, &totalCount).
  49. AssertEqual(int(totalCount), len(announcementPolicyInfoInfos), "总数不一致").
  50. AssertEqual(announcementPolicyInfoID, announcementPolicyInfoInfos[0].ID, "公告政策信息ID不一致").
  51. AssertEqual(title, announcementPolicyInfoInfos[0].Title, "公告政策信息标题不一致").
  52. AssertEqual(announcementPolicyType, announcementPolicyInfoInfos[0].AnnouncementPolicyType, "公告政策信息类型 1:企业公告 2:采购公告 3:经销政策不一致").
  53. AssertEqual(enterpriseAnnouncementType, announcementPolicyInfoInfos[0].EnterpriseAnnouncementType, "公告政策信息企业公告类型 1:规章制度 2:企业动态不一致").
  54. AssertEqual(releaseDate, announcementPolicyInfoInfos[0].ReleaseDate, "公告政策信息发布日期不一致").
  55. AssertEqual(titleImgUrl, announcementPolicyInfoInfos[0].TitleImgUrl, "公告政策信息标题图片引用路径不一致").
  56. AssertEqual(content, announcementPolicyInfoInfos[0].Content, "公告政策信息内容不一致").
  57. AssertEqual(createUserID, announcementPolicyInfoInfos[0].CreateUserID, "创建用户ID不一致").
  58. AssertEqual(createUserID, announcementPolicyInfoInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  59. AssertNotEmpty(announcementPolicyInfoInfos[0].CreatedTime, "创建时间为空").
  60. AssertNotEmpty(announcementPolicyInfoInfos[0].LastUpdatedTime, "最近更新时间为空").
  61. GetAnnouncementPolicyInfos(title, announcementPolicyType, enterpriseAnnouncementType, releaseDate, titleImgUrl, content, "0", "0", &announcementPolicyInfoInfos, &totalCount).
  62. AssertEqual(int(totalCount), len(announcementPolicyInfoInfos), "总数不一致").
  63. AssertEqual(1, len(announcementPolicyInfoInfos), "公告政策信息数应当为1").
  64. AssertEqual(announcementPolicyInfoID, announcementPolicyInfoInfos[0].ID, "公告政策信息ID不一致").
  65. AssertEqual(title, announcementPolicyInfoInfos[0].Title, "公告政策信息标题不一致").
  66. AssertEqual(announcementPolicyType, announcementPolicyInfoInfos[0].AnnouncementPolicyType, "公告政策信息类型 1:企业公告 2:采购公告 3:经销政策不一致").
  67. AssertEqual(enterpriseAnnouncementType, announcementPolicyInfoInfos[0].EnterpriseAnnouncementType, "公告政策信息企业公告类型 1:规章制度 2:企业动态不一致").
  68. AssertEqual(releaseDate, announcementPolicyInfoInfos[0].ReleaseDate, "公告政策信息发布日期不一致").
  69. AssertEqual(titleImgUrl, announcementPolicyInfoInfos[0].TitleImgUrl, "公告政策信息标题图片引用路径不一致").
  70. AssertEqual(content, announcementPolicyInfoInfos[0].Content, "公告政策信息内容不一致").
  71. AssertEqual(createUserID, announcementPolicyInfoInfos[0].CreateUserID, "创建用户ID不一致").
  72. AssertEqual(createUserID, announcementPolicyInfoInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  73. AssertNotEmpty(announcementPolicyInfoInfos[0].CreatedTime, "创建时间为空").
  74. AssertNotEmpty(announcementPolicyInfoInfos[0].LastUpdatedTime, "最近更新时间为空").
  75. UpdateAnnouncementPolicyInfo(announcementPolicyInfoID, newTitle, newAnnouncementPolicyType, newEnterpriseAnnouncementType, newReleaseDate, newTitleImgUrl, newContent, updateUserID, operatorUserName).
  76. GetAnnouncementPolicyInfos(newTitle, newAnnouncementPolicyType, newEnterpriseAnnouncementType, newReleaseDate, newTitleImgUrl, newContent, "1", "1", &announcementPolicyInfoInfos, &totalCount).
  77. AssertEqual(int(totalCount), len(announcementPolicyInfoInfos), "总数不一致").
  78. AssertEqual(announcementPolicyInfoID, announcementPolicyInfoInfos[0].ID, "公告政策信息ID不一致").
  79. AssertEqual(newTitle, announcementPolicyInfoInfos[0].Title, "公告政策信息标题不一致").
  80. AssertEqual(newAnnouncementPolicyType, announcementPolicyInfoInfos[0].AnnouncementPolicyType, "公告政策信息类型 1:企业公告 2:采购公告 3:经销政策不一致").
  81. AssertEqual(newEnterpriseAnnouncementType, announcementPolicyInfoInfos[0].EnterpriseAnnouncementType, "公告政策信息企业公告类型 1:规章制度 2:企业动态不一致").
  82. AssertEqual(newReleaseDate, announcementPolicyInfoInfos[0].ReleaseDate, "公告政策信息发布日期不一致").
  83. AssertEqual(newTitleImgUrl, announcementPolicyInfoInfos[0].TitleImgUrl, "公告政策信息标题图片引用路径不一致").
  84. AssertEqual(newContent, announcementPolicyInfoInfos[0].Content, "公告政策信息内容不一致").
  85. AssertEqual(createUserID, announcementPolicyInfoInfos[0].CreateUserID, "创建用户ID不一致").
  86. AssertEqual(updateUserID, announcementPolicyInfoInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
  87. AssertNotEmpty(announcementPolicyInfoInfos[0].CreatedTime, "创建时间为空").
  88. AssertNotEmpty(announcementPolicyInfoInfos[0].LastUpdatedTime, "最近更新时间为空").
  89. DeleteAnnouncementPolicyInfo(announcementPolicyInfoID, deleteUserID, operatorUserName).
  90. GetAnnouncementPolicyInfos(newTitle, newAnnouncementPolicyType, newEnterpriseAnnouncementType, newReleaseDate, newTitleImgUrl, newContent, "1", "1", &announcementPolicyInfoInfos, &totalCount).
  91. AssertEqual(int(totalCount), len(announcementPolicyInfoInfos), "总数不一致").
  92. AssertEqual(0, len(announcementPolicyInfoInfos), "删除公告政策信息失败")
  93. }
  94. /* HAC: TEST RELATION FUNCTIONS */
  95. /* HAC: END TEST RELATION FUNCTIONS */
  96. func (toolKit *ToolKit) CreateAnnouncementPolicyInfo(title string, announcementPolicyType int, enterpriseAnnouncementType int, releaseDate string, titleImgUrl string, content string, createUserID string, operatorUserName string, announcementPolicyInfoID *string) *ToolKit {
  97. idResponse := new(response.IDResponse)
  98. toolKit.SetHeader("Content-Type", "application/json").
  99. SetJsonBody(&announcement_policy_info.CreateAnnouncementPolicyInfoJsonBody{
  100. Title: title, AnnouncementPolicyType: announcementPolicyType, EnterpriseAnnouncementType: enterpriseAnnouncementType, ReleaseDate: releaseDate, TitleImgUrl: titleImgUrl, Content: content,
  101. CreateUserIDJsonBody: request.CreateUserIDJsonBody{CreateUserID: createUserID},
  102. OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName},
  103. }).
  104. SetJsonResponse(idResponse).
  105. Request("/erpims/api/v1/announcementPolicyInfo/create", http.MethodPost).
  106. AssertStatusCode(http.StatusOK).
  107. AssertEqual(true, idResponse.Success, idResponse.Msg).
  108. AssertNotEmpty(idResponse.ID, "公告政策信息ID为空")
  109. if announcementPolicyInfoID != nil {
  110. *announcementPolicyInfoID = idResponse.ID
  111. }
  112. return toolKit
  113. }
  114. func (toolKit *ToolKit) DeleteAnnouncementPolicyInfo(id string, deleteUserID string, operatorUserName string) *ToolKit {
  115. msgResponse := new(response.MsgResponse)
  116. toolKit.SetHeader("Content-Type", "application/json").
  117. SetJsonResponse(msgResponse).
  118. SetQueryParams("id", id).
  119. SetQueryParams("deleteUserId", deleteUserID).
  120. SetQueryParams("operatorUserName", operatorUserName).
  121. Request("/erpims/api/v1/announcementPolicyInfo/delete", http.MethodDelete).
  122. AssertStatusCode(http.StatusOK).
  123. AssertEqual(true, msgResponse.Success, msgResponse.Msg)
  124. return toolKit
  125. }
  126. func (toolKit *ToolKit) UpdateAnnouncementPolicyInfo(id string, title string, announcementPolicyType int, enterpriseAnnouncementType int, releaseDate string, titleImgUrl string, content string, updateUserID string, operatorUserName string) *ToolKit {
  127. msgResponse := new(response.MsgResponse)
  128. toolKit.SetHeader("Content-Type", "application/json").
  129. SetJsonBody(&announcement_policy_info.UpdateAnnouncementPolicyInfoJsonBody{
  130. IDJsonBody: request.IDJsonBody{ID: id},
  131. Title: title,
  132. AnnouncementPolicyType: announcementPolicyType,
  133. EnterpriseAnnouncementType: enterpriseAnnouncementType,
  134. ReleaseDate: releaseDate,
  135. TitleImgUrl: titleImgUrl,
  136. Content: content,
  137. UpdateUserIDJsonBody: request.UpdateUserIDJsonBody{UpdateUserID: updateUserID},
  138. OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName},
  139. }).
  140. SetJsonResponse(msgResponse).
  141. Request("/erpims/api/v1/announcementPolicyInfo/update", http.MethodPut).
  142. AssertStatusCode(http.StatusOK).
  143. AssertEqual(true, msgResponse.Success, msgResponse.Msg)
  144. return toolKit
  145. }
  146. func (toolKit *ToolKit) GetAnnouncementPolicyInfos(title string, announcementPolicyType int, enterpriseAnnouncementType int, releaseDate string, titleImgUrl string, content string, pageNo string, pageSize string, retInfos *[]announcement_policy_info.Info, retTotalCount *int64) *ToolKit {
  147. infosResponse := new(response.InfosResponse[announcement_policy_info.Info])
  148. toolKit.SetHeader("Content-Type", "application/json").
  149. SetJsonResponse(infosResponse).
  150. SetQueryParams("title", title).
  151. SetQueryParams("announcementPolicyType", strconv.FormatInt(int64(announcementPolicyType), 10)).
  152. SetQueryParams("enterpriseAnnouncementType", strconv.FormatInt(int64(enterpriseAnnouncementType), 10)).
  153. SetQueryParams("releaseDate", releaseDate).
  154. SetQueryParams("titleImgUrl", titleImgUrl).
  155. SetQueryParams("content", content).
  156. SetQueryParams("pageNo", pageNo).
  157. SetQueryParams("pageSize", pageSize).
  158. Request("/erpims/api/v1/announcementPolicyInfo/query", http.MethodGet).
  159. AssertStatusCode(http.StatusOK).
  160. AssertEqual(true, infosResponse.Success, infosResponse.Msg)
  161. if retInfos != nil {
  162. *retInfos = make([]announcement_policy_info.Info, 0)
  163. *retInfos = append(*retInfos, infosResponse.Infos...)
  164. }
  165. if retTotalCount != nil {
  166. *retTotalCount = infosResponse.TotalCount
  167. }
  168. return toolKit
  169. }
  170. func (toolKit *ToolKit) GetAnnouncementPolicyInfo(id string, retInfo *announcement_policy_info.Info) *ToolKit {
  171. infoResponse := new(response.InfoResponse[*announcement_policy_info.Info])
  172. toolKit.SetHeader("Content-Type", "application/json").
  173. SetJsonResponse(infoResponse).
  174. SetQueryParams("id", id).
  175. Request("/erpims/api/v1/announcementPolicyInfo/get", http.MethodGet).
  176. AssertStatusCode(http.StatusOK).
  177. AssertEqual(true, infoResponse.Success, infoResponse.Msg)
  178. if retInfo != nil {
  179. *retInfo = announcement_policy_info.Info{}
  180. *retInfo = *infoResponse.Info
  181. }
  182. return toolKit
  183. }
  184. /* HAC: TEST RELATION METHODS */
  185. /* HAC: END TEST RELATION METHODS */