This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / appview / models / label_test.go
1.5 kB 50 lines
1package models 2 3import ( 4 "slices" 5 "testing" 6 "time" 7 8 "github.com/bluesky-social/indigo/atproto/syntax" 9) 10 11func TestApplyLabelOps_FutureDatedOrderIndependent(t *testing.T) { 12 def := &LabelDefinition{ 13 Did: "did:plc:boltless", Rkey: "st", Name: "status", 14 ValueType: ValueType{Type: ConcreteTypeString}, 15 Scope: []string{"sh.tangled.repo.issue"}, 16 Multiple: false, 17 } 18 key := def.AtUri().String() 19 ctx := &LabelApplicationCtx{Defs: map[string]*LabelDefinition{key: def}} 20 subject := syntax.ATURI("at://did:plc:boltless/sh.tangled.repo.issue/issue1") 21 22 mk := func(rkey, val string, performed time.Time) LabelOp { 23 return LabelOp{ 24 Did: "did:plc:boltless", Rkey: rkey, Subject: subject, 25 Operation: LabelOperationAdd, OperandKey: key, OperandValue: val, 26 PerformedAt: performed, 27 } 28 } 29 30 earlier := time.Date(2100, 1, 1, 0, 0, 0, 0, time.UTC) 31 later := time.Date(2200, 1, 1, 0, 0, 0, 0, time.UTC) 32 33 fold := func(ops []LabelOp) []string { 34 st := NewLabelState() 35 ctx.ApplyLabelOps(st, ops) 36 out := st.LabelNameValues() 37 slices.Sort(out) 38 return out 39 } 40 41 forward := fold([]LabelOp{mk("aaa", "open", earlier), mk("bbb", "closed", later)}) 42 reverse := fold([]LabelOp{mk("bbb", "closed", later), mk("aaa", "open", earlier)}) 43 44 if !slices.Equal(forward, reverse) { 45 t.Fatalf("fold must be order-independent for future-dated ops: forward=%v reverse=%v", forward, reverse) 46 } 47 if !slices.Equal(forward, []string{"status:closed"}) { 48 t.Fatalf("the later createdAt must win regardless of ingest order, got %v", forward) 49 } 50}