feat: add reason repo unit test

This commit is contained in:
LinkinStar 2022-10-28 17:02:24 +08:00
parent ccbf42c685
commit 915f3d1c94
4 changed files with 24 additions and 4 deletions

View File

@ -21,9 +21,9 @@ func NewReasonRepo(configRepo config.ConfigRepo) reason_common.ReasonRepo {
}
}
func (rr *reasonRepo) ListReasons(ctx context.Context, req schema.ReasonReq) (resp []schema.ReasonItem, err error) {
func (rr *reasonRepo) ListReasons(ctx context.Context, objectType, action string) (resp []schema.ReasonItem, err error) {
var (
reasonAction = fmt.Sprintf("%s.%s.reasons", req.ObjectType, req.Action)
reasonAction = fmt.Sprintf("%s.%s.reasons", objectType, action)
reasonKeys []string
cfgValue string
)

View File

@ -0,0 +1,18 @@
package repo_test
import (
"context"
"testing"
"github.com/answerdev/answer/internal/repo/config"
"github.com/answerdev/answer/internal/repo/reason"
"github.com/stretchr/testify/assert"
)
func Test_reasonRepo_ListReasons(t *testing.T) {
configRepo := config.NewConfigRepo(testDataSource)
reasonRepo := reason.NewReasonRepo(configRepo)
reasonItems, err := reasonRepo.ListReasons(context.TODO(), "question", "close")
assert.NoError(t, err)
assert.Equal(t, 4, len(reasonItems))
}

View File

@ -2,6 +2,7 @@ package reason
import (
"context"
"github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/internal/service/reason_common"
)
@ -17,5 +18,5 @@ func NewReasonService(reasonRepo reason_common.ReasonRepo) *ReasonService {
}
func (rs ReasonService) GetReasons(ctx context.Context, req schema.ReasonReq) (resp []schema.ReasonItem, err error) {
return rs.reasonRepo.ListReasons(ctx, req)
return rs.reasonRepo.ListReasons(ctx, req.ObjectType, req.Action)
}

View File

@ -2,9 +2,10 @@ package reason_common
import (
"context"
"github.com/answerdev/answer/internal/schema"
)
type ReasonRepo interface {
ListReasons(ctx context.Context, req schema.ReasonReq) (resp []schema.ReasonItem, err error)
ListReasons(ctx context.Context, objectType, action string) (resp []schema.ReasonItem, err error)
}