package notification import ( "testing" ) // TestCatalogClosure asserts that the SupportedKinds slice and the // `catalog` map agree on the kind set. This catches dropped entries // during catalog edits. func TestCatalogClosure(t *testing.T) { t.Parallel() want := SupportedKinds() if len(want) != len(catalog) { t.Fatalf("supported kinds=%d, catalog entries=%d", len(want), len(catalog)) } for _, k := range want { if _, ok := catalog[k]; !ok { t.Errorf("kind %q listed by SupportedKinds but missing from catalog", k) } } } // TestCatalogChannels enforces the per-kind channel set documented in // `backend/README.md` §10. A drift here means the README and the code // disagree — either fix the table or fix the test. func TestCatalogChannels(t *testing.T) { t.Parallel() expect := map[string][]string{ KindLobbyInviteReceived: {ChannelPush, ChannelEmail}, KindLobbyInviteRevoked: {ChannelPush}, KindLobbyApplicationSubmitted: {ChannelPush}, KindLobbyApplicationApproved: {ChannelPush, ChannelEmail}, KindLobbyApplicationRejected: {ChannelPush, ChannelEmail}, KindLobbyMembershipRemoved: {ChannelPush, ChannelEmail}, KindLobbyMembershipBlocked: {ChannelPush, ChannelEmail}, KindLobbyRaceNameRegistered: {ChannelPush}, KindLobbyRaceNamePending: {ChannelPush, ChannelEmail}, KindLobbyRaceNameExpired: {ChannelPush}, KindRuntimeImagePullFailed: {ChannelEmail}, KindRuntimeContainerStartFailed: {ChannelEmail}, KindRuntimeStartConfigInvalid: {ChannelEmail}, KindGameTurnReady: {ChannelPush}, } for kind, want := range expect { entry, ok := LookupCatalog(kind) if !ok { t.Errorf("kind %q missing from catalog", kind) continue } if len(entry.Channels) != len(want) { t.Errorf("kind %q channels=%v want %v", kind, entry.Channels, want) continue } for i, ch := range want { if entry.Channels[i] != ch { t.Errorf("kind %q channels[%d]=%s want %s", kind, i, entry.Channels[i], ch) } } } } // TestCatalogAdminOnlyForRuntime keeps the runtime kinds admin-only and // every lobby kind user-facing. func TestCatalogAdminOnlyForRuntime(t *testing.T) { t.Parallel() for kind, entry := range catalog { switch kind { case KindRuntimeImagePullFailed, KindRuntimeContainerStartFailed, KindRuntimeStartConfigInvalid: if !entry.Admin { t.Errorf("kind %q expected Admin=true", kind) } default: if entry.Admin { t.Errorf("kind %q expected Admin=false", kind) } } } }