Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(core): cover S3 middyfied handler #1216

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/core/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
APIGatewayProxyEvent,
APIGatewayProxyResult,
Context,
Handler as AWSLambdaHandler
Handler as AWSLambdaHandler,
S3Handler,
S3Event
} from 'aws-lambda'

// extends Handler type from aws-lambda
Expand Down Expand Up @@ -400,3 +402,11 @@ const baseHandler: AWSLambdaHandler = async (event) => {

const handler1176 = middy(baseHandler)
expectType<MiddyfiedHandler<any, any, Error, Context, {}>>(handler1176)

// Issue #1182
const s3Handler: S3Handler = async (event) => {
await Promise.all(event.Records.map(async () => await Promise.resolve()))
}

const handler1182 = middy(s3Handler)
expectType<MiddyfiedHandler<S3Event, void, Error, Context, {}>>(handler1182)
3 changes: 1 addition & 2 deletions packages/http-cors/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ test('It should return whitelisted origin (any)', async (t) => {
t.deepEqual(response, {
statusCode: 204,
headers: {
'Access-Control-Allow-Origin': 'https://another-example.com',
Vary: 'Origin'
'Access-Control-Allow-Origin': '*'
}
})
})
Expand Down
10 changes: 7 additions & 3 deletions packages/http-multipart-body-parser/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ test('It should handle invalid form data (undefined) as an UnprocessableEntity',
await handler(event, defaultContext)
} catch (e) {
t.is(e.message, 'Invalid or malformed multipart/form-data was provided')
t.is(
e.cause.data.message,
'The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received undefined'
t.true(
[
// Node 18
'The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received undefined',
// Node 20
'The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined'
].includes(e.cause.data.message)
)
}
})
Expand Down
8 changes: 4 additions & 4 deletions packages/validator/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ test('It should validate an event object with formats', async (t) => {
const event = {
body: {
date: '2000-01-01',
time: '00:00:00',
'date-time': '2000-01-01T00:00:00',
time: '00:00:00-0000',
'date-time': '2000-01-01T00:00:00-0000',
uri: 'https://example.org',
email: '[email protected]',
hostname: 'sub.example.org',
Expand All @@ -250,8 +250,8 @@ test('It should validate an event object with formats', async (t) => {

t.deepEqual(body, {
date: '2000-01-01',
time: '00:00:00',
'date-time': '2000-01-01T00:00:00',
time: '00:00:00-0000',
'date-time': '2000-01-01T00:00:00-0000',
uri: 'https://example.org',
email: '[email protected]',
hostname: 'sub.example.org',
Expand Down
Loading