fix(test): replace duration-based age check with calendar-relative anchors
TestThreeMonthAgeCheck used 89*24h as "3 months minus 1 day", but 89 calendar days == exactly 3 months on dates like May 1 (Feb+Mar+Apr= 28+31+30=89). The equality case makes the >3-month eligibility check return true instead of false. Replace with AddDate-relative anchors so the test stays correct regardless of current date. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3a2d48b3b5
commit
c726de4d7c
1 changed files with 15 additions and 12 deletions
|
|
@ -253,25 +253,28 @@ func TestEngagementPruneSkipTierWithFewMaps(t *testing.T) {
|
|||
|
||||
func TestThreeMonthAgeCheck(t *testing.T) {
|
||||
// created_at must be >= 3 months ago for classic promotion.
|
||||
// Use calendar-relative anchors (AddDate) rather than fixed durations
|
||||
// to avoid day-count ambiguity across month boundaries.
|
||||
now := time.Now()
|
||||
cutoff := now.AddDate(0, -classicMinMonths, 0)
|
||||
|
||||
tests := []struct {
|
||||
createdAgo time.Duration
|
||||
eligible bool
|
||||
createdAt time.Time
|
||||
eligible bool
|
||||
label string
|
||||
}{
|
||||
{30 * 24 * time.Hour, false}, // 1 month
|
||||
{89 * 24 * time.Hour, false}, // ~3 months minus 1 day
|
||||
{90 * 24 * time.Hour, true}, // 3 months
|
||||
{180 * 24 * time.Hour, true}, // 6 months
|
||||
{365 * 24 * time.Hour, true}, // 1 year
|
||||
{now.AddDate(0, -1, 0), false, "1 month ago"},
|
||||
{cutoff.Add(time.Hour), false, "1 hour before cutoff"},
|
||||
{cutoff, true, "exactly at cutoff"},
|
||||
{cutoff.Add(-time.Hour), true, "1 hour past cutoff"},
|
||||
{now.AddDate(0, -6, 0), true, "6 months ago"},
|
||||
{now.AddDate(-1, 0, 0), true, "1 year ago"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
createdAt := now.Add(-tc.createdAgo)
|
||||
// Use a simpler check: created_at < NOW() - 3 months
|
||||
cutoff := now.AddDate(0, -classicMinMonths, 0)
|
||||
eligibleByDate := !createdAt.After(cutoff)
|
||||
eligibleByDate := !tc.createdAt.After(cutoff)
|
||||
if eligibleByDate != tc.eligible {
|
||||
t.Errorf("created %v ago: eligible=%v, want %v", tc.createdAgo, eligibleByDate, tc.eligible)
|
||||
t.Errorf("%s: eligible=%v, want %v", tc.label, eligibleByDate, tc.eligible)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue