package test import ( "erpims/application/domain/banner" "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 TestBanner(t *testing.T) { Init() defer Destroy() var bannerID string var totalCount int64 bannerInfo := new(banner.Info) bannerInfos := make([]banner.Info, 0) createUserID := strutils.SimpleUUID() updateUserID := strutils.SimpleUUID() deleteUserID := strutils.SimpleUUID() operatorUserName := strutils.SimpleUUID() title := strutils.SimpleUUID() pageUrl := strutils.SimpleUUID() picUrl := strutils.SimpleUUID() status := int(rand.Int()) newTitle := strutils.SimpleUUID() newPageUrl := strutils.SimpleUUID() newPicUrl := strutils.SimpleUUID() newStatus := int(rand.Int()) NewToolKit(t).CreateBanner(title, pageUrl, picUrl, status, createUserID, operatorUserName, &bannerID). GetBanner(bannerID, bannerInfo). AssertEqual(bannerID, bannerInfo.ID, "宣传图ID不一致"). AssertEqual(title, bannerInfo.Title, "宣传图标题不一致"). AssertEqual(pageUrl, bannerInfo.PageUrl, "宣传图页面路径不一致"). AssertEqual(picUrl, bannerInfo.PicUrl, "宣传图图片地址不一致"). AssertEqual(status, bannerInfo.Status, "宣传图状态 1隐藏,2显示不一致"). AssertEqual(createUserID, bannerInfo.CreateUserID, "创建用户ID不一致"). AssertEqual(createUserID, bannerInfo.LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(bannerInfo.CreatedTime, "创建时间为空"). AssertNotEmpty(bannerInfo.LastUpdatedTime, "最近更新时间为空"). GetBanners(title, pageUrl, picUrl, status, "1", "1", &bannerInfos, &totalCount). AssertEqual(int(totalCount), len(bannerInfos), "总数不一致"). AssertEqual(bannerID, bannerInfos[0].ID, "宣传图ID不一致"). AssertEqual(title, bannerInfos[0].Title, "宣传图标题不一致"). AssertEqual(pageUrl, bannerInfos[0].PageUrl, "宣传图页面路径不一致"). AssertEqual(picUrl, bannerInfos[0].PicUrl, "宣传图图片地址不一致"). AssertEqual(status, bannerInfos[0].Status, "宣传图状态 1隐藏,2显示不一致"). AssertEqual(createUserID, bannerInfos[0].CreateUserID, "创建用户ID不一致"). AssertEqual(createUserID, bannerInfos[0].LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(bannerInfos[0].CreatedTime, "创建时间为空"). AssertNotEmpty(bannerInfos[0].LastUpdatedTime, "最近更新时间为空"). GetBanners(title, pageUrl, picUrl, status, "0", "0", &bannerInfos, &totalCount). AssertEqual(int(totalCount), len(bannerInfos), "总数不一致"). AssertEqual(1, len(bannerInfos), "宣传图数应当为1"). AssertEqual(bannerID, bannerInfos[0].ID, "宣传图ID不一致"). AssertEqual(title, bannerInfos[0].Title, "宣传图标题不一致"). AssertEqual(pageUrl, bannerInfos[0].PageUrl, "宣传图页面路径不一致"). AssertEqual(picUrl, bannerInfos[0].PicUrl, "宣传图图片地址不一致"). AssertEqual(status, bannerInfos[0].Status, "宣传图状态 1隐藏,2显示不一致"). AssertEqual(createUserID, bannerInfos[0].CreateUserID, "创建用户ID不一致"). AssertEqual(createUserID, bannerInfos[0].LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(bannerInfos[0].CreatedTime, "创建时间为空"). AssertNotEmpty(bannerInfos[0].LastUpdatedTime, "最近更新时间为空"). UpdateBanner(bannerID, newTitle, newPageUrl, newPicUrl, newStatus, updateUserID, operatorUserName). GetBanners(newTitle, newPageUrl, newPicUrl, newStatus, "1", "1", &bannerInfos, &totalCount). AssertEqual(int(totalCount), len(bannerInfos), "总数不一致"). AssertEqual(bannerID, bannerInfos[0].ID, "宣传图ID不一致"). AssertEqual(newTitle, bannerInfos[0].Title, "宣传图标题不一致"). AssertEqual(newPageUrl, bannerInfos[0].PageUrl, "宣传图页面路径不一致"). AssertEqual(newPicUrl, bannerInfos[0].PicUrl, "宣传图图片地址不一致"). AssertEqual(newStatus, bannerInfos[0].Status, "宣传图状态 1隐藏,2显示不一致"). AssertEqual(createUserID, bannerInfos[0].CreateUserID, "创建用户ID不一致"). AssertEqual(updateUserID, bannerInfos[0].LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(bannerInfos[0].CreatedTime, "创建时间为空"). AssertNotEmpty(bannerInfos[0].LastUpdatedTime, "最近更新时间为空"). DeleteBanner(bannerID, deleteUserID, operatorUserName). GetBanners(newTitle, newPageUrl, newPicUrl, newStatus, "1", "1", &bannerInfos, &totalCount). AssertEqual(int(totalCount), len(bannerInfos), "总数不一致"). AssertEqual(0, len(bannerInfos), "删除宣传图失败") } /* HAC: TEST RELATION FUNCTIONS */ /* HAC: END TEST RELATION FUNCTIONS */ func (toolKit *ToolKit) CreateBanner(title string, pageUrl string, picUrl string, status int, createUserID string, operatorUserName string, bannerID *string) *ToolKit { idResponse := new(response.IDResponse) toolKit.SetHeader("Content-Type", "application/json"). SetJsonBody(&banner.CreateBannerJsonBody{ Title: title, PageUrl: pageUrl, PicUrl: picUrl, Status: status, CreateUserIDJsonBody: request.CreateUserIDJsonBody{CreateUserID: createUserID}, OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName}, }). SetJsonResponse(idResponse). Request("/erpims/api/v1/banner/create", http.MethodPost). AssertStatusCode(http.StatusOK). AssertEqual(true, idResponse.Success, idResponse.Msg). AssertNotEmpty(idResponse.ID, "宣传图ID为空") if bannerID != nil { *bannerID = idResponse.ID } return toolKit } func (toolKit *ToolKit) DeleteBanner(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/banner/delete", http.MethodDelete). AssertStatusCode(http.StatusOK). AssertEqual(true, msgResponse.Success, msgResponse.Msg) return toolKit } func (toolKit *ToolKit) UpdateBanner(id string, title string, pageUrl string, picUrl string, status int, updateUserID string, operatorUserName string) *ToolKit { msgResponse := new(response.MsgResponse) toolKit.SetHeader("Content-Type", "application/json"). SetJsonBody(&banner.UpdateBannerJsonBody{ IDJsonBody: request.IDJsonBody{ID: id}, Title: title, PageUrl: pageUrl, PicUrl: picUrl, Status: status, UpdateUserIDJsonBody: request.UpdateUserIDJsonBody{UpdateUserID: updateUserID}, OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName}, }). SetJsonResponse(msgResponse). Request("/erpims/api/v1/banner/update", http.MethodPut). AssertStatusCode(http.StatusOK). AssertEqual(true, msgResponse.Success, msgResponse.Msg) return toolKit } func (toolKit *ToolKit) GetBanners(title string, pageUrl string, picUrl string, status int, pageNo string, pageSize string, retInfos *[]banner.Info, retTotalCount *int64) *ToolKit { infosResponse := new(response.InfosResponse[banner.Info]) toolKit.SetHeader("Content-Type", "application/json"). SetJsonResponse(infosResponse). SetQueryParams("title", title). SetQueryParams("pageUrl", pageUrl). SetQueryParams("picUrl", picUrl). SetQueryParams("status", strconv.FormatInt(int64(status), 10)). SetQueryParams("pageNo", pageNo). SetQueryParams("pageSize", pageSize). Request("/erpims/api/v1/banner/query", http.MethodGet). AssertStatusCode(http.StatusOK). AssertEqual(true, infosResponse.Success, infosResponse.Msg) if retInfos != nil { *retInfos = make([]banner.Info, 0) *retInfos = append(*retInfos, infosResponse.Infos...) } if retTotalCount != nil { *retTotalCount = infosResponse.TotalCount } return toolKit } func (toolKit *ToolKit) GetBanner(id string, retInfo *banner.Info) *ToolKit { infoResponse := new(response.InfoResponse[*banner.Info]) toolKit.SetHeader("Content-Type", "application/json"). SetJsonResponse(infoResponse). SetQueryParams("id", id). Request("/erpims/api/v1/banner/get", http.MethodGet). AssertStatusCode(http.StatusOK). AssertEqual(true, infoResponse.Success, infoResponse.Msg) if retInfo != nil { *retInfo = banner.Info{} *retInfo = *infoResponse.Info } return toolKit } /* HAC: TEST RELATION METHODS */ /* HAC: END TEST RELATION METHODS */