feat: add language support and tests for English and Chinese seed data
- Introduced a new package `seedlang` to handle language parsing and constants for English and Chinese. - Updated `Init` functions across various modules (kb, quickreply, skill, tag) to accept a language parameter. - Implemented English seed data for FAQs, quick replies, skills, and tags, ensuring no Chinese text is present in English data. - Added tests to verify that English seed data does not contain Chinese characters. - Removed outdated README file from the kb test data directory. - Created new test files for channel and kb to validate the absence of Chinese text in English seed data.
This commit is contained in:
Vendored
+37
-19
@@ -1,6 +1,7 @@
|
||||
package tag
|
||||
|
||||
import (
|
||||
"agent-desk/cmd/testdata/seedlang"
|
||||
"agent-desk/internal/models"
|
||||
"agent-desk/internal/pkg/enums"
|
||||
"agent-desk/internal/repositories"
|
||||
@@ -9,24 +10,8 @@ import (
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
)
|
||||
|
||||
func Init() error {
|
||||
seed := []struct {
|
||||
id int64
|
||||
parentID int64
|
||||
name string
|
||||
sortNo int
|
||||
}{
|
||||
{1, 0, "售前", 1},
|
||||
{2, 1, "AgentDesk", 1},
|
||||
{3, 2, "产品咨询", 1},
|
||||
{4, 2, "购买意向", 1},
|
||||
{5, 0, "售后", 2},
|
||||
{6, 5, "AgentDesk", 1},
|
||||
{7, 6, "问题反馈", 1},
|
||||
{8, 6, "产品部署", 2},
|
||||
{9, 6, "需求工单", 3},
|
||||
}
|
||||
|
||||
func Init(lang seedlang.Language) error {
|
||||
seed := seedItems(lang)
|
||||
return sqls.WithTransaction(func(ctx *sqls.TxContext) error {
|
||||
now := time.Now()
|
||||
for _, row := range seed {
|
||||
@@ -68,5 +53,38 @@ func Init() error {
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
type seedItem struct {
|
||||
id int64
|
||||
parentID int64
|
||||
name string
|
||||
sortNo int
|
||||
}
|
||||
|
||||
func seedItems(lang seedlang.Language) []seedItem {
|
||||
if lang == seedlang.English {
|
||||
return []seedItem{
|
||||
{1, 0, "Pre-sales", 1},
|
||||
{2, 1, "AgentDesk", 1},
|
||||
{3, 2, "Product Inquiry", 1},
|
||||
{4, 2, "Purchase Intent", 1},
|
||||
{5, 0, "After-sales", 2},
|
||||
{6, 5, "AgentDesk", 1},
|
||||
{7, 6, "Issue Feedback", 1},
|
||||
{8, 6, "Product Deployment", 2},
|
||||
{9, 6, "Feature Request", 3},
|
||||
}
|
||||
}
|
||||
return []seedItem{
|
||||
{1, 0, "售前", 1},
|
||||
{2, 1, "AgentDesk", 1},
|
||||
{3, 2, "产品咨询", 1},
|
||||
{4, 2, "购买意向", 1},
|
||||
{5, 0, "售后", 2},
|
||||
{6, 5, "AgentDesk", 1},
|
||||
{7, 6, "问题反馈", 1},
|
||||
{8, 6, "产品部署", 2},
|
||||
{9, 6, "需求工单", 3},
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
package tag
|
||||
|
||||
import (
|
||||
"agent-desk/cmd/testdata/seedlang"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var hanTextPattern = regexp.MustCompile(`\p{Han}`)
|
||||
|
||||
func TestEnglishTagSeedsDoNotContainChineseText(t *testing.T) {
|
||||
for _, item := range seedItems(seedlang.English) {
|
||||
if hanTextPattern.MatchString(item.name) {
|
||||
t.Fatalf("english tag seed contains Chinese text: %q", item.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user