package test import ( "erpims/application/domain/about_us" "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" "net/http" "testing" ) func TestAboutUs(t *testing.T) { Init() defer Destroy() var aboutUsID string var totalCount int64 aboutUsInfo := new(about_us.Info) aboutUsInfos := make([]about_us.Info, 0) createUserID := strutils.SimpleUUID() updateUserID := strutils.SimpleUUID() deleteUserID := strutils.SimpleUUID() operatorUserName := strutils.SimpleUUID() companyTel := strutils.SimpleUUID() onlineShoppingTel := strutils.SimpleUUID() afterSaleTel := strutils.SimpleUUID() companyAddress := strutils.SimpleUUID() postCode := strutils.SimpleUUID() fax := strutils.SimpleUUID() email := strutils.SimpleUUID() wxMpQrCode := strutils.SimpleUUID() copyright := strutils.SimpleUUID() recordNumber := strutils.SimpleUUID() contactQrCode := strutils.SimpleUUID() newCompanyTel := strutils.SimpleUUID() newOnlineShoppingTel := strutils.SimpleUUID() newAfterSaleTel := strutils.SimpleUUID() newCompanyAddress := strutils.SimpleUUID() newPostCode := strutils.SimpleUUID() newFax := strutils.SimpleUUID() newEmail := strutils.SimpleUUID() newWxMpQrCode := strutils.SimpleUUID() newCopyright := strutils.SimpleUUID() newRecordNumber := strutils.SimpleUUID() newContactQrCode := strutils.SimpleUUID() NewToolKit(t).CreateAboutUs(companyTel, onlineShoppingTel, afterSaleTel, companyAddress, postCode, fax, email, wxMpQrCode, copyright, recordNumber, contactQrCode, createUserID, operatorUserName, &aboutUsID). GetAboutUs(aboutUsID, aboutUsInfo). AssertEqual(aboutUsID, aboutUsInfo.ID, "关于我们ID不一致"). AssertEqual(companyTel, aboutUsInfo.CompanyTel, "关于我们公司电话不一致"). AssertEqual(onlineShoppingTel, aboutUsInfo.OnlineShoppingTel, "关于我们网购热线不一致"). AssertEqual(afterSaleTel, aboutUsInfo.AfterSaleTel, "关于我们访问路径不一致"). AssertEqual(companyAddress, aboutUsInfo.CompanyAddress, "关于我们公司地址不一致"). AssertEqual(postCode, aboutUsInfo.PostCode, "关于我们邮编不一致"). AssertEqual(fax, aboutUsInfo.Fax, "关于我们传真不一致"). AssertEqual(email, aboutUsInfo.Email, "关于我们邮箱不一致"). AssertEqual(wxMpQrCode, aboutUsInfo.WxMpQrCode, "关于我们微信公众号二维码不一致"). AssertEqual(copyright, aboutUsInfo.Copyright, "关于我们版权所有不一致"). AssertEqual(recordNumber, aboutUsInfo.RecordNumber, "关于我们备案号不一致"). AssertEqual(contactQrCode, aboutUsInfo.ContactQrCode, "关于我们联系方式二维码不一致"). AssertEqual(createUserID, aboutUsInfo.CreateUserID, "创建用户ID不一致"). AssertEqual(createUserID, aboutUsInfo.LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(aboutUsInfo.CreatedTime, "创建时间为空"). AssertNotEmpty(aboutUsInfo.LastUpdatedTime, "最近更新时间为空"). GetAboutUses(companyTel, onlineShoppingTel, afterSaleTel, companyAddress, postCode, fax, email, wxMpQrCode, copyright, recordNumber, contactQrCode, "1", "1", &aboutUsInfos, &totalCount). AssertEqual(int(totalCount), len(aboutUsInfos), "总数不一致"). AssertEqual(aboutUsID, aboutUsInfos[0].ID, "关于我们ID不一致"). AssertEqual(companyTel, aboutUsInfos[0].CompanyTel, "关于我们公司电话不一致"). AssertEqual(onlineShoppingTel, aboutUsInfos[0].OnlineShoppingTel, "关于我们网购热线不一致"). AssertEqual(afterSaleTel, aboutUsInfos[0].AfterSaleTel, "关于我们访问路径不一致"). AssertEqual(companyAddress, aboutUsInfos[0].CompanyAddress, "关于我们公司地址不一致"). AssertEqual(postCode, aboutUsInfos[0].PostCode, "关于我们邮编不一致"). AssertEqual(fax, aboutUsInfos[0].Fax, "关于我们传真不一致"). AssertEqual(email, aboutUsInfos[0].Email, "关于我们邮箱不一致"). AssertEqual(wxMpQrCode, aboutUsInfos[0].WxMpQrCode, "关于我们微信公众号二维码不一致"). AssertEqual(copyright, aboutUsInfos[0].Copyright, "关于我们版权所有不一致"). AssertEqual(recordNumber, aboutUsInfos[0].RecordNumber, "关于我们备案号不一致"). AssertEqual(contactQrCode, aboutUsInfos[0].ContactQrCode, "关于我们联系方式二维码不一致"). AssertEqual(createUserID, aboutUsInfos[0].CreateUserID, "创建用户ID不一致"). AssertEqual(createUserID, aboutUsInfos[0].LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(aboutUsInfos[0].CreatedTime, "创建时间为空"). AssertNotEmpty(aboutUsInfos[0].LastUpdatedTime, "最近更新时间为空"). GetAboutUses(companyTel, onlineShoppingTel, afterSaleTel, companyAddress, postCode, fax, email, wxMpQrCode, copyright, recordNumber, contactQrCode, "0", "0", &aboutUsInfos, &totalCount). AssertEqual(int(totalCount), len(aboutUsInfos), "总数不一致"). AssertEqual(1, len(aboutUsInfos), "关于我们数应当为1"). AssertEqual(aboutUsID, aboutUsInfos[0].ID, "关于我们ID不一致"). AssertEqual(companyTel, aboutUsInfos[0].CompanyTel, "关于我们公司电话不一致"). AssertEqual(onlineShoppingTel, aboutUsInfos[0].OnlineShoppingTel, "关于我们网购热线不一致"). AssertEqual(afterSaleTel, aboutUsInfos[0].AfterSaleTel, "关于我们访问路径不一致"). AssertEqual(companyAddress, aboutUsInfos[0].CompanyAddress, "关于我们公司地址不一致"). AssertEqual(postCode, aboutUsInfos[0].PostCode, "关于我们邮编不一致"). AssertEqual(fax, aboutUsInfos[0].Fax, "关于我们传真不一致"). AssertEqual(email, aboutUsInfos[0].Email, "关于我们邮箱不一致"). AssertEqual(wxMpQrCode, aboutUsInfos[0].WxMpQrCode, "关于我们微信公众号二维码不一致"). AssertEqual(copyright, aboutUsInfos[0].Copyright, "关于我们版权所有不一致"). AssertEqual(recordNumber, aboutUsInfos[0].RecordNumber, "关于我们备案号不一致"). AssertEqual(contactQrCode, aboutUsInfos[0].ContactQrCode, "关于我们联系方式二维码不一致"). AssertEqual(createUserID, aboutUsInfos[0].CreateUserID, "创建用户ID不一致"). AssertEqual(createUserID, aboutUsInfos[0].LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(aboutUsInfos[0].CreatedTime, "创建时间为空"). AssertNotEmpty(aboutUsInfos[0].LastUpdatedTime, "最近更新时间为空"). UpdateAboutUs(aboutUsID, newCompanyTel, newOnlineShoppingTel, newAfterSaleTel, newCompanyAddress, newPostCode, newFax, newEmail, newWxMpQrCode, newCopyright, newRecordNumber, newContactQrCode, updateUserID, operatorUserName). GetAboutUses(newCompanyTel, newOnlineShoppingTel, newAfterSaleTel, newCompanyAddress, newPostCode, newFax, newEmail, newWxMpQrCode, newCopyright, newRecordNumber, newContactQrCode, "1", "1", &aboutUsInfos, &totalCount). AssertEqual(int(totalCount), len(aboutUsInfos), "总数不一致"). AssertEqual(aboutUsID, aboutUsInfos[0].ID, "关于我们ID不一致"). AssertEqual(newCompanyTel, aboutUsInfos[0].CompanyTel, "关于我们公司电话不一致"). AssertEqual(newOnlineShoppingTel, aboutUsInfos[0].OnlineShoppingTel, "关于我们网购热线不一致"). AssertEqual(newAfterSaleTel, aboutUsInfos[0].AfterSaleTel, "关于我们访问路径不一致"). AssertEqual(newCompanyAddress, aboutUsInfos[0].CompanyAddress, "关于我们公司地址不一致"). AssertEqual(newPostCode, aboutUsInfos[0].PostCode, "关于我们邮编不一致"). AssertEqual(newFax, aboutUsInfos[0].Fax, "关于我们传真不一致"). AssertEqual(newEmail, aboutUsInfos[0].Email, "关于我们邮箱不一致"). AssertEqual(newWxMpQrCode, aboutUsInfos[0].WxMpQrCode, "关于我们微信公众号二维码不一致"). AssertEqual(newCopyright, aboutUsInfos[0].Copyright, "关于我们版权所有不一致"). AssertEqual(newRecordNumber, aboutUsInfos[0].RecordNumber, "关于我们备案号不一致"). AssertEqual(newContactQrCode, aboutUsInfos[0].ContactQrCode, "关于我们联系方式二维码不一致"). AssertEqual(createUserID, aboutUsInfos[0].CreateUserID, "创建用户ID不一致"). AssertEqual(updateUserID, aboutUsInfos[0].LastUpdateUserID, "最近更新用户ID不一致"). AssertNotEmpty(aboutUsInfos[0].CreatedTime, "创建时间为空"). AssertNotEmpty(aboutUsInfos[0].LastUpdatedTime, "最近更新时间为空"). DeleteAboutUs(aboutUsID, deleteUserID, operatorUserName). GetAboutUses(newCompanyTel, newOnlineShoppingTel, newAfterSaleTel, newCompanyAddress, newPostCode, newFax, newEmail, newWxMpQrCode, newCopyright, newRecordNumber, newContactQrCode, "1", "1", &aboutUsInfos, &totalCount). AssertEqual(int(totalCount), len(aboutUsInfos), "总数不一致"). AssertEqual(0, len(aboutUsInfos), "删除关于我们失败") } /* HAC: TEST RELATION FUNCTIONS */ /* HAC: END TEST RELATION FUNCTIONS */ func (toolKit *ToolKit) CreateAboutUs(companyTel string, onlineShoppingTel string, afterSaleTel string, companyAddress string, postCode string, fax string, email string, wxMpQrCode string, copyright string, recordNumber string, contactQrCode string, createUserID string, operatorUserName string, aboutUsID *string) *ToolKit { idResponse := new(response.IDResponse) toolKit.SetHeader("Content-Type", "application/json"). SetJsonBody(&about_us.CreateAboutUsJsonBody{ CompanyTel: companyTel, OnlineShoppingTel: onlineShoppingTel, AfterSaleTel: afterSaleTel, CompanyAddress: companyAddress, PostCode: postCode, Fax: fax, Email: email, WxMpQrCode: wxMpQrCode, Copyright: copyright, RecordNumber: recordNumber, ContactQrCode: contactQrCode, CreateUserIDJsonBody: request.CreateUserIDJsonBody{CreateUserID: createUserID}, OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName}, }). SetJsonResponse(idResponse). Request("/erpims/api/v1/aboutUs/create", http.MethodPost). AssertStatusCode(http.StatusOK). AssertEqual(true, idResponse.Success, idResponse.Msg). AssertNotEmpty(idResponse.ID, "关于我们ID为空") if aboutUsID != nil { *aboutUsID = idResponse.ID } return toolKit } func (toolKit *ToolKit) DeleteAboutUs(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/aboutUs/delete", http.MethodDelete). AssertStatusCode(http.StatusOK). AssertEqual(true, msgResponse.Success, msgResponse.Msg) return toolKit } func (toolKit *ToolKit) UpdateAboutUs(id string, companyTel string, onlineShoppingTel string, afterSaleTel string, companyAddress string, postCode string, fax string, email string, wxMpQrCode string, copyright string, recordNumber string, contactQrCode string, updateUserID string, operatorUserName string) *ToolKit { msgResponse := new(response.MsgResponse) toolKit.SetHeader("Content-Type", "application/json"). SetJsonBody(&about_us.UpdateAboutUsJsonBody{ IDJsonBody: request.IDJsonBody{ID: id}, CompanyTel: companyTel, OnlineShoppingTel: onlineShoppingTel, AfterSaleTel: afterSaleTel, CompanyAddress: companyAddress, PostCode: postCode, Fax: fax, Email: email, WxMpQrCode: wxMpQrCode, Copyright: copyright, RecordNumber: recordNumber, ContactQrCode: contactQrCode, UpdateUserIDJsonBody: request.UpdateUserIDJsonBody{UpdateUserID: updateUserID}, OperatorUserNameJsonBody: request.OperatorUserNameJsonBody{OperatorUserName: operatorUserName}, }). SetJsonResponse(msgResponse). Request("/erpims/api/v1/aboutUs/update", http.MethodPut). AssertStatusCode(http.StatusOK). AssertEqual(true, msgResponse.Success, msgResponse.Msg) return toolKit } func (toolKit *ToolKit) GetAboutUses(companyTel string, onlineShoppingTel string, afterSaleTel string, companyAddress string, postCode string, fax string, email string, wxMpQrCode string, copyright string, recordNumber string, contactQrCode string, pageNo string, pageSize string, retInfos *[]about_us.Info, retTotalCount *int64) *ToolKit { infosResponse := new(response.InfosResponse[about_us.Info]) toolKit.SetHeader("Content-Type", "application/json"). SetJsonResponse(infosResponse). SetQueryParams("companyTel", companyTel). SetQueryParams("onlineShoppingTel", onlineShoppingTel). SetQueryParams("afterSaleTel", afterSaleTel). SetQueryParams("companyAddress", companyAddress). SetQueryParams("postCode", postCode). SetQueryParams("fax", fax). SetQueryParams("email", email). SetQueryParams("wxMpQrCode", wxMpQrCode). SetQueryParams("copyright", copyright). SetQueryParams("recordNumber", recordNumber). SetQueryParams("contactQrCode", contactQrCode). SetQueryParams("pageNo", pageNo). SetQueryParams("pageSize", pageSize). Request("/erpims/api/v1/aboutUs/query", http.MethodGet). AssertStatusCode(http.StatusOK). AssertEqual(true, infosResponse.Success, infosResponse.Msg) if retInfos != nil { *retInfos = make([]about_us.Info, 0) *retInfos = append(*retInfos, infosResponse.Infos...) } if retTotalCount != nil { *retTotalCount = infosResponse.TotalCount } return toolKit } func (toolKit *ToolKit) GetAboutUs(id string, retInfo *about_us.Info) *ToolKit { infoResponse := new(response.InfoResponse[*about_us.Info]) toolKit.SetHeader("Content-Type", "application/json"). SetJsonResponse(infoResponse). SetQueryParams("id", id). Request("/erpims/api/v1/aboutUs/get", http.MethodGet). AssertStatusCode(http.StatusOK). AssertEqual(true, infoResponse.Success, infoResponse.Msg) if retInfo != nil { *retInfo = about_us.Info{} *retInfo = *infoResponse.Info } return toolKit } /* HAC: TEST RELATION METHODS */ /* HAC: END TEST RELATION METHODS */