Skip to content

Commit

Permalink
Merge pull request #1216 from naorpeled/test/add-coverage-for-s3-midd…
Browse files Browse the repository at this point in the history
…y-handler

test(core): cover S3 middyfied handler
  • Loading branch information
willfarrell authored Jun 7, 2024
2 parents 593d40b + 02528a2 commit d597cd4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
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

0 comments on commit d597cd4

Please sign in to comment.