@@ -0,0 +1,55 @@
|
||||
package proto
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProductResUIConfigJSONContract(t *testing.T) {
|
||||
response := ProductRes{
|
||||
UIConfig: &VIPCardUIConfig{
|
||||
BackgroundImage: "vip-card-skin-a.png",
|
||||
BadgeStyles: []VIPCardBadgeStyle{{
|
||||
BadgeType: "MOST_POPULAR",
|
||||
BackgroundColor: "#2B251A",
|
||||
TextColor: "#F7D98C",
|
||||
}},
|
||||
},
|
||||
}
|
||||
data, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error = %v", err)
|
||||
}
|
||||
for _, field := range [][]byte{
|
||||
[]byte(`"uiConfig"`),
|
||||
[]byte(`"backgroundImage":"vip-card-skin-a.png"`),
|
||||
[]byte(`"badgeType":"MOST_POPULAR"`),
|
||||
[]byte(`"backgroundColor":"#2B251A"`),
|
||||
[]byte(`"textColor":"#F7D98C"`),
|
||||
} {
|
||||
if !bytes.Contains(data, field) {
|
||||
t.Fatalf("JSON response missing %s: %s", field, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProductResOmitsEmptyUIConfig(t *testing.T) {
|
||||
data, err := json.Marshal(ProductRes{})
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error = %v", err)
|
||||
}
|
||||
if bytes.Contains(data, []byte(`"uiConfig"`)) {
|
||||
t.Fatalf("legacy JSON response contains uiConfig: %s", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProductResIncludesExperimentStatus(t *testing.T) {
|
||||
data, err := json.Marshal(ProductRes{ExperimentStatus: "DISABLED"})
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal() error = %v", err)
|
||||
}
|
||||
if !bytes.Contains(data, []byte(`"experimentStatus":"DISABLED"`)) {
|
||||
t.Fatalf("JSON response missing experimentStatus: %s", data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user