Skip to content

fix(tests): date-sensitive gift tests use dynamic dates (v0.5.2) - #89

Merged
argszero merged 1 commit into
mainfrom
feat/fix-date-sensitive-tests
Aug 19, 2026
Merged

argszero merged 1 commit into
mainfrom
feat/fix-date-sensitive-tests

Conversation

@argszero

Copy link
Copy Markdown
Owner

Summary

Fixes 3 time-sensitive tests that fail after midnight: tests hardcoded 2026-08-18 dates for gift grants, so once the date rolled over the grants were already past expires_at and lazily marked expired instead of used, breaking assertions.

Affected tests (host rant 2026-08-19T10:13:47 — BUG 时间敏感测试):

  • billing::tests::settle_deducts_gift_first_then_permanent
  • gift::tests::deduct_gift_first_oldest_expiry
  • gift::tests::deduct_overflow_falls_to_permanent

Changes

  • Replace hardcoded '2026-08-18 10:00:00' / '2026-08-18 23:59:59' with SQLite dynamic dates:
    • granted_at: datetime('now')
    • expires_at (today): strftime('%Y-%m-%d 23:59:59', 'now')
    • expires_at (tomorrow): strftime('%Y-%m-%d 23:59:59', 'now', '+1 day')
    • expired-yesterday: datetime('now', '-1 day') / strftime('%Y-%m-%d 23:59:59', 'now', '-1 day')
  • Also made dynamic: settle_expired_gift_not_consumed, expired_gift_cleaned_lazily, test user created_at (new ts() helper), outside_window_no_gift (-11 days)
  • Version bumped to v0.5.2 (Cargo.toml + README)

Tests

  • cargo test — 102/102 pass (previously 3 failing)
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo fmt --check — clean
  • No hardcoded fixed-date literals remain in tests

3 tests hardcoded 2026-08-18 dates for gift grants; after midnight the
grants were expired at settle/deduct time, failing assertions expecting
'used'. Replace with SQLite dynamic dates: datetime('now') for granted_at
and strftime('%Y-%m-%d 23:59:59', 'now'[,'+1 day'|'-1 day']) for
expires_at. Also make test user created_at dynamic via a ts() helper and
bump version to v0.5.2.

Fixes: billing settle_deducts_gift_first_then_permanent /
settle_expired_gift_not_consumed; gift deduct_gift_first_oldest_expiry /
deduct_overflow_falls_to_permanent / expired_gift_cleaned_lazily.
@argszero
argszero merged commit 9db0dc4 into main Aug 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant