Files
olons_server/internal/httpapi/ai_export_test.go
T

56 lines
1.3 KiB
Go

package httpapi
import (
"archive/zip"
"bytes"
"io"
"strings"
"testing"
"time"
"git.118im.com/im_team/im_workbench/internal/store"
)
func TestAITableAnalysisDocx(t *testing.T) {
docx, err := aiTableAnalysisDocx(&store.AITableAnalysis{
RecordID: "airec_tbl_test",
FileName: "sales.xlsx",
FileType: "xlsx",
FileSize: 1234,
Topic: "销售数据",
MetricsJSON: `[{"name":"销售额","value":"12万","change_text":"+10%","trend":"up"}]`,
AlertsJSON: `[{"level":"warning","title":"异常波动","description":"订单量下降"}]`,
Interpretation: "整体销售额增长。",
CreatedAt: time.Date(2026, 9, 29, 8, 0, 0, 0, time.UTC),
})
if err != nil {
t.Fatal(err)
}
zr, err := zip.NewReader(bytes.NewReader(docx), int64(len(docx)))
if err != nil {
t.Fatalf("docx is not a zip: %v", err)
}
var document string
for _, file := range zr.File {
if file.Name != "word/document.xml" {
continue
}
rc, err := file.Open()
if err != nil {
t.Fatal(err)
}
data, err := io.ReadAll(rc)
_ = rc.Close()
if err != nil {
t.Fatal(err)
}
document = string(data)
break
}
for _, want := range []string{"销售数据", "销售额", "异常波动", "整体销售额增长"} {
if !strings.Contains(document, want) {
t.Fatalf("document.xml missing %q: %s", want, document)
}
}
}