-
Notifications
You must be signed in to change notification settings - Fork 2
/
storage_test.go
77 lines (69 loc) · 1.92 KB
/
storage_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"context"
"testing"
"github.com/bits-and-blooms/bloom/v3"
"github.com/nbd-wtf/go-nostr"
"github.com/stretchr/testify/assert"
)
func TestAfterSave(t *testing.T) {
const sourceEventPubkey = "e6230af84359c4bedd38207a349dfbf8d25ad3b767518e7231fcae03907b9282"
var tests = []struct {
name string
sourceEvent *nostr.Event
expectedContent string
expectedTags nostr.Tags
}{
{
name: "handle 1808",
sourceEvent: &nostr.Event{
ID: "source.event.id",
PubKey: sourceEventPubkey,
Kind: 1808,
Content: "a sample 1808",
},
expectedContent: "🎉 Let's gooo! nostr:npub1uc3s47zrt8ztahfcyparf80mlrf945ahvagcuu33ljhq8yrmj2pqefmzr7 just shared a track on nostr:npub1stemstrls4f5plqeqkeq43gtjhtycuqd9w25v5r5z5ygaq2n2sjsd6mul5 🙌.\n\nCheck it out at https://stemstr.app/thread/source.event.id/\n\n#stemstr #music #tunestr",
expectedTags: nostr.Tags{
{"p", sourceEventPubkey}, // Tag author
{"p", stemstrHexpub}, // Tag stemstr
{"t", "stemstr"},
{"t", "music"},
{"t", "tunestr"},
},
},
{
name: "ignore 1",
sourceEvent: &nostr.Event{
ID: "source.event.id",
PubKey: sourceEventPubkey,
Kind: 1,
Content: "a sample kind 1",
},
expectedContent: "",
expectedTags: nostr.Tags{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
store := &storage{
seenEvents: bloom.New(1000, 5),
blastr: &mockBlastr{
sendAsserter: func(event nostr.Event) {
// Make sure the message is properly rendered
assert.Equal(t, tt.expectedContent, event.Content)
// And the mentions are tagged
assert.Equal(t, tt.expectedTags, event.Tags)
},
},
}
store.AfterSave(tt.sourceEvent)
})
}
}
type mockBlastr struct {
sendAsserter func(nostr.Event)
}
func (m *mockBlastr) Send(ctx context.Context, event nostr.Event) error {
m.sendAsserter(event)
return nil
}