61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package config
|
||
|
||
import (
|
||
"encoding/json"
|
||
"testing"
|
||
)
|
||
|
||
func TestRemoteConfigDefaultsAreComplete(t *testing.T) {
|
||
document, err := loadRemoteConfig("")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if document.SchemaVersion != 1 || document.ConfigVersion != 1 {
|
||
t.Fatalf("unexpected versions: %+v", document)
|
||
}
|
||
if document.Copy.Navigation.Favourites != "Favourites" {
|
||
t.Fatalf("favourites label = %q", document.Copy.Navigation.Favourites)
|
||
}
|
||
if !document.ContinueWatching.IncludeNextUp || len(document.Home.Sections) == 0 {
|
||
t.Fatalf("central defaults are incomplete: %+v", document)
|
||
}
|
||
}
|
||
|
||
func TestRemoteConfigDefaultsMissingNewSectionsForOlderDocuments(t *testing.T) {
|
||
raw := `{"schemaVersion":1,"configVersion":3,"copy":{"navigation":{"home":"Home","forYou":"For You","search":"Search","movies":"Movies","tvShows":"TV Shows","tvCalendar":"TV Calendar","favourites":"Favourites","user":"User","settings":"Settings"},"tagline":"Matt’s Android TV client"},"features":{"showNavigationVersion":true},"presentation":{"navigationRailExpandedWidthDp":184,"navigationContentShiftDp":112}}`
|
||
document, err := loadRemoteConfig(raw)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if !document.ContinueWatching.Enabled || document.Search.MaxResults != 50 {
|
||
t.Fatalf("new fields did not receive defaults: %+v", document)
|
||
}
|
||
}
|
||
|
||
func TestRemoteConfigRejectsMalformedAndUnsafeDocuments(t *testing.T) {
|
||
document := DefaultRemoteConfig()
|
||
document.Presentation.NavigationRailExpandedWidthDp = 500
|
||
raw, err := json.Marshal(document)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if _, err := loadRemoteConfig(string(raw)); err == nil {
|
||
t.Fatal("unsafe presentation value was accepted")
|
||
}
|
||
|
||
if _, err := loadRemoteConfig(`{"schemaVersion":1,"unknown":true}`); err == nil {
|
||
t.Fatal("unknown fields were accepted")
|
||
}
|
||
|
||
document = DefaultRemoteConfig()
|
||
document.MinimumAppVersion = "0.3.0"
|
||
document.MaximumAppVersion = "0.2.54"
|
||
raw, err = json.Marshal(document)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if _, err := loadRemoteConfig(string(raw)); err == nil {
|
||
t.Fatal("reversed app-version bounds were accepted")
|
||
}
|
||
}
|