clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

feat/standalone-relay
tinyrelay / internal / records / views_test.go
views_test.go 1.6K
1package records23import (4 "strconv"5 "testing"67 "github.com/FelineStateMachine/tinyrelay/internal/event"8)910func TestFoldKeepsProfileAndRelayForSameAuthor(t *testing.T) {11 pk := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"12 events := []event.Event{13 {Kind: event.KIND_PROFILE, PubKey: pk, Content: `{"name":"Alice"}`},14 {Kind: 10002, PubKey: pk, Tags: [][]string{{"r", "wss://relay.example/"}}},15 }16 profiles, _ := fold("profiles", events, "", 100)17 relays, _ := fold("relays", events, "", 100)18 if len(profiles) != 1 || profiles[0][1] != pk {19 t.Fatalf("profiles = %#v", profiles)20 }21 if len(relays) != 1 || relays[0][1] != "wss://relay.example" {22 t.Fatalf("relays = %#v", relays)23 }24}2526func TestFoldCalendarWindowAndArticlesUsePublishedAt(t *testing.T) {27 now := int64(1_700_000_000)28 old := event.Event{Kind: 31923, PubKey: "a", Tags: [][]string{{"d", "old"}, {"start", strconv.FormatInt(now-2*86400, 10)}}}29 future := event.Event{Kind: 31923, PubKey: "a", Tags: [][]string{{"d", "future"}, {"start", strconv.FormatInt(now+2*86400, 10)}, {"title", "Future"}}}30 cal, _ := fold("calendar", []event.Event{old, future}, "", now)31 if len(cal) != 1 || cal[0][1] != "31923:a:future" {32 t.Fatalf("calendar = %#v", cal)33 }34 late := event.Event{Kind: 30023, PubKey: "a", CreatedAt: 10, Tags: [][]string{{"d", "late"}, {"published_at", "200"}}}35 early := event.Event{Kind: 30023, PubKey: "a", CreatedAt: 20, Tags: [][]string{{"d", "early"}, {"published_at", "100"}}}36 articles, _ := fold("articles", []event.Event{late, early}, "", now)37 if len(articles) != 2 || articles[0][1] != "30023:a:late" {38 t.Fatalf("articles = %#v", articles)39 }40}