feat(notifications): send product notifications with a rights check right before each send

This commit is contained in:
shira committed 2026-10-09 20:38:39 +03:00
1 parent a856066316
commit 623d41b969
59 files changed
+4125 -1126

No files matched your search

@@ -118,3 +118,36 @@ func TestNewMailQuotaLimits(t *testing.T) {
})
}
}
func TestWithReserveLeavesEachWindowItsOwnShare(t *testing.T) {
limits, err := NewMailQuotaLimits(100, 3000)
if err != nil {
t.Fatalf("NewMailQuotaLimits() error = %v", err)
}
admission, err := limits.WithReserve(20, 600)
if err != nil {
t.Fatalf("WithReserve(20, 600) error = %v", err)
}
if admission.Daily() != 80 || admission.Monthly() != 2400 {
t.Fatalf("admission = %d a day and %d a month, want 80 and 2400", admission.Daily(), admission.Monthly())
}
if unchanged, err := limits.WithReserve(0, 0); err != nil || unchanged.Daily() != 100 || unchanged.Monthly() != 3000 {
t.Fatalf("WithReserve(0, 0) = %+v, %v; want the limits unchanged", unchanged, err)
}
}
func TestWithReserveRefusesAReserveThatLeavesNoRoom(t *testing.T) {
limits, err := NewMailQuotaLimits(100, 3000)
if err != nil {
t.Fatalf("NewMailQuotaLimits() error = %v", err)
}
for name, reserve := range map[string][2]int64{
"a daily reserve equal to the limit": {100, 0},
"a monthly reserve above the limit": {0, 3001},
"a negative reserve": {-1, 0},
} {
if _, err := limits.WithReserve(reserve[0], reserve[1]); !errors.Is(err, ErrInvalidMailQuota) {
t.Fatalf("%s: WithReserve() error = %v, want ErrInvalidMailQuota", name, err)
}
}
}