商城c端前端
This commit is contained in:
@@ -44,6 +44,9 @@ type Product struct {
|
||||
Summary string `json:"summary"`
|
||||
ClaimedCount int64 `json:"claimed_count"`
|
||||
IsRecommended bool `json:"is_recommended"`
|
||||
IsLimited bool `json:"is_limited"`
|
||||
StartAt string `json:"start_at"`
|
||||
EndAt string `json:"end_at"`
|
||||
AvailableActions []string `json:"available_actions"`
|
||||
PaymentType string `json:"payment_type,omitempty"`
|
||||
DetailText string `json:"detail_text,omitempty"`
|
||||
@@ -113,7 +116,8 @@ func productFromStore(row store.ManualProduct, detail bool) Product {
|
||||
Category: Category{ID: row.CategoryID, Code: row.CategoryCode, Name: row.CategoryName},
|
||||
Name: row.Name, ShopName: row.ShopName, PriceAmount: row.PriceAmount, Currency: row.Currency,
|
||||
CoverURL: safeHTTPSURL(row.CoverURL), Summary: truncate(detailText, maxSummaryRunes),
|
||||
ClaimedCount: row.ClaimedCount, IsRecommended: row.IsRecommended,
|
||||
ClaimedCount: row.ClaimedCount, IsRecommended: row.IsRecommended, IsLimited: row.EndAt != "",
|
||||
StartAt: row.StartAt, EndAt: row.EndAt,
|
||||
AvailableActions: []string{"contact_support"}}
|
||||
if detail {
|
||||
result.PaymentType = row.PaymentType
|
||||
|
||||
@@ -25,14 +25,16 @@ func TestProductsMapsSafeCard(t *testing.T) {
|
||||
service := New(&fakeRepository{items: []store.ManualProduct{{ID: 4, ProductNo: "DEMO-P-03",
|
||||
CategoryID: 2, CategoryCode: "DAILY", CategoryName: "日用", Name: "体验商品", ShopName: "平台",
|
||||
PriceAmount: 12900, Currency: "CNY", CoverURL: "https://example.com/cover.png",
|
||||
DetailHTML: "<h3>标题</h3><script>alert(1)</script><p>内容</p>", ClaimedCount: 2, IsRecommended: true}}})
|
||||
DetailHTML: "<h3>标题</h3><script>alert(1)</script><p>内容</p>", ClaimedCount: 2, IsRecommended: true,
|
||||
StartAt: "2026-10-01T00:00:00Z", EndAt: "2026-10-31T00:00:00Z"}}})
|
||||
|
||||
result, err := service.Products(context.Background(), 0, 0, 1, 20)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(result.Items) != 1 || result.Items[0].CoverURL == "" || result.Items[0].Summary != "标题 内容" ||
|
||||
len(result.Items[0].AvailableActions) != 1 || result.Items[0].AvailableActions[0] != "contact_support" {
|
||||
!result.Items[0].IsLimited || result.Items[0].EndAt == "" || len(result.Items[0].AvailableActions) != 1 ||
|
||||
result.Items[0].AvailableActions[0] != "contact_support" {
|
||||
t.Fatalf("unexpected product: %#v", result.Items)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user