github.com/status-im/status-go@v1.1.0/protocol/communities/community_events_processing_test.go (about) 1 package communities 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/suite" 7 8 "github.com/status-im/status-go/protocol/protobuf" 9 ) 10 11 func TestEventsProcessorSuite(t *testing.T) { 12 suite.Run(t, new(EventsProcessorSuite)) 13 } 14 15 type EventsProcessorSuite struct { 16 suite.Suite 17 } 18 19 func (s *EventsProcessorSuite) TestRetainNewestEventsPerPropertyTypeID() { 20 processor := &eventsProcessor{ 21 eventsToApply: []CommunityEvent{ 22 CommunityEvent{ 23 CommunityEventClock: 1, 24 Type: protobuf.CommunityEvent_COMMUNITY_EDIT, 25 }, 26 CommunityEvent{ 27 CommunityEventClock: 2, 28 Type: protobuf.CommunityEvent_COMMUNITY_EDIT, 29 }, 30 CommunityEvent{ 31 CommunityEventClock: 3, 32 Type: protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_ACCEPT, 33 MemberToAction: "A", 34 }, 35 CommunityEvent{ 36 CommunityEventClock: 4, 37 Type: protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_REJECT, 38 MemberToAction: "A", 39 }, 40 CommunityEvent{ 41 CommunityEventClock: 5, 42 Type: protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_ACCEPT, 43 MemberToAction: "A", 44 }, 45 CommunityEvent{ 46 CommunityEventClock: 1, 47 Type: protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_ACCEPT, 48 MemberToAction: "B", 49 }, 50 }, 51 } 52 53 processor.retainNewestEventsPerEventTypeID() 54 s.Require().Len(processor.eventsToApply, 4) 55 56 processor.sortEvents() 57 58 s.Require().Equal(protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_ACCEPT, processor.eventsToApply[0].Type) 59 s.Require().EqualValues(1, processor.eventsToApply[0].CommunityEventClock) 60 61 s.Require().Equal(protobuf.CommunityEvent_COMMUNITY_EDIT, processor.eventsToApply[1].Type) 62 s.Require().EqualValues(2, processor.eventsToApply[1].CommunityEventClock) 63 64 s.Require().Equal(protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_REJECT, processor.eventsToApply[2].Type) 65 s.Require().EqualValues(4, processor.eventsToApply[2].CommunityEventClock) 66 67 s.Require().Equal(protobuf.CommunityEvent_COMMUNITY_REQUEST_TO_JOIN_ACCEPT, processor.eventsToApply[3].Type) 68 s.Require().EqualValues(5, processor.eventsToApply[3].CommunityEventClock) 69 }