package dto import ( "encoding/json" "testing" "browser.local/platform/domain" ) func TestRuntimeLogEventDeclarationRoundTripUsesSafeProjection(t *testing.T) { body := GamePluginRuntimeProfilesBody{ LogEvents: []RuntimeLogEventBody{{ Key: "chat-message", Title: "Chat message", SourceKey: "chat-log", EventType: "chat.message", Permission: "server.logs.read", SchemaRef: "schemas/log-events/chat-message.schema.json", RetentionDays: 30, Severity: "info", }}, } profiles := body.ToDomain() if len(profiles.LogEvents) != 1 || profiles.LogEvents[0].EventType != "chat.message" || profiles.LogEvents[0].Severity != "info" { t.Fatalf("log event conversion lost declaration fields: %+v", profiles.LogEvents) } profiles.LogEvents[0].Title = "Mutated" if body.LogEvents[0].Title != "Chat message" { t.Fatal("log event domain conversion aliases request DTO data") } projection := runtimeProfilesFromDomain(domain.GamePluginRuntimeProfiles{LogEvents: profiles.LogEvents}) encoded, err := json.Marshal(projection.LogEvents[0]) if err != nil { t.Fatalf("marshal log event projection: %v", err) } var fields map[string]any if err := json.Unmarshal(encoded, &fields); err != nil { t.Fatalf("decode log event projection: %v", err) } expected := []string{"key", "title", "sourceKey", "eventType", "permission", "schemaRef", "retentionDays", "severity"} if len(fields) != len(expected) { t.Fatalf("log event projection contains unexpected fields: %s", encoded) } for _, field := range expected { if _, exists := fields[field]; !exists { t.Fatalf("log event projection is missing %q: %s", field, encoded) } } }