41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
_ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
|
|
"slogan-agent/styleagent/model/dto"
|
|
)
|
|
|
|
func TestGenerateReqOccasionValidation(t *testing.T) {
|
|
valid := []string{"", "通勤", "约会", "聚会", "运动"}
|
|
for _, v := range valid {
|
|
req := &dto.OutfitGenerateReq{
|
|
StartDate: "2026-08-01", EndDate: "2026-08-02",
|
|
Location: "上海", Occasion: v,
|
|
}
|
|
if err := g.Validator().Data(req).Run(context.Background()); err != nil {
|
|
t.Fatalf("occasion %q 应通过校验: %v", v, err)
|
|
}
|
|
}
|
|
req := &dto.OutfitGenerateReq{
|
|
StartDate: "2026-08-01", EndDate: "2026-08-02",
|
|
Location: "上海", Occasion: "随便",
|
|
}
|
|
if err := g.Validator().Data(req).Run(context.Background()); err == nil {
|
|
t.Fatal("非法 occasion 应被拒绝")
|
|
}
|
|
}
|
|
|
|
func TestNormalizeOccasion(t *testing.T) {
|
|
if got := normalizeOccasion(""); got != "通勤" {
|
|
t.Fatalf("空场景应默认通勤, got %q", got)
|
|
}
|
|
if got := normalizeOccasion("约会"); got != "约会" {
|
|
t.Fatalf("非空场景应原样返回, got %q", got)
|
|
}
|
|
}
|