Files
llm-intelligence/scripts/import_zhipu_coding_plan_test.go
phamnazage-jpg 958245537a feat(imports): add real pricing and subscription collectors
Add plan catalog and subscription schema support, seed baselines, and real importers for core domestic subscriptions plus stable official pricing sources.

This commit also hardens the shared fetch layers so the importers can support live collection and database writes instead of relying on manual placeholders alone.
2026-05-15 22:32:57 +08:00

67 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//go:build llm_script
package main
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)
func TestParseZhipuCodingPlanBuildsPromoEntry(t *testing.T) {
overviewRaw, err := os.ReadFile(filepath.Join("testdata", "zhipu_coding_plan_overview_sample.txt"))
if err != nil {
t.Fatalf("读取 overview fixture 失败: %v", err)
}
promoRaw, err := os.ReadFile(filepath.Join("testdata", "zhipu_coding_plan_promotion_sample.txt"))
if err != nil {
t.Fatalf("读取 promotion fixture 失败: %v", err)
}
plans, err := parseZhipuCodingPlanCatalog(string(overviewRaw), string(promoRaw))
if err != nil {
t.Fatalf("parseZhipuCodingPlanCatalog 返回错误: %v", err)
}
if len(plans) != 1 {
t.Fatalf("期望 1 条智谱公开活动价记录,实际 %d", len(plans))
}
if plans[0].PlanCode != "zhipu-coding-plan-promo-floor" {
t.Fatalf("planCode 错误: %q", plans[0].PlanCode)
}
if plans[0].ListPrice != 20 {
t.Fatalf("活动价错误: %v", plans[0].ListPrice)
}
if !strings.Contains(plans[0].Notes, "Lite/Pro/Max") {
t.Fatalf("备注缺少套餐分档说明: %q", plans[0].Notes)
}
if !strings.Contains(plans[0].Notes, "首单 9 折") {
t.Fatalf("备注缺少折扣说明: %q", plans[0].Notes)
}
}
func TestRunZhipuCodingPlanImportDryRunPrintsSummary(t *testing.T) {
var out bytes.Buffer
err := runZhipuCodingPlanImport(zhipuCodingPlanImportConfig{
OverviewFixture: filepath.Join("testdata", "zhipu_coding_plan_overview_sample.txt"),
PromotionFixture: filepath.Join("testdata", "zhipu_coding_plan_promotion_sample.txt"),
DryRun: true,
}, nil, &out)
if err != nil {
t.Fatalf("runZhipuCodingPlanImport 返回错误: %v", err)
}
output := out.String()
for _, want := range []string{
"source=zhipu-coding-plan-import",
"plans=1",
"provider=Zhipu AI",
"operator=Zhipu",
"dry_run=true",
} {
if !strings.Contains(output, want) {
t.Fatalf("输出缺少 %q实际: %q", want, output)
}
}
}