Skip to content
Myr

handler.test.ts

This file

Path

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

169 lines · 5.5 KiB · TypeScript

Last changed by

fix(aws-lambda): avoid duplicating already set headers (#2585)Aluisio Amorimbefore adoptionc95e135

History of this file

Take it

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

fix(aws-lambda): avoid duplicating already set headers (#2585)Aluisio Amorimbefore adoptionc95e135

lines 1–2why, one step back
1import type { LambdaEvent } from './handler'
2import { getProcessor, isContentEncodingBinary, isContentTypeBinary } from './handler'

fix(jsx): use self closing tag only if element has no children (#2384)Taku Amanobefore adoption31d2ea4

lines 3–28why, one step back
3
4describe('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)16 expect(isContentTypeBinary('application/json; charset=UTF-8')).toBe(false)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)

fix(aws-lambda): avoid duplicating already set headers (#2585)Aluisio Amorimbefore adoptionc95e135

lines 29–167why, one step back
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 },48 queryStringParameters: {49 parameter2: 'value',50 },51 multiValueQueryStringParameters: {52 parameter1: ['value1', 'value2'],53 parameter2: ['value'],54 },55 requestContext: {56 accountId: '123456789012',57 apiId: 'id',58 authorizer: {59 claims: null,60 scopes: null,61 },62 domainName: 'id.execute-api.us-east-1.amazonaws.com',63 domainPrefix: 'id',64 extendedRequestId: 'request-id',65 httpMethod: 'GET',66 identity: {67 sourceIp: '192.0.2.1',68 userAgent: 'user-agent',69 clientCert: {70 clientCertPem: 'CERT_CONTENT',71 subjectDN: 'www.example.com',72 issuerDN: 'Example issuer',73 serialNumber: 'a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1',74 validity: {75 notBefore: 'May 28 12:30:02 2019 GMT',76 notAfter: 'Aug 5 09:36:04 2021 GMT',77 },78 },79 },80 path: '/my/path',81 protocol: 'HTTP/1.1',82 requestId: 'id=',83 requestTime: '04/Mar/2020:19:15:17 +0000',84 requestTimeEpoch: 1583349317135,85 resourcePath: '/my/path',86 stage: '$default',87 },88 pathParameters: {},89 stageVariables: {},90 body: null,91 isBase64Encoded: false,92 }9394 const processor = getProcessor(event)95 const request = processor.createRequest(event)9697 expect(request.method).toEqual('GET')98 expect(request.url).toEqual(99 'https://id.execute-api.us-east-1.amazonaws.com/my/path?parameter2=value'100 )101 expect(Object.fromEntries(request.headers)).toEqual({102 'content-type': 'application/json',103 header1: 'value1',104 header2: 'value1, value2, value3',105 })106 })107108 it('Should return valid Request object from version 2.0 API Gateway event', () => {109 const event: LambdaEvent = {110 version: '2.0',111 routeKey: '$default',112 rawPath: '/my/path',113 rawQueryString: 'parameter1=value1&parameter1=value2&parameter2=value',114 cookies: ['cookie1', 'cookie2'],115 headers: {116 'content-type': 'application/json',117 header1: 'value1',118 header2: 'value1,value2',119 },120 queryStringParameters: {121 parameter1: 'value1,value2',122 parameter2: 'value',123 },124 requestContext: {125 accountId: '123456789012',126 apiId: 'api-id',127 authentication: null,128 authorizer: {},129 domainName: 'id.execute-api.us-east-1.amazonaws.com',130 domainPrefix: 'id',131 http: {132 method: 'POST',133 path: '/my/path',134 protocol: 'HTTP/1.1',135 sourceIp: '192.0.2.1',136 userAgent: 'agent',137 },138 requestId: 'id',139 routeKey: '$default',140 stage: '$default',141 time: '12/Mar/2020:19:03:58 +0000',142 timeEpoch: 1583348638390,143 },144 body: 'Hello from Lambda',145 pathParameters: {146 parameter1: 'value1',147 },148 isBase64Encoded: false,149 stageVariables: {150 stageVariable1: 'value1',151 stageVariable2: 'value2',152 },153 }154155 const processor = getProcessor(event)156 const request = processor.createRequest(event)157158 expect(request.method).toEqual('POST')159 expect(request.url).toEqual(160 'https://id.execute-api.us-east-1.amazonaws.com/my/path?parameter1=value1&parameter1=value2&parameter2=value'161 )162 expect(Object.fromEntries(request.headers)).toEqual({163 'content-type': 'application/json',164 cookie: 'cookie1; cookie2',165 header1: 'value1',166 header2: 'value1,value2',167 })

fix(jsx): use self closing tag only if element has no children (#2384)Taku Amanobefore adoption31d2ea4

lines 168–169why, one step back
168 })
169})