1package search
2
3import (
4 "encoding/json"
5 "io"
6 "os"
7 "testing"
8
9 appbsky "github.com/bluesky-social/indigo/api/bsky"
10 "github.com/bluesky-social/indigo/atproto/identity"
11 "github.com/bluesky-social/indigo/atproto/syntax"
12
13 "github.com/stretchr/testify/assert"
14)
15
16func TestParseEmojis(t *testing.T) {
17 assert := assert.New(t)
18
19 assert.Equal(parseEmojis("bunch 🎅 of 🏡 emoji 🤰and 🫄 some 👩👩👧👧 compound"), []string{"🎅", "🏡", "🤰", "🫄", "👩👩👧👧"})
20
21 assert.Equal(parseEmojis("more ⛄ from ☠ lower ⛴ range"), []string{"⛄", "☠", "⛴"})
22 assert.True(parseEmojis("blah") == nil)
23}
24
25type profileFixture struct {
26 DID string `json:"did"`
27 Handle string `json:"handle"`
28 Rkey string `json:"rkey"`
29 Cid string `json:"cid"`
30 DocId string `json:"doc_id"`
31 ProfileRecord *appbsky.ActorProfile
32 ProfileDoc ProfileDoc
33}
34
35func TestTransformProfileFixtures(t *testing.T) {
36 f, err := os.Open("testdata/transform-profile-fixtures.json")
37 if err != nil {
38 t.Fatal(err)
39 }
40 defer f.Close()
41
42 fixBytes, err := io.ReadAll(f)
43 if err != nil {
44 t.Fatal(err)
45 }
46
47 var fixtures []profileFixture
48 if err := json.Unmarshal(fixBytes, &fixtures); err != nil {
49 t.Fatal(err)
50 }
51
52 for _, row := range fixtures {
53 _ = row
54 testProfileFixture(t, row)
55 }
56}
57
58func testProfileFixture(t *testing.T, row profileFixture) {
59 assert := assert.New(t)
60
61 repo := identity.Identity{
62 Handle: syntax.Handle(row.Handle),
63 DID: syntax.DID(row.DID),
64 }
65 doc := TransformProfile(row.ProfileRecord, &repo, row.Cid)
66 doc.DocIndexTs = "2006-01-02T15:04:05.000Z"
67 assert.Equal(row.ProfileDoc, doc)
68 assert.Equal(row.DocId, doc.DocId())
69}
70
71type postFixture struct {
72 DID string `json:"did"`
73 Handle string `json:"handle"`
74 Rkey string `json:"rkey"`
75 Cid string `json:"cid"`
76 DocId string `json:"doc_id"`
77 PostRecord *appbsky.FeedPost
78 PostDoc PostDoc
79}
80
81func TestTransformPostFixtures(t *testing.T) {
82 f, err := os.Open("testdata/transform-post-fixtures.json")
83 if err != nil {
84 t.Fatal(err)
85 }
86 defer f.Close()
87
88 fixBytes, err := io.ReadAll(f)
89 if err != nil {
90 t.Fatal(err)
91 }
92
93 var fixtures []postFixture
94 if err := json.Unmarshal(fixBytes, &fixtures); err != nil {
95 t.Fatal(err)
96 }
97
98 for _, row := range fixtures {
99 _ = row
100 testPostFixture(t, row)
101 }
102}
103
104func testPostFixture(t *testing.T, row postFixture) {
105 assert := assert.New(t)
106
107 repo := identity.Identity{
108 Handle: syntax.Handle(row.Handle),
109 DID: syntax.DID(row.DID),
110 }
111 doc := TransformPost(row.PostRecord, repo.DID, row.Rkey, row.Cid)
112 doc.DocIndexTs = "2006-01-02T15:04:05.000Z"
113 assert.Equal(row.PostDoc, doc)
114 assert.Equal(row.DocId, doc.DocId())
115}