Skip to content
Myr

handler.test.ts

This file

Path

src/adapter/aws-lambda/handler.test.ts

171 lines · 5.6 KiB · TypeScript

Last changed by

fix: Remove `charset` parameter from MIME type of `application/json` (#3743)SaekiTominagabefore adoptionbaa231e

History of this file

Take it

The walk stopped after 200 commits: lines older than bdaaa7f point at it.

docs: `Twitter` to `X` (#3354)Yusuke Wadabefore adoptionbdaaa7f

lines 1–15why, one step back
1import type { LambdaEvent } from './handler'
2import { getProcessor, isContentEncodingBinary, isContentTypeBinary } from './handler'34describe('isContentTypeBinary', () => {5 it('Should determine whether it is binary', () => {6 expect(isContentTypeBinary('image/png')).toBe(true)7 expect(isContentTypeBinary('font/woff2')).toBe(true)8 expect(isContentTypeBinary('image/svg+xml')).toBe(false)9 expect(isContentTypeBinary('image/svg+xml; charset=UTF-8')).toBe(false)10 expect(isContentTypeBinary('text/plain')).toBe(false)11 expect(isContentTypeBinary('text/plain; charset=UTF-8')).toBe(false)12 expect(isContentTypeBinary('text/css')).toBe(false)13 expect(isContentTypeBinary('text/javascript')).toBe(false)14 expect(isContentTypeBinary('application/json')).toBe(false)15 expect(isContentTypeBinary('application/ld+json')).toBe(false)

fix: Remove `charset` parameter from MIME type of `application/json` (#3743)SaekiTominagabefore adoptionbaa231e

line 16why, one step back
16 expect(isContentTypeBinary('application/json')).toBe(false)

docs: `Twitter` to `X` (#3354)Yusuke Wadabefore adoptionbdaaa7f

lines 17–47why, one step back
17 })
18})1920describe('isContentEncodingBinary', () => {21 it('Should determine whether it is compressed', () => {22 expect(isContentEncodingBinary('gzip')).toBe(true)23 expect(isContentEncodingBinary('compress')).toBe(true)24 expect(isContentEncodingBinary('deflate')).toBe(true)25 expect(isContentEncodingBinary('br')).toBe(true)26 expect(isContentEncodingBinary('deflate, gzip')).toBe(true)27 expect(isContentEncodingBinary('')).toBe(false)28 expect(isContentEncodingBinary('unknown')).toBe(false)29 })30})3132describe('EventProcessor.createRequest', () => {33 it('Should return valid Request object from version 1.0 API Gateway event', () => {34 const event: LambdaEvent = {35 version: '1.0',36 resource: '/my/path',37 path: '/my/path',38 httpMethod: 'GET',39 headers: {40 'content-type': 'application/json',41 header1: 'value1',42 header2: 'value1',43 },44 multiValueHeaders: {45 header1: ['value1'],46 header2: ['value1', 'value2', 'value3'],47 },

fix(aws-lambda): Fix query string handling for v1 (#3717)Hollis Wubefore adoption4af04a6

lines 48–49why, one step back
48 // This value doesn't match multi value's content.
49 // We want to assert handler is using the multi value's content when both are available.

docs: `Twitter` to `X` (#3354)Yusuke Wadabefore adoptionbdaaa7f

lines 50–100why, one step back
50 queryStringParameters: {
51 parameter2: 'value',52 },53 multiValueQueryStringParameters: {54 parameter1: ['value1', 'value2'],55 parameter2: ['value'],56 },57 requestContext: {58 accountId: '123456789012',59 apiId: 'id',60 authorizer: {61 claims: null,62 scopes: null,63 },64 domainName: 'id.execute-api.us-east-1.amazonaws.com',65 domainPrefix: 'id',66 extendedRequestId: 'request-id',67 httpMethod: 'GET',68 identity: {69 sourceIp: '192.0.2.1',70 userAgent: 'user-agent',71 clientCert: {72 clientCertPem: 'CERT_CONTENT',73 subjectDN: 'www.example.com',74 issuerDN: 'Example issuer',75 serialNumber: 'a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1',76 validity: {77 notBefore: 'May 28 12:30:02 2019 GMT',78 notAfter: 'Aug 5 09:36:04 2021 GMT',79 },80 },81 },82 path: '/my/path',83 protocol: 'HTTP/1.1',84 requestId: 'id=',85 requestTime: '04/Mar/2020:19:15:17 +0000',86 requestTimeEpoch: 1583349317135,87 resourcePath: '/my/path',88 stage: '$default',89 },90 pathParameters: {},91 stageVariables: {},92 body: null,93 isBase64Encoded: false,94 }9596 const processor = getProcessor(event)97 const request = processor.createRequest(event)9899 expect(request.method).toEqual('GET')100 expect(request.url).toEqual(

fix(aws-lambda): Fix query string handling for v1 (#3717)Hollis Wubefore adoption4af04a6

line 101why, one step back
101 'https://id.execute-api.us-east-1.amazonaws.com/my/path?parameter1=value1&parameter1=value2&parameter2=value'

docs: `Twitter` to `X` (#3354)Yusuke Wadabefore adoptionbdaaa7f

lines 102–171why, one step back
102 )
103 expect(Object.fromEntries(request.headers)).toEqual({104 'content-type': 'application/json',105 header1: 'value1',106 header2: 'value1, value2, value3',107 })108 })109110 it('Should return valid Request object from version 2.0 API Gateway event', () => {111 const event: LambdaEvent = {112 version: '2.0',113 routeKey: '$default',114 rawPath: '/my/path',115 rawQueryString: 'parameter1=value1&parameter1=value2&parameter2=value',116 cookies: ['cookie1', 'cookie2'],117 headers: {118 'content-type': 'application/json',119 header1: 'value1',120 header2: 'value1,value2',121 },122 queryStringParameters: {123 parameter1: 'value1,value2',124 parameter2: 'value',125 },126 requestContext: {127 accountId: '123456789012',128 apiId: 'api-id',129 authentication: null,130 authorizer: {},131 domainName: 'id.execute-api.us-east-1.amazonaws.com',132 domainPrefix: 'id',133 http: {134 method: 'POST',135 path: '/my/path',136 protocol: 'HTTP/1.1',137 sourceIp: '192.0.2.1',138 userAgent: 'agent',139 },140 requestId: 'id',141 routeKey: '$default',142 stage: '$default',143 time: '12/Mar/2020:19:03:58 +0000',144 timeEpoch: 1583348638390,145 },146 body: 'Hello from Lambda',147 pathParameters: {148 parameter1: 'value1',149 },150 isBase64Encoded: false,151 stageVariables: {152 stageVariable1: 'value1',153 stageVariable2: 'value2',154 },155 }156157 const processor = getProcessor(event)158 const request = processor.createRequest(event)159160 expect(request.method).toEqual('POST')161 expect(request.url).toEqual(162 'https://id.execute-api.us-east-1.amazonaws.com/my/path?parameter1=value1&parameter1=value2&parameter2=value'163 )164 expect(Object.fromEntries(request.headers)).toEqual({165 'content-type': 'application/json',166 cookie: 'cookie1; cookie2',167 header1: 'value1',168 header2: 'value1,value2',169 })170 })171})