Some checks failed
Go / build-and-release (push) Has been cancelled
Major refactoring of event handling into clean, testable domain services: - Add pkg/event/validation: JSON hex validation, signature verification, timestamp bounds, NIP-70 protected tag validation - Add pkg/event/authorization: Policy and ACL authorization decisions, auth challenge handling, access level determination - Add pkg/event/routing: Event router registry with ephemeral and delete handlers, kind-based dispatch - Add pkg/event/processing: Event persistence, delivery to subscribers, and post-save hooks (ACL reconfig, sync, relay groups) - Reduce handle-event.go from 783 to 296 lines (62% reduction) - Add comprehensive unit tests for all new domain services - Refactor database tests to use shared TestMain setup - Fix blossom URL test expectations (missing "/" separator) - Add go-memory-optimization skill and analysis documentation - Update DDD_ANALYSIS.md to reflect completed decomposition Files modified: - app/handle-event.go: Slim orchestrator using domain services - app/server.go: Service initialization and interface wrappers - app/handle-event-types.go: Shared types (OkHelper, result types) - pkg/event/validation/*: New validation service package - pkg/event/authorization/*: New authorization service package - pkg/event/routing/*: New routing service package - pkg/event/processing/*: New processing service package - pkg/database/*_test.go: Refactored to shared TestMain - pkg/blossom/http_test.go: Fixed URL format expectations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package database
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.mleku.dev/mleku/nostr/encoders/filter"
|
|
"git.mleku.dev/mleku/nostr/encoders/kind"
|
|
"git.mleku.dev/mleku/nostr/encoders/tag"
|
|
"next.orly.dev/pkg/utils"
|
|
)
|
|
|
|
func TestQueryForKindsAuthors(t *testing.T) {
|
|
// Use shared database (read-only test)
|
|
db, ctx := GetSharedDB(t)
|
|
events := GetSharedEvents(t)
|
|
|
|
if len(events) < 2 {
|
|
t.Fatalf("Need at least 2 saved events, got %d", len(events))
|
|
}
|
|
|
|
// Test querying by kind and author
|
|
// Find an event with a specific kind and author
|
|
testKind := kind.New(1) // Kind 1 is typically text notes
|
|
kindFilter := kind.NewS(testKind)
|
|
|
|
// Use the author from events[1]
|
|
authorFilter := tag.NewFromBytesSlice(events[1].Pubkey)
|
|
|
|
idTsPk, err := db.QueryForIds(
|
|
ctx, &filter.F{
|
|
Kinds: kindFilter,
|
|
Authors: authorFilter,
|
|
},
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("Failed to query for kinds and authors: %v", err)
|
|
}
|
|
|
|
// Verify we got results
|
|
if len(idTsPk) == 0 {
|
|
t.Fatal("did not find any events with the specified kind and author")
|
|
}
|
|
|
|
// Verify the results have the correct kind and author
|
|
for i, result := range idTsPk {
|
|
// Find the event with this ID
|
|
var found bool
|
|
for _, ev := range events {
|
|
if utils.FastEqual(result.Id, ev.ID) {
|
|
found = true
|
|
if ev.Kind != testKind.K {
|
|
t.Fatalf(
|
|
"result %d has incorrect kind, got %d, expected %d",
|
|
i, ev.Kind, testKind.K,
|
|
)
|
|
}
|
|
if !utils.FastEqual(ev.Pubkey, events[1].Pubkey) {
|
|
t.Fatalf(
|
|
"result %d has incorrect author, got %x, expected %x",
|
|
i, ev.Pubkey, events[1].Pubkey,
|
|
)
|
|
}
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("result %d with ID %x not found in events", i, result.Id)
|
|
}
|
|
}
|
|
}
|