123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package test
- import (
- "erpims/application/domain/advertising"
- "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 TestAdvertising(t *testing.T) {
- Init()
- defer Destroy()
- var advertisingID string
- var totalCount int64
- advertisingInfo := new(advertising.Info)
- advertisingInfos := make([]advertising.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).CreateAdvertising(title, pageUrl, picUrl, status, createUserID, operatorUserName, &advertisingID).
- GetAdvertising(advertisingID, advertisingInfo).
- AssertEqual(advertisingID, advertisingInfo.ID, "广告配置ID不一致").
- AssertEqual(title, advertisingInfo.Title, "广告配置标题不一致").
- AssertEqual(pageUrl, advertisingInfo.PageUrl, "广告配置页面路径不一致").
- AssertEqual(picUrl, advertisingInfo.PicUrl, "广告配置图片地址不一致").
- AssertEqual(status, advertisingInfo.Status, "广告配置状态 1隐藏,2显示不一致").
- AssertEqual(createUserID, advertisingInfo.CreateUserID, "创建用户ID不一致").
- AssertEqual(createUserID, advertisingInfo.LastUpdateUserID, "最近更新用户ID不一致").
- AssertNotEmpty(advertisingInfo.CreatedTime, "创建时间为空").
- AssertNotEmpty(advertisingInfo.LastUpdatedTime, "最近更新时间为空").
- GetAdvertisings(title, pageUrl, picUrl, status, "1", "1", &advertisingInfos, &totalCount).
- AssertEqual(int(totalCount), len(advertisingInfos), "总数不一致").
- AssertEqual(advertisingID, advertisingInfos[0].ID, "广告配置ID不一致").
- AssertEqual(title, advertisingInfos[0].Title, "广告配置标题不一致").
- AssertEqual(pageUrl, advertisingInfos[0].PageUrl, "广告配置页面路径不一致").
- AssertEqual(picUrl, advertisingInfos[0].PicUrl, "广告配置图片地址不一致").
- AssertEqual(status, advertisingInfos[0].Status, "广告配置状态 1隐藏,2显示不一致").
- AssertEqual(createUserID, advertisingInfos[0].CreateUserID, "创建用户ID不一致").
- AssertEqual(createUserID, advertisingInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
- AssertNotEmpty(advertisingInfos[0].CreatedTime, "创建时间为空").
- AssertNotEmpty(advertisingInfos[0].LastUpdatedTime, "最近更新时间为空").
- GetAdvertisings(title, pageUrl, picUrl, status, "0", "0", &advertisingInfos, &totalCount).
- AssertEqual(int(totalCount), len(advertisingInfos), "总数不一致").
- AssertEqual(1, len(advertisingInfos), "广告配置数应当为1").
- AssertEqual(advertisingID, advertisingInfos[0].ID, "广告配置ID不一致").
- AssertEqual(title, advertisingInfos[0].Title, "广告配置标题不一致").
- AssertEqual(pageUrl, advertisingInfos[0].PageUrl, "广告配置页面路径不一致").
- AssertEqual(picUrl, advertisingInfos[0].PicUrl, "广告配置图片地址不一致").
- AssertEqual(status, advertisingInfos[0].Status, "广告配置状态 1隐藏,2显示不一致").
- AssertEqual(createUserID, advertisingInfos[0].CreateUserID, "创建用户ID不一致").
- AssertEqual(createUserID, advertisingInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
- AssertNotEmpty(advertisingInfos[0].CreatedTime, "创建时间为空").
- AssertNotEmpty(advertisingInfos[0].LastUpdatedTime, "最近更新时间为空").
- UpdateAdvertising(advertisingID, newTitle, newPageUrl, newPicUrl, newStatus, updateUserID, operatorUserName).
- GetAdvertisings(newTitle, newPageUrl, newPicUrl, newStatus, "1", "1", &advertisingInfos, &totalCount).
- AssertEqual(int(totalCount), len(advertisingInfos), "总数不一致").
- AssertEqual(advertisingID, advertisingInfos[0].ID, "广告配置ID不一致").
- AssertEqual(newTitle, advertisingInfos[0].Title, "广告配置标题不一致").
- AssertEqual(newPageUrl, advertisingInfos[0].PageUrl, "广告配置页面路径不一致").
- AssertEqual(newPicUrl, advertisingInfos[0].PicUrl, "广告配置图片地址不一致").
- AssertEqual(newStatus, advertisingInfos[0].Status, "广告配置状态 1隐藏,2显示不一致").
- AssertEqual(createUserID, advertisingInfos[0].CreateUserID, "创建用户ID不一致").
- AssertEqual(updateUserID, advertisingInfos[0].LastUpdateUserID, "最近更新用户ID不一致").
- AssertNotEmpty(advertisingInfos[0].CreatedTime, "创建时间为空").
- AssertNotEmpty(advertisingInfos[0].LastUpdatedTime, "最近更新时间为空").
- DeleteAdvertising(advertisingID, deleteUserID, operatorUserName).
- GetAdvertisings(newTitle, newPageUrl, newPicUrl, newStatus, "1", "1", &advertisingInfos, &totalCount).
- AssertEqual(int(totalCount), len(advertisingInfos), "总数不一致").
- AssertEqual(0, len(advertisingInfos), "删除广告配置失败")
- }
- /* HAC: TEST RELATION FUNCTIONS */
- /* HAC: END TEST RELATION FUNCTIONS */
- func (toolKit *ToolKit) CreateAdvertising(title string, pageUrl string, picUrl string, status int, createUserID string, operatorUserName string, advertisingID *string) *ToolKit {
- idResponse := new(response.IDResponse)
- toolKit.SetHeader("Content-Type", "application/json").
- SetJsonBody(&advertising.CreateAdvertisingJsonBody{
- Title: title, PageUrl: pageUrl, PicUrl: picUrl, Status: status,
- CreateUserIDJsonBody: request.CreateUserIDJsonBody{CreateUserID: createUserID},
- OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName},
- }).
- SetJsonResponse(idResponse).
- Request("/erpims/api/v1/advertising/create", http.MethodPost).
- AssertStatusCode(http.StatusOK).
- AssertEqual(true, idResponse.Success, idResponse.Msg).
- AssertNotEmpty(idResponse.ID, "广告配置ID为空")
- if advertisingID != nil {
- *advertisingID = idResponse.ID
- }
- return toolKit
- }
- func (toolKit *ToolKit) DeleteAdvertising(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/advertising/delete", http.MethodDelete).
- AssertStatusCode(http.StatusOK).
- AssertEqual(true, msgResponse.Success, msgResponse.Msg)
- return toolKit
- }
- func (toolKit *ToolKit) UpdateAdvertising(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(&advertising.UpdateAdvertisingJsonBody{
- 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/advertising/update", http.MethodPut).
- AssertStatusCode(http.StatusOK).
- AssertEqual(true, msgResponse.Success, msgResponse.Msg)
- return toolKit
- }
- func (toolKit *ToolKit) GetAdvertisings(title string, pageUrl string, picUrl string, status int, pageNo string, pageSize string, retInfos *[]advertising.Info, retTotalCount *int64) *ToolKit {
- infosResponse := new(response.InfosResponse[advertising.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/advertising/query", http.MethodGet).
- AssertStatusCode(http.StatusOK).
- AssertEqual(true, infosResponse.Success, infosResponse.Msg)
- if retInfos != nil {
- *retInfos = make([]advertising.Info, 0)
- *retInfos = append(*retInfos, infosResponse.Infos...)
- }
- if retTotalCount != nil {
- *retTotalCount = infosResponse.TotalCount
- }
- return toolKit
- }
- func (toolKit *ToolKit) GetAdvertising(id string, retInfo *advertising.Info) *ToolKit {
- infoResponse := new(response.InfoResponse[*advertising.Info])
- toolKit.SetHeader("Content-Type", "application/json").
- SetJsonResponse(infoResponse).
- SetQueryParams("id", id).
- Request("/erpims/api/v1/advertising/get", http.MethodGet).
- AssertStatusCode(http.StatusOK).
- AssertEqual(true, infoResponse.Success, infoResponse.Msg)
- if retInfo != nil {
- *retInfo = advertising.Info{}
- *retInfo = *infoResponse.Info
- }
- return toolKit
- }
- /* HAC: TEST RELATION METHODS */
- /* HAC: END TEST RELATION METHODS */
|