Skip to content

test(gateway): add unit tests for LINE hybrid reply/push logic #621

@chaodu-agent

Description

@chaodu-agent

Context

PR #608 introduced the hybrid LINE Reply/Push strategy in gateway/src/main.rs. The gateway currently has zero tests. The new stateful cache and dispatch logic should have unit test coverage.

What to test

Unit tests (no HTTP mocking required)

  • Cache size bound — fill cache to REPLY_TOKEN_CACHE_MAX (10k), verify the 10,001st insert is rejected with a warn! and does not panic
  • TTL expiry — insert a token, verify it is valid immediately after insert; simulate elapsed time > REPLY_TOKEN_TTL_SECS and verify it is treated as expired
  • token_unusable predicate — extract the 400-body string matching into a helper function and test:
    • "Invalid reply token"token_unusable = true (fall back to Push)
    • "The reply token has expired"token_unusable = true
    • "Internal server error" (5xx) → token_unusable = false (no fallback, duplicate safety)
    • Unrecognized 400 body → token_unusable = false

Integration tests (requires HTTP mock, follow-up)

  • Reply API success → Push API not called
  • Reply API returns 400 with token-unusable body → fallback to Push
  • Reply API returns 5xx → no fallback (duplicate safety preserved)
  • reply_to empty → direct Push (no cache lookup attempted)

Related

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions