mirror of https://gitee.com/answerdev/answer.git
feat: add reason repo unit test
This commit is contained in:
parent
ccbf42c685
commit
915f3d1c94
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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))
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue