1. 14 Apr, 2026 2 commits
    • erio's avatar
      test: add unit tests for billing, websearch, and notify systems · 9028d208
      erio authored
      Billing (25 tests):
      - CalculateCostUnified: nil resolver fallback, token/per_request/image modes
      - GetModelPricingWithChannel: nil/partial/full channel overrides
      - resolveAccountStatsCost: four-level priority chain integration tests
      
      WebSearch (18 tests):
      - PopulateWebSearchUsage: nil input, manager states, QuotaLimit nil/*int64
      - ResetWebSearchUsage: nil manager error
      - Manager.ResetUsage: nil Redis
      - shouldEmulateWebSearch: full decision chain (8 scenarios)
      
      Notify (36 tests):
      - ParseNotifyEmails/MarshalNotifyEmails: old/new format, roundtrip
      - crossedDownward: boundary values, threshold semantics
      - checkQuotaDimCrossings: mixed dimensions, disabled/zero skip
      9028d208
    • erio's avatar
      test: add 66 unit tests for balance/quota notify + plan validation · ca673f98
      erio authored
      balance_notify_service_test.go (27 tests):
      - resolveBalanceThreshold: fixed/percentage/zero recharged/empty type
      - quotaDim.resolvedThreshold: fixed normal/exceed/equal limit, percentage 0/30/100/>100, zero/negative limit
      - sanitizeEmailHeader: CRLF/CR/LF/clean/empty/multiple newlines
      - buildQuotaDims / buildQuotaDimsFromState: all dimensions, empty extra, state-vs-account precedence
      - collectBalanceNotifyRecipients: empty, filter disabled/unverified, case-insensitive dedup, skip empty, trim
      
      balance_notify_check_test.go (16 tests):
      - CheckBalanceAfterDeduction guard clauses: nil user/disabled/global-off/threshold=0/user-override/no-crossing
      - CheckAccountQuotaAfterIncrement guards: nil account/zero cost/negative cost/global-disabled
      - getBalanceNotifyConfig: all fields, disabled, invalid threshold
      - isAccountQuotaNotifyEnabled: missing/false/true
      - getSiteName: default fallback + configured
      
      balance_notify_email_body_test.go (10 tests):
      - Guards against fmt.Sprintf arg-count mismatches in email templates
      - Verifies HTML escaping of recharge URL
      - Verifies CSS %% escape produces literal % in output
      - Verifies unlimited/percentage/over-quota display branches
      
      payment_config_plans_validation_test.go (13 tests):
      - validatePlanRequired: all 5 validation branches + whitespace handling
      ca673f98