mail: add tests for operator-over-tier and domain sorting
TestOperatorCanOverrideTierGrant verifies an operator can raise a tier cap (tier-first, then operator grants apply). TestGrantSortsDomains verifies domain ordering stability. Both gaps caught during review.
1 file changed,
+31
−0
internal/mail/walk_grant_test.go+31 −0
diff --git a/internal/mail/walk_grant_test.go b/internal/mail/walk_grant_test.go| index 3661e1133..52d6ce4ea 100644 |
| --- a/internal/mail/walk_grant_test.go |
| +++ b/internal/mail/walk_grant_test.go |
| @@ -53,3 +53,34 @@ func TestGrantRefusesAnUndeclaredApp(t *testing.T) { |
| t.Fatalf("= %v, want ErrNotDeclared", err) |
| } |
| } |
| + |
| +// An operator must be able to override a tier grant. This is how an operator |
| +// raises a cap on a tiered account — the entire point of recording Source. |
| +func TestOperatorCanOverrideTierGrant(t *testing.T) { |
| + ctx, s := context.Background(), release.NewDirStore(t.TempDir()) |
| + now := time.Date(2026, 8, 19, 12, 0, 0, 0, time.UTC) |
| + Declare(ctx, s, "bag", "seapointish", "SEAPOINTISH_SMTP", "n@x.com", "paul@rslw.com", now) |
| + ApplyGrant(ctx, s, "bag", "seapointish", []string{"x.com"}, 50, "tier:free", "tier", now) |
| + rec, err := ApplyGrant(ctx, s, "bag", "seapointish", []string{"x.com"}, 5000, "operator", "paul@rslw.com", now) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if rec.Grant.DailyCap != 5000 || rec.Grant.Source != "operator" { |
| + t.Fatalf("operator override failed: got DailyCap=%d Source=%q, want 5000/operator", rec.Grant.DailyCap, rec.Grant.Source) |
| + } |
| +} |
| + |
| +// Domains are sorted before storage for consistency, so grant lookups are |
| +// stable regardless of the order they were supplied in. |
| +func TestGrantSortsDomains(t *testing.T) { |
| + ctx, s := context.Background(), release.NewDirStore(t.TempDir()) |
| + now := time.Date(2026, 8, 19, 12, 0, 0, 0, time.UTC) |
| + Declare(ctx, s, "bag", "seapointish", "SEAPOINTISH_SMTP", "n@x.com", "paul@rslw.com", now) |
| + rec, err := ApplyGrant(ctx, s, "bag", "seapointish", []string{"z.com", "a.com", "m.com"}, 50, "tier:free", "tier", now) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if rec.Grant.Domains[0] != "a.com" || rec.Grant.Domains[1] != "m.com" || rec.Grant.Domains[2] != "z.com" { |
| + t.Fatalf("domains not sorted: %v", rec.Grant.Domains) |
| + } |
| +} |