package web import ( "testing" "git.zio.sh/cs2/simpleadmin-web/internal/live" "git.zio.sh/cs2/simpleadmin-web/internal/store" ) func TestIsClanID(t *testing.T) { for _, c := range []struct { id uint64 want bool }{ {103582791429521412, true}, // a group {103582791429521408, false}, // account 0 {76561198012345678, false}, // a player {0, false}, } { if got := isClanID(c.id); got != c.want { t.Errorf("isClanID(%d) = %v, want %v", c.id, got, c.want) } } } func TestValidClanTag(t *testing.T) { for tag, want := range map[string]bool{ "": true, "zio": true, "zio.sh": true, "twelve chars": true, "thirteen char": false, "say \"hi\"": false, "a;quit": false, "back\\slash": false, "tab\there": false, "🙂🙂🙂🙂🙂🙂": true, // 12 UTF-16 units "🙂🙂🙂🙂🙂🙂🙂": false, // 14 } { if got := validClanTag(tag); got != want { t.Errorf("validClanTag(%q) = %v, want %v", tag, got, want) } } } func TestVerifyShown(t *testing.T) { on := store.VerifySettings{Enabled: true, GroupID: "103582791429521412"} for _, c := range []struct { info verifyInfo want bool }{ {verifyInfo{Tables: true, Settings: on, Plugin: live.PluginLoaded}, true}, {verifyInfo{Tables: true, Settings: on, Plugin: live.PluginUnknown}, true}, {verifyInfo{Tables: true, Settings: on, Plugin: live.PluginMissing}, false}, {verifyInfo{Tables: false, Settings: on, Plugin: live.PluginLoaded}, false}, {verifyInfo{Tables: true, Settings: store.VerifySettings{Enabled: false, GroupID: on.GroupID}, Plugin: live.PluginLoaded}, false}, {verifyInfo{Tables: true, Settings: store.VerifySettings{Enabled: true}, Plugin: live.PluginLoaded}, false}, } { if got := c.info.Shown(); got != c.want { t.Errorf("%+v: Shown() = %v, want %v", c.info, got, c.want) } } }