Skip to content

test(aws-lambda): expand handler unit tests for processors and createResult#4744

Open
rokasta12 wants to merge 2 commits intohonojs:mainfrom
rokasta12:feat/aws-lambda-handler-tests
Open

test(aws-lambda): expand handler unit tests for processors and createResult#4744
rokasta12 wants to merge 2 commits intohonojs:mainfrom
rokasta12:feat/aws-lambda-handler-tests

Conversation

@rokasta12
Copy link
Copy Markdown
Contributor

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

Adds 48 new unit tests to src/adapter/aws-lambda/handler.test.ts, expanding coverage from 12 to 60 test cases. The handler.ts coverage improves to 77% statements, 90% branches, 85% functions.

What's covered

ALBProcessor (previously untested at the unit level)

  • createRequest with single-value and multi-value headers
  • getQueryString with queryStringParameters and multiValueQueryStringParameters
  • Priority of multiValueQueryStringParameters over queryStringParameters
  • Cookie extraction from both header formats
  • Base64-encoded body decoding

createResult

  • multiValueHeaders vs headers format based on event type
  • content-encoding binary detection (gzip/br triggering base64)
  • set-cookie handling for all 4 event types:
    • V2 → result.cookies array
    • V1 → result.multiValueHeaders['set-cookie']
    • ALB (single headers) → serialized with ,
    • ALB (multi-value) → result.multiValueHeaders['set-cookie']
    • Lattice → serialized with , into result.headers
  • Empty body (204) and custom status codes

getDomainName fallback chain

  • requestContext.domainName (API Gateway)
  • headers.host (ALB)
  • multiValueHeaders.host (ALB with multi-value enabled)
  • Lattice host from array headers

getProcessor

  • All 4 processor types: ALBProcessor, EventV1Processor, EventV2Processor, LatticeV2Processor

Non-ASCII header sanitization

  • V1 multiValueHeaders with non-ASCII values
  • ALB single headers with non-ASCII values
  • ALB multiValueHeaders joining with ; and sanitizing

Base64 body decoding

  • V1 and V2 events with isBase64Encoded: true
  • Pass-through for non-base64 bodies

LatticeV2Processor

  • Query string from path (getQueryString returns '')
  • Set-cookie serialization

…Result

Add 48 new unit tests covering:
- ALBProcessor: createRequest, headers, multiValueHeaders, query strings,
  multiValueQueryStringParameters, cookies (single/multi-value)
- createResult: multiValueHeaders format, content-encoding binary,
  set-cookie handling for V1/V2/ALB/Lattice, status codes, empty body
- Base64 body decoding for V1 and V2 events
- getDomainName fallback: host header, multiValueHeaders host
- getProcessor: all 4 processor types (ALB, V1, V2, Lattice)
- Non-ASCII header sanitization for V1 multiValueHeaders and ALB
- LatticeV2Processor: query string behavior, set-cookie handling

handler.ts coverage: 77% statements, 90% branches, 85% functions
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.48%. Comparing base (d2ed2e9) to head (c3b5bf6).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4744   +/-   ##
=======================================
  Coverage   91.48%   91.48%           
=======================================
  Files         177      177           
  Lines       11556    11556           
  Branches     3358     3359    +1     
=======================================
  Hits        10572    10572           
  Misses        983      983           
  Partials        1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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