27 lines
724 B
Go
27 lines
724 B
Go
package app
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestDeduplicateJoinLeaveEventsIgnoresRepeatedReplays(t *testing.T) {
|
|
at := time.Date(2026, 7, 1, 1, 23, 45, 0, time.FixedZone("JST", 9*60*60))
|
|
events := []JoinLeaveEvent{
|
|
{At: at, Kind: "join", Name: "Alice", Count: 10},
|
|
{At: at, Kind: "join", Name: "Alice", Count: 11},
|
|
{At: at.Add(5 * time.Second), Kind: "leave", Name: "Alice", Count: 9},
|
|
}
|
|
|
|
got := dedupeJoinLeaveEvents(events)
|
|
if len(got) != 2 {
|
|
t.Fatalf("expected 2 unique events, got %d: %#v", len(got), got)
|
|
}
|
|
if got[0].Count != 10 {
|
|
t.Fatalf("expected first event to remain stable, got %#v", got[0])
|
|
}
|
|
if got[1].Kind != "leave" {
|
|
t.Fatalf("expected leave event to remain, got %#v", got[1])
|
|
}
|
|
}
|