55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package vidmod
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestWatchCountRespJSONIncludesTotal(t *testing.T) {
|
|
data, err := json.Marshal(WatchCountResp{
|
|
IsCan: true,
|
|
WatchCount: 2,
|
|
TotalWatchCount: 3,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(data), `"totalWatchCount":3`) {
|
|
t.Fatalf("totalWatchCount missing from response: %s", data)
|
|
}
|
|
}
|
|
|
|
func TestVideoInfoIncludesFreeTrialFieldsWhenFalse(t *testing.T) {
|
|
for name, value := range map[string]interface{}{
|
|
"VideoInfo": VideoInfo{},
|
|
"VideoInfoResp": VideoInfoResp{},
|
|
} {
|
|
t.Run(name, func(t *testing.T) {
|
|
data, err := json.Marshal(value)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, field := range []string{
|
|
`"showFreeTrialBadge":false`,
|
|
`"freeTrialRemaining":0`,
|
|
`"canUseFreeTrial":false`,
|
|
} {
|
|
if !strings.Contains(string(data), field) {
|
|
t.Fatalf("%s missing from response: %s", field, data)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestVideoInfoRespIncludesFreeArea(t *testing.T) {
|
|
data, err := json.Marshal(VideoInfoResp{FreeArea: true})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(data), `"freeArea":true`) {
|
|
t.Fatalf("freeArea missing from response: %s", data)
|
|
}
|
|
}
|