@@ -0,0 +1,54 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user