Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: api.common and api.version logic error , hard-coding in tests #144

Merged
merged 9 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions api/handler/api/common_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions api/handler/api/paper_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/west2-online/fzuhelper-server/api/rpc"
"github.com/west2-online/fzuhelper-server/kitex_gen/model"
"github.com/west2-online/fzuhelper-server/kitex_gen/paper"
"github.com/west2-online/fzuhelper-server/pkg/errno"
)

func TestGetDownloadUrl(t *testing.T) {
Expand All @@ -60,7 +61,7 @@ func TestGetDownloadUrl(t *testing.T) {
{
Name: "BindAndValidateError",
ExpectedError: false,
ExpectedResult: `{"code":"20001","message":"parameter error, 'filepath' field is a 'required' parameter` +
ExpectedResult: `{"code":"20001","message":"` + errno.ParamError.ErrorMsg + `, 'filepath' field is a 'required' parameter` +
`, but the request body does not have this parameter 'filepath'"}`,
Url: "/api/v1/paper/download",
},
Expand Down Expand Up @@ -165,7 +166,7 @@ func TestListDirFiles(t *testing.T) {
{
Name: "EmptyPath",
ExpectedError: false,
ExpectedResult: `{"code":"20001","message":"parameter error, path is empty"}`,
ExpectedResult: `{"code":"20001","message":"` + errno.ParamError.ErrorMsg + `, path is empty"}`,
ExpectUpYunResult: nil,
Path: "",
},
Expand Down Expand Up @@ -224,7 +225,7 @@ func TestGetDownloadUrlForAndroid(t *testing.T) {
{
Name: "BindAndValidateError",
ExpectedError: false,
ExpectedResult: `{"code":20001,"data":null,"msg":"parameter error, 'filepath' field is a 'required' parameter,` +
ExpectedResult: `{"code":20001,"data":null,"msg":"` + errno.ParamError.ErrorMsg + `, 'filepath' field is a 'required' parameter,` +
` but the request body does not have this parameter 'filepath'"}`,
Url: "/api/v1/paper/download",
},
Expand Down Expand Up @@ -329,7 +330,7 @@ func TestListDirFilesForAndroid(t *testing.T) {
{
Name: "EmptyPath",
ExpectedError: false,
ExpectedResult: `{"code":20001,"data":null,"msg":"parameter error, path is empty"}`,
ExpectedResult: `{"code":20001,"data":null,"msg":"` + errno.ParamError.ErrorMsg + `, path is empty"}`,
ExpectUpYunResult: nil,
Path: "",
},
Expand Down
28 changes: 10 additions & 18 deletions api/handler/api/version_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions api/handler/custom/launch_screen_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/west2-online/fzuhelper-server/api/rpc"
"github.com/west2-online/fzuhelper-server/kitex_gen/launch_screen"
"github.com/west2-online/fzuhelper-server/pkg/errno"
"github.com/west2-online/fzuhelper-server/pkg/logger"
)

// MobileGetImage .
Expand All @@ -36,7 +35,6 @@ func MobileGetImage(ctx context.Context, c *app.RequestContext) {
var req api.MobileGetImageRequest
err = c.BindAndValidate(&req)
if err != nil {
logger.Errorf("api.MobileGetImage: BindAndValidate error %v", err)
pack.RespError(c, errno.ParamError.WithError(err))
return
}
Expand Down Expand Up @@ -65,7 +63,6 @@ func AddImagePointTime(ctx context.Context, c *app.RequestContext) {
var req api.AddImagePointTimeRequest
err = c.BindAndValidate(&req)
if err != nil {
logger.Errorf("api.AddImagePointTime: BindAndValidate error %v", err)
pack.RespError(c, errno.ParamError.WithError(err))
return
}
Expand Down
9 changes: 1 addition & 8 deletions api/handler/custom/url_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion api/mw/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/west2-online/fzuhelper-server/pkg/constants"
)

const secretKeyExample = "MC4CAQAwBQYDK2VwBCIEIPAfnWESrQOyNXXHpMqx2xcgXXvPqvuSup4YLqIjMpI3"

// TestCreateExpiredToken 是一个特殊测试,旨在生成一个过期的 Token
func TestCreateExpiredToken(t *testing.T) {
// 默认生成时间是一年一个月七天前的
Expand All @@ -46,7 +48,7 @@ func TestCreateExpiredToken(t *testing.T) {
}
tokenStruct := jwt.NewWithClaims(jwt.SigningMethodEdDSA, claims)
key, err := jwt.ParseEdPrivateKeyFromPEM([]byte(fmt.Sprintf("%v\n%v\n%v", "-----BEGIN PRIVATE KEY-----",
"此处需要修改为私钥",
secretKeyExample,
"-----END PRIVATE KEY-----")))
if err != nil {
t.Errorf("parse private key failed, err: %v", err)
Expand Down
10 changes: 8 additions & 2 deletions internal/common/service/get_agreement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ package service

import (
"fmt"
"strconv"
"strings"
"testing"

"github.com/bytedance/mockey"
"github.com/stretchr/testify/assert"

"github.com/west2-online/fzuhelper-server/pkg/errno"
"github.com/west2-online/fzuhelper-server/pkg/upyun"
)

Expand All @@ -48,9 +51,12 @@ func TestGetUserAgreement(t *testing.T) {
{
name: "FileNotFound",
mockFileResult: nil,
mockFileError: fmt.Errorf("file not found"),
mockFileError: errno.UpcloudError,
expectedResult: nil,
expectedError: fmt.Errorf("CommonService.GetUserAgreement error:file not found"),
expectedError: fmt.Errorf("%s", strings.Join([]string{
"CommonService.GetUserAgreement error:[",
strconv.Itoa(errno.BizFileUploadErrorCode), "] ", errno.UpcloudError.ErrorMsg,
}, "")),
},
}

Expand Down
Loading
Loading