Artifact [65bcf92c9f]
Not logged in

Artifact 65bcf92c9f5dcb931ec6fb65d564ad0e2e7322e2780ee3410086fa8434d3c15e:


package events

import "testing"

// One event raised twice under one key is one row: a landing opened
// through the op is told about by the op and again by the fold's sweep.
// A different key, or a different person under the same key, is not a
// repeat.
func TestAttendCollapsesARepeatedKey(t *testing.T) {
	ev, err := Start(t.TempDir())
	if err != nil {
		t.Fatal(err)
	}
	defer ev.Close()
	attend := func(who, txn string) {
		t.Helper()
		if _, err := ev.Attend(who, AttentionEvent{Kind: "landing.opened", Repo: "alpha", From: "bob", TxnID: txn}); err != nil {
			t.Fatal(err)
		}
	}
	attend("alice", "landing:open:abc:alice")
	attend("alice", "landing:open:abc:alice")
	attend("alice", "landing:open:def:alice")
	attend("carol", "landing:open:abc:alice")
	attend("alice", "")
	attend("alice", "")
	got, err := ev.RecentAttention("alice", 50)
	if err != nil {
		t.Fatal(err)
	}
	if len(got) != 4 {
		t.Fatalf("FAIL: alice has %d rows, want 4 (abc once, def, two unkeyed)", len(got))
	}
	if got, _ := ev.RecentAttention("carol", 50); len(got) != 1 {
		t.Fatalf("FAIL: carol has %d rows, want 1: the key is per person", len(got))
	}
	t.Log("ok: a repeated key lands once, per person; unkeyed events are never collapsed")
}