handler.test.ts
This file
Path
src/adapter/lambda-edge/handler.test.ts
36 lines 路 1.5 KiB 路 TypeScript
Last changed by
fix(lambda-edge): Lambda@Edge GET/HEAD body error. (#2351)trkbt10before adoption72f8650
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637import { createBody, isContentTypeBinary } from './handler'
describe('isContentTypeBinary', () => { it('Should determine whether it is binary', () => { expect(isContentTypeBinary('image/png')).toBe(true) expect(isContentTypeBinary('font/woff2')).toBe(true) expect(isContentTypeBinary('image/svg+xml')).toBe(false) expect(isContentTypeBinary('image/svg+xml; charset=UTF-8')).toBe(false) expect(isContentTypeBinary('text/plain')).toBe(false) expect(isContentTypeBinary('text/plain; charset=UTF-8')).toBe(false) expect(isContentTypeBinary('text/css')).toBe(false) expect(isContentTypeBinary('text/javascript')).toBe(false) expect(isContentTypeBinary('application/json')).toBe(false) expect(isContentTypeBinary('application/ld+json')).toBe(false) expect(isContentTypeBinary('application/json; charset=UTF-8')).toBe(false) })})
describe('createBody', () => { it('Should the request be a GET or HEAD, the Request must not include a Body', () => { const data = Buffer.from('test') const body = { action: 'read-only', data: data.toString('base64'), encoding: 'base64', inputTruncated: false, }
expect(createBody('GET', body)).toEqual(undefined) expect(createBody('GET', body)).not.toEqual(data) expect(createBody('HEAD', body)).toEqual(undefined) expect(createBody('HEAD', body)).not.toEqual(data) expect(createBody('POST', body)).toEqual(data) expect(createBody('POST', body)).not.toEqual(undefined) })})