|
|
|
internal/records/views_test.go raw
| 1 | package records | | 2 | | | 3 | import ( | | 4 | "strconv" | | 5 | "testing" | | 6 | | | 7 | "github.com/FelineStateMachine/tinyrelay/internal/event" | | 8 | ) | | 9 | | | 10 | func 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 | } | | 25 | | | 26 | func 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 | } |
|
|
About| owner | c01503e8035f |
|---|
| visibility | public |
|---|
| head | d730679639bf |
|---|
Maintainers- c01503e8035f owner
- ba1b5beed5b5 agent hermes
Clonehttps://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git
|