This repository has no description
1package spindle
2
3import (
4 "context"
5 "encoding/json"
6 "testing"
7
8 "github.com/bluesky-social/indigo/atproto/syntax"
9 "github.com/bluesky-social/jetstream/pkg/models"
10
11 "tangled.org/core/api/tangled"
12 "tangled.org/core/spindle/config"
13 "tangled.org/core/tapc"
14)
15
16func TestTapProcessEventIgnoresPullRecords(t *testing.T) {
17 client := &Tap{}
18 err := client.processEvent(context.Background(), tapc.Event{
19 Type: tapc.EvtRecord,
20 Record: &tapc.RecordEventData{
21 Live: true,
22 Did: syntax.DID("did:plc:jge3zxi7lgrfnvhzcgrimeo7"),
23 Collection: syntax.NSID(tangled.RepoPullNSID),
24 Rkey: syntax.RecordKey("3mrhpypucbsg4"),
25 Action: tapc.RecordCreateAction,
26 Record: json.RawMessage(`{`),
27 },
28 })
29 if err != nil {
30 t.Fatalf("Tap.processEvent() returned an error for a pull record: %v", err)
31 }
32}
33
34func TestJetstreamToTapEventMarksPullRecordsLive(t *testing.T) {
35 tests := []struct {
36 name string
37 operation string
38 action tapc.RecordAction
39 }{
40 {name: "create", operation: models.CommitOperationCreate, action: tapc.RecordCreateAction},
41 {name: "update", operation: models.CommitOperationUpdate, action: tapc.RecordUpdateAction},
42 {name: "delete", operation: models.CommitOperationDelete, action: tapc.RecordDeleteAction},
43 }
44
45 for _, tt := range tests {
46 t.Run(tt.name, func(t *testing.T) {
47 event, ok := jetstreamToTapEvent(&models.Event{
48 Did: "did:plc:jge3zxi7lgrfnvhzcgrimeo7",
49 Kind: models.EventKindCommit,
50 Commit: &models.Commit{
51 Operation: tt.operation,
52 Collection: tangled.RepoPullNSID,
53 RKey: "3mrhpypucbsg4",
54 Record: json.RawMessage(`{"title":"test"}`),
55 },
56 })
57 if !ok {
58 t.Fatal("jetstreamToTapEvent() rejected a valid pull event")
59 }
60 if event.Record == nil {
61 t.Fatal("jetstreamToTapEvent() returned no record")
62 }
63 if !event.Record.Live {
64 t.Error("converted pull event is not live")
65 }
66 if event.Record.Collection.String() != tangled.RepoPullNSID {
67 t.Errorf("collection = %q, want %q", event.Record.Collection, tangled.RepoPullNSID)
68 }
69 if event.Record.Action != tt.action {
70 t.Errorf("action = %q, want %q", event.Record.Action, tt.action)
71 }
72 })
73 }
74}
75
76func TestEmbeddedTapDoesNotSubscribeToPullRecords(t *testing.T) {
77 tcfg := newEmbeddedTapConfig(&config.Config{})
78
79 if tcfg.SignalCollection == tangled.RepoPullNSID {
80 t.Errorf("SignalCollection = %q, must not ingest pull records", tcfg.SignalCollection)
81 }
82 for _, collection := range tcfg.CollectionFilters {
83 if collection == tangled.RepoPullNSID {
84 t.Errorf("CollectionFilters includes %q", tangled.RepoPullNSID)
85 }
86 }
87}