package test import ( "erpims/application/domain/announcement_policy_info" "git.sxidc.com/go-framework/baize/framework/core/api/request" "git.sxidc.com/go-framework/baize/framework/core/api/response" "git.sxidc.com/go-tools/utils/strutils" "math/rand" "net/http" "strconv" "testing" ) func TestAnnouncementPolicyInfo(t *testing.T) { Init() defer Destroy() var announcementPolicyInfoID string var totalCount int64 announcementPolicyInfoInfo := new(announcement_policy_info.Info) announcementPolicyInfoInfos := make([]announcement_policy_info.Info, 0) createUserID := strutils.SimpleUUID() updateUserID := strutils.SimpleUUID() deleteUserID := strutils.SimpleUUID() operatorUserName := strutils.SimpleUUID() title := strutils.SimpleUUID() announcementPolicyType := int(rand.Int()) enterpriseAnnouncementType := int(rand.Int()) releaseDate := "2999-01-01 00:00:00" titleImgUrl := strutils.SimpleUUID() content := strutils.SimpleUUID() newTitle := strutils.SimpleUUID() newAnnouncementPolicyType := int(rand.Int()) newEnterpriseAnnouncementType := int(rand.Int()) newReleaseDate := "3000-01-01 00:00:00" newTitleImgUrl := strutils.SimpleUUID() newContent := strutils.SimpleUUID() NewToolKit(t).CreateAnnouncementPolicyInfo(title, announcementPolicyType, enterpriseAnnouncementType, releaseDate, titleImgUrl, content, createUserID, operatorUserName, &announcementPolicyInfoID). GetAnnouncementPolicyInfo(announcementPolicyInfoID, announcementPolicyInfoInfo). AssertEqual(announcementPolicyInfoID, announcementPolicyInfoInfo.ID, "公告政策信息ID不一致"). AssertEqual(title, announcementPolicyInfoInfo.Title, "公告政策信息标题不一致"). AssertEqual(announcementPolicyType, announcementPolicyInfoInfo.AnnouncementPolicyType, "公告政策信息类型 1:企业公告 2:采购公告 3:经销政策不一致"). AssertEqual(enterpriseAnnouncementType, announcementPolicyInfoInfo.EnterpriseAnnouncementType, "公告政策信息企业公告类型 1:规章制度 2:企业动态不一致"). AssertEqual(releaseDate, announcementPolicyInfoInfo.ReleaseDate, "公告政策信息发布日期不一致"). AssertEqual(titleImgUrl, announcementPolicyInfoInfo.TitleImgUrl, "公告政策信息标题图片引用路径不一致"). AssertEqual(content, announcementPolicyInfoInfo.Content, "公告政策信息内容不一致"). AssertEqual(createUserID, announcementPolicyInfoInfo.CreateUserID, "创建用户ID不一致"). AssertEqual(createUserID, announcementPolicyInfoInfo.LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(announcementPolicyInfoInfo.CreatedTime, "创建时间为空"). AssertNotEmpty(announcementPolicyInfoInfo.LastUpdatedTime, "最近更新时间为空"). GetAnnouncementPolicyInfos(title, announcementPolicyType, enterpriseAnnouncementType, releaseDate, titleImgUrl, content, "1", "1", &announcementPolicyInfoInfos, &totalCount). AssertEqual(int(totalCount), len(announcementPolicyInfoInfos), "总数不一致"). AssertEqual(announcementPolicyInfoID, announcementPolicyInfoInfos[0].ID, "公告政策信息ID不一致"). AssertEqual(title, announcementPolicyInfoInfos[0].Title, "公告政策信息标题不一致"). AssertEqual(announcementPolicyType, announcementPolicyInfoInfos[0].AnnouncementPolicyType, "公告政策信息类型 1:企业公告 2:采购公告 3:经销政策不一致"). AssertEqual(enterpriseAnnouncementType, announcementPolicyInfoInfos[0].EnterpriseAnnouncementType, "公告政策信息企业公告类型 1:规章制度 2:企业动态不一致"). AssertEqual(releaseDate, announcementPolicyInfoInfos[0].ReleaseDate, "公告政策信息发布日期不一致"). AssertEqual(titleImgUrl, announcementPolicyInfoInfos[0].TitleImgUrl, "公告政策信息标题图片引用路径不一致"). AssertEqual(content, announcementPolicyInfoInfos[0].Content, "公告政策信息内容不一致"). AssertEqual(createUserID, announcementPolicyInfoInfos[0].CreateUserID, "创建用户ID不一致"). AssertEqual(createUserID, announcementPolicyInfoInfos[0].LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(announcementPolicyInfoInfos[0].CreatedTime, "创建时间为空"). AssertNotEmpty(announcementPolicyInfoInfos[0].LastUpdatedTime, "最近更新时间为空"). GetAnnouncementPolicyInfos(title, announcementPolicyType, enterpriseAnnouncementType, releaseDate, titleImgUrl, content, "0", "0", &announcementPolicyInfoInfos, &totalCount). AssertEqual(int(totalCount), len(announcementPolicyInfoInfos), "总数不一致"). AssertEqual(1, len(announcementPolicyInfoInfos), "公告政策信息数应当为1"). AssertEqual(announcementPolicyInfoID, announcementPolicyInfoInfos[0].ID, "公告政策信息ID不一致"). AssertEqual(title, announcementPolicyInfoInfos[0].Title, "公告政策信息标题不一致"). AssertEqual(announcementPolicyType, announcementPolicyInfoInfos[0].AnnouncementPolicyType, "公告政策信息类型 1:企业公告 2:采购公告 3:经销政策不一致"). AssertEqual(enterpriseAnnouncementType, announcementPolicyInfoInfos[0].EnterpriseAnnouncementType, "公告政策信息企业公告类型 1:规章制度 2:企业动态不一致"). AssertEqual(releaseDate, announcementPolicyInfoInfos[0].ReleaseDate, "公告政策信息发布日期不一致"). AssertEqual(titleImgUrl, announcementPolicyInfoInfos[0].TitleImgUrl, "公告政策信息标题图片引用路径不一致"). AssertEqual(content, announcementPolicyInfoInfos[0].Content, "公告政策信息内容不一致"). AssertEqual(createUserID, announcementPolicyInfoInfos[0].CreateUserID, "创建用户ID不一致"). AssertEqual(createUserID, announcementPolicyInfoInfos[0].LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(announcementPolicyInfoInfos[0].CreatedTime, "创建时间为空"). AssertNotEmpty(announcementPolicyInfoInfos[0].LastUpdatedTime, "最近更新时间为空"). UpdateAnnouncementPolicyInfo(announcementPolicyInfoID, newTitle, newAnnouncementPolicyType, newEnterpriseAnnouncementType, newReleaseDate, newTitleImgUrl, newContent, updateUserID, operatorUserName). GetAnnouncementPolicyInfos(newTitle, newAnnouncementPolicyType, newEnterpriseAnnouncementType, newReleaseDate, newTitleImgUrl, newContent, "1", "1", &announcementPolicyInfoInfos, &totalCount). AssertEqual(int(totalCount), len(announcementPolicyInfoInfos), "总数不一致"). AssertEqual(announcementPolicyInfoID, announcementPolicyInfoInfos[0].ID, "公告政策信息ID不一致"). AssertEqual(newTitle, announcementPolicyInfoInfos[0].Title, "公告政策信息标题不一致"). AssertEqual(newAnnouncementPolicyType, announcementPolicyInfoInfos[0].AnnouncementPolicyType, "公告政策信息类型 1:企业公告 2:采购公告 3:经销政策不一致"). AssertEqual(newEnterpriseAnnouncementType, announcementPolicyInfoInfos[0].EnterpriseAnnouncementType, "公告政策信息企业公告类型 1:规章制度 2:企业动态不一致"). AssertEqual(newReleaseDate, announcementPolicyInfoInfos[0].ReleaseDate, "公告政策信息发布日期不一致"). AssertEqual(newTitleImgUrl, announcementPolicyInfoInfos[0].TitleImgUrl, "公告政策信息标题图片引用路径不一致"). AssertEqual(newContent, announcementPolicyInfoInfos[0].Content, "公告政策信息内容不一致"). AssertEqual(createUserID, announcementPolicyInfoInfos[0].CreateUserID, "创建用户ID不一致"). AssertEqual(updateUserID, announcementPolicyInfoInfos[0].LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(announcementPolicyInfoInfos[0].CreatedTime, "创建时间为空"). AssertNotEmpty(announcementPolicyInfoInfos[0].LastUpdatedTime, "最近更新时间为空"). DeleteAnnouncementPolicyInfo(announcementPolicyInfoID, deleteUserID, operatorUserName). GetAnnouncementPolicyInfos(newTitle, newAnnouncementPolicyType, newEnterpriseAnnouncementType, newReleaseDate, newTitleImgUrl, newContent, "1", "1", &announcementPolicyInfoInfos, &totalCount). AssertEqual(int(totalCount), len(announcementPolicyInfoInfos), "总数不一致"). AssertEqual(0, len(announcementPolicyInfoInfos), "删除公告政策信息失败") } /* HAC: TEST RELATION FUNCTIONS */ /* HAC: END TEST RELATION FUNCTIONS */ func (toolKit *ToolKit) CreateAnnouncementPolicyInfo(title string, announcementPolicyType int, enterpriseAnnouncementType int, releaseDate string, titleImgUrl string, content string, createUserID string, operatorUserName string, announcementPolicyInfoID *string) *ToolKit { idResponse := new(response.IDResponse) toolKit.SetHeader("Content-Type", "application/json"). SetJsonBody(&announcement_policy_info.CreateAnnouncementPolicyInfoJsonBody{ Title: title, AnnouncementPolicyType: announcementPolicyType, EnterpriseAnnouncementType: enterpriseAnnouncementType, ReleaseDate: releaseDate, TitleImgUrl: titleImgUrl, Content: content, CreateUserIDJsonBody: request.CreateUserIDJsonBody{CreateUserID: createUserID}, OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName}, }). SetJsonResponse(idResponse). Request("/erpims/api/v1/announcementPolicyInfo/create", http.MethodPost). AssertStatusCode(http.StatusOK). AssertEqual(true, idResponse.Success, idResponse.Msg). AssertNotEmpty(idResponse.ID, "公告政策信息ID为空") if announcementPolicyInfoID != nil { *announcementPolicyInfoID = idResponse.ID } return toolKit } func (toolKit *ToolKit) DeleteAnnouncementPolicyInfo(id string, deleteUserID string, operatorUserName string) *ToolKit { msgResponse := new(response.MsgResponse) toolKit.SetHeader("Content-Type", "application/json"). SetJsonResponse(msgResponse). SetQueryParams("id", id). SetQueryParams("deleteUserId", deleteUserID). SetQueryParams("operatorUserName", operatorUserName). Request("/erpims/api/v1/announcementPolicyInfo/delete", http.MethodDelete). AssertStatusCode(http.StatusOK). AssertEqual(true, msgResponse.Success, msgResponse.Msg) return toolKit } func (toolKit *ToolKit) UpdateAnnouncementPolicyInfo(id string, title string, announcementPolicyType int, enterpriseAnnouncementType int, releaseDate string, titleImgUrl string, content string, updateUserID string, operatorUserName string) *ToolKit { msgResponse := new(response.MsgResponse) toolKit.SetHeader("Content-Type", "application/json"). SetJsonBody(&announcement_policy_info.UpdateAnnouncementPolicyInfoJsonBody{ IDJsonBody: request.IDJsonBody{ID: id}, Title: title, AnnouncementPolicyType: announcementPolicyType, EnterpriseAnnouncementType: enterpriseAnnouncementType, ReleaseDate: releaseDate, TitleImgUrl: titleImgUrl, Content: content, UpdateUserIDJsonBody: request.UpdateUserIDJsonBody{UpdateUserID: updateUserID}, OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName}, }). SetJsonResponse(msgResponse). Request("/erpims/api/v1/announcementPolicyInfo/update", http.MethodPut). AssertStatusCode(http.StatusOK). AssertEqual(true, msgResponse.Success, msgResponse.Msg) return toolKit } 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 { infosResponse := new(response.InfosResponse[announcement_policy_info.Info]) toolKit.SetHeader("Content-Type", "application/json"). SetJsonResponse(infosResponse). SetQueryParams("title", title). SetQueryParams("announcementPolicyType", strconv.FormatInt(int64(announcementPolicyType), 10)). SetQueryParams("enterpriseAnnouncementType", strconv.FormatInt(int64(enterpriseAnnouncementType), 10)). SetQueryParams("releaseDate", releaseDate). SetQueryParams("titleImgUrl", titleImgUrl). SetQueryParams("content", content). SetQueryParams("pageNo", pageNo). SetQueryParams("pageSize", pageSize). Request("/erpims/api/v1/announcementPolicyInfo/query", http.MethodGet). AssertStatusCode(http.StatusOK). AssertEqual(true, infosResponse.Success, infosResponse.Msg) if retInfos != nil { *retInfos = make([]announcement_policy_info.Info, 0) *retInfos = append(*retInfos, infosResponse.Infos...) } if retTotalCount != nil { *retTotalCount = infosResponse.TotalCount } return toolKit } func (toolKit *ToolKit) GetAnnouncementPolicyInfo(id string, retInfo *announcement_policy_info.Info) *ToolKit { infoResponse := new(response.InfoResponse[*announcement_policy_info.Info]) toolKit.SetHeader("Content-Type", "application/json"). SetJsonResponse(infoResponse). SetQueryParams("id", id). Request("/erpims/api/v1/announcementPolicyInfo/get", http.MethodGet). AssertStatusCode(http.StatusOK). AssertEqual(true, infoResponse.Success, infoResponse.Msg) if retInfo != nil { *retInfo = announcement_policy_info.Info{} *retInfo = *infoResponse.Info } return toolKit } /* HAC: TEST RELATION METHODS */ /* HAC: END TEST RELATION METHODS */