Artifact 06d295d92337114424a976a57b70394295e324f70ba2e2861332820194498da2:
- File
internal/oltp/praise_test.go
— part of check-in
[f1a6be9a77]
at
2026-08-24 19:59:53
on branch praise
— Praise: vocabulary, storage, ops
Any signed-in account may praise any repository it can SEE — no capability letter, because the read gate has already decided whether the repository exists for this caller and past that gate praising is not a privilege anyone needs granting.
Per account, not per contributor: someone who has never authored an artifact can still say a repository is worth attention, which is why this cannot hang off the contributor pages.
praise.list filters by the VIEWER, never the owner. Praise is public; the existence of a private repository is not, and this is where the two meet.
UI deferred: the button belongs in the repo stats strip, which is on the unlanded clone-counts branch. (user: dmestas, size: 2703) [annotate] [blame] [check-ins using] [more...]
package oltp import ( "path/filepath" "testing" ) func praiseDB(t *testing.T) *DB { t.Helper() db, err := Open(filepath.Join(t.TempDir(), "oltp.db")) if err != nil { t.Fatal(err) } t.Cleanup(func() { db.Close() }) return db } func TestPraiseIsOnePerAccountPerRepo(t *testing.T) { db := praiseDB(t) if db.Praised("alpha", "dan") { t.Error("praised before anyone praised") } for i := 0; i < 3; i++ { if on, err := db.SetPraise("alpha", "dan", true); err != nil || !on { t.Fatalf("praise: %v %v", on, err) } } if n := db.PraiseCount("alpha"); n != 1 { t.Errorf("count = %d after praising three times; the key is the idempotency", n) } if _, err := db.SetPraise("alpha", "eve", true); err != nil { t.Fatal(err) } if n := db.PraiseCount("alpha"); n != 2 { t.Errorf("count = %d, want 2", n) } // Withdrawing is a delete, and only the withdrawer's. if on, err := db.SetPraise("alpha", "dan", false); err != nil || on { t.Fatalf("withdraw: %v %v", on, err) } if db.Praised("alpha", "dan") { t.Error("still praised after withdrawing") } if !db.Praised("alpha", "eve") { t.Error("withdrawing took someone else's praise with it") } if n := db.PraiseCount("alpha"); n != 1 { t.Errorf("count = %d, want 1", n) } } // Re-praising must not move the date, or a listing ordered by when you // praised something reshuffles on a double-click. func TestRepraiseKeepsItsPlace(t *testing.T) { db := praiseDB(t) for _, repo := range []string{"alpha", "beta", "gamma"} { if _, err := db.SetPraise(repo, "dan", true); err != nil { t.Fatal(err) } } first, err := db.PraisedBy("dan") if err != nil { t.Fatal(err) } if _, err := db.SetPraise("alpha", "dan", true); err != nil { t.Fatal(err) } again, _ := db.PraisedBy("dan") if len(first) != 3 || len(again) != 3 { t.Fatalf("listing lengths %d then %d, want 3", len(first), len(again)) } for i := range first { if first[i] != again[i] { t.Fatalf("re-praising reordered the list: %v then %v", first, again) } } } func TestPraisedByIsPerAccount(t *testing.T) { db := praiseDB(t) db.SetPraise("alpha", "dan", true) db.SetPraise("beta", "eve", true) dan, _ := db.PraisedBy("dan") if len(dan) != 1 || dan[0] != "alpha" { t.Errorf("dan praises %v, want [alpha]", dan) } if got, _ := db.PraisedBy("nobody"); len(got) != 0 { t.Errorf("an account that praised nothing lists %v", got) } } func TestPraiseRefusesAnUnnamedSubject(t *testing.T) { db := praiseDB(t) if _, err := db.SetPraise("", "dan", true); err == nil { t.Error("praised no repository") } if _, err := db.SetPraise("alpha", "", true); err == nil { t.Error("praised as nobody — praise must be attributable") } }