package store import "testing" // Normalisation is what stands between a hand-edited row (or a console built against an // older vocabulary) and a gateway that cannot decide what day it is. func TestNormalizeGatewaySettingsRefusesWhatItCannotUse(t *testing.T) { settings := normalizeGatewaySettings(GatewaySettings{ Timezone: " Not/AZone ", LogLevel: "LOUD", SessionIdleDays: -4, }) if settings.Timezone != "" { t.Fatalf("an unloadable timezone should be dropped, got %q", settings.Timezone) } if settings.LogLevel != "" { t.Fatalf("an unknown level should be dropped, got %q", settings.LogLevel) } // Session expiry cannot be switched off — a household with no expiry at all is a // database full of live Emby tokens — so a negative reads as "leave it alone". if settings.SessionIdleDays != 0 { t.Fatalf("session expiry should not be switchable off, got %d", settings.SessionIdleDays) } } func TestNormalizeGatewaySettingsDefaultsNotificationDisplayToHomeOnly(t *testing.T) { for _, value := range []string{"", "unknown"} { settings := normalizeGatewaySettings(GatewaySettings{NotificationDisplay: value}) if settings.NotificationDisplay != NotificationDisplayHomeOnly { t.Fatalf("notification display %q became %q, want %q", value, settings.NotificationDisplay, NotificationDisplayHomeOnly) } } } func TestNormalizeGatewaySettingsKeepsNotificationDisplayVocabulary(t *testing.T) { for _, value := range GatewayNotificationDisplays { settings := normalizeGatewaySettings(GatewaySettings{NotificationDisplay: " " + value + " "}) if settings.NotificationDisplay != value { t.Fatalf("notification display %q became %q", value, settings.NotificationDisplay) } } } func TestNormalizeGatewaySettingsKeepsTheThreeMeanings(t *testing.T) { settings := normalizeGatewaySettings(GatewaySettings{ Timezone: "Pacific/Auckland", LogLevel: " Debug ", SonarrAlertMinutes: -9, RadarrAlertMinutes: 0, EmbyHealthSeconds: 5, }) if settings.Timezone != "Pacific/Auckland" { t.Fatalf("a real zone should survive, got %q", settings.Timezone) } if settings.LogLevel != "debug" { t.Fatalf("a level should be trimmed and folded, got %q", settings.LogLevel) } if settings.SonarrAlertMinutes != GatewaySettingsOff { t.Fatalf("every negative should collapse to the one off value, got %d", settings.SonarrAlertMinutes) } if settings.RadarrAlertMinutes != 0 { t.Fatalf("zero must keep meaning deployed, got %d", settings.RadarrAlertMinutes) } // Below the floor rather than refused: an operator asking for a five-second probe has // said "as often as possible", and the answer to that is the fastest allowed. if settings.EmbyHealthSeconds != 10 { t.Fatalf("a value under the floor should clamp to it, got %d", settings.EmbyHealthSeconds) } }