porting all github actions from bluesky-social/indigo to tangled CI
at main 1.4 kB view raw
1package engine 2 3import ( 4 "bytes" 5 "context" 6 "testing" 7 8 appbsky "github.com/bluesky-social/indigo/api/bsky" 9 "github.com/bluesky-social/indigo/atproto/identity" 10 "github.com/bluesky-social/indigo/atproto/syntax" 11 "github.com/bluesky-social/indigo/automod/countstore" 12 13 "github.com/stretchr/testify/assert" 14) 15 16func alwaysReportAccountRule(c *RecordContext) error { 17 c.ReportAccount(ReportReasonOther, "test report") 18 return nil 19} 20 21func TestAccountReportDedupe(t *testing.T) { 22 assert := assert.New(t) 23 ctx := context.Background() 24 eng := EngineTestFixture() 25 eng.Rules = RuleSet{ 26 RecordRules: []RecordRuleFunc{ 27 alwaysReportAccountRule, 28 }, 29 } 30 31 //path := "app.bsky.feed.post/abc123" 32 cid1 := syntax.CID("cid123") 33 p1 := appbsky.FeedPost{Text: "some post blah"} 34 p1buf := new(bytes.Buffer) 35 assert.NoError(p1.MarshalCBOR(p1buf)) 36 p1cbor := p1buf.Bytes() 37 id1 := identity.Identity{ 38 DID: syntax.DID("did:plc:abc111"), 39 Handle: syntax.Handle("handle.example.com"), 40 } 41 42 // exact same event multiple times; should only report once 43 op := RecordOp{ 44 Action: CreateOp, 45 DID: id1.DID, 46 Collection: "app.bsky.feed.post", 47 RecordKey: "abc123", 48 CID: &cid1, 49 RecordCBOR: p1cbor, 50 } 51 for i := 0; i < 5; i++ { 52 assert.NoError(eng.ProcessRecordOp(ctx, op)) 53 } 54 55 reports, err := eng.Counters.GetCount(ctx, "automod-quota", "report", countstore.PeriodDay) 56 assert.NoError(err) 57 assert.Equal(1, reports) 58}