Files
Ilia Denisov 535e27008f
Tests · Go / test (push) Successful in 1m44s
Tests · Integration / integration (pull_request) Successful in 1m44s
Tests · Go / test (pull_request) Successful in 2m45s
diplomail (Stage A): add in-game personal mail subsystem
Phase 28 of ui/PLAN.md needs a persistent player-to-player mail
channel; the existing `mail` package is a transactional email
outbox and the `notification` catalog is one-way platform events.
Stage A lands the schema (diplomail_messages / _recipients /
_translations), a single-recipient personal send/read/delete
service path, a `diplomail.message.received` push kind plumbed
through the notification pipeline, and an unread-counts endpoint
that drives the lobby badge. Admin / system mail, lifecycle hooks,
paid-tier broadcast, multi-game broadcast, bulk purge and language
detection / translation cache come in stages B–D.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 18:28:55 +02:00

81 lines
2.6 KiB
Go

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},
KindGamePaused: {ChannelPush},
KindDiplomailReceived: {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)
}
}
}
}