adding a real test Method for API gateway
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
PutIntegrationResponseCommand,
|
||||
PutMethodCommand,
|
||||
PutMethodResponseCommand,
|
||||
TestInvokeMethodCommand,
|
||||
type APIGatewayClient,
|
||||
} from '@aws-sdk/client-api-gateway'
|
||||
import {AddPermissionCommand, GetFunctionCommand, RemovePermissionCommand, type LambdaClient} from '@aws-sdk/client-lambda'
|
||||
@@ -263,6 +264,47 @@ describe('AwsApiGatewayAdapter', () => {
|
||||
}
|
||||
})
|
||||
|
||||
test('tests a configured method through the AWS SDK without a deployed stage', async () => {
|
||||
const commands: unknown[] = []
|
||||
const adapter = new AwsApiGatewayAdapter(fakeClient((command) => {
|
||||
commands.push(command)
|
||||
if (command instanceof TestInvokeMethodCommand) {
|
||||
return {
|
||||
status: 201,
|
||||
body: '{"id":"order-123"}',
|
||||
headers: {'x-request-id': 'request-123'},
|
||||
multiValueHeaders: {'set-cookie': ['first', 'second']},
|
||||
log: 'Execution completed',
|
||||
latency: 17,
|
||||
}
|
||||
}
|
||||
throw new Error('Unexpected command')
|
||||
}))
|
||||
|
||||
await expect(adapter.testApiGatewayMethod('a1b2c3', {
|
||||
resourceId: 'resource456',
|
||||
httpMethod: 'POST',
|
||||
pathWithQueryString: '/orders?dryRun=true',
|
||||
body: '{"name":"Ada"}',
|
||||
headers: {'content-type': 'application/json'},
|
||||
multiValueHeaders: {'x-tag': ['one', 'two']},
|
||||
stageVariables: {environment: 'test'},
|
||||
})).resolves.toEqual({
|
||||
statusCode: 201,
|
||||
body: '{"id":"order-123"}',
|
||||
headers: {'x-request-id': 'request-123'},
|
||||
multiValueHeaders: {'set-cookie': ['first', 'second']},
|
||||
log: 'Execution completed',
|
||||
latency: 17,
|
||||
})
|
||||
expect((commands[0] as TestInvokeMethodCommand).input).toEqual({
|
||||
restApiId: 'a1b2c3', resourceId: 'resource456', httpMethod: 'POST',
|
||||
pathWithQueryString: '/orders?dryRun=true', body: '{"name":"Ada"}',
|
||||
headers: {'content-type': 'application/json'}, multiValueHeaders: {'x-tag': ['one', 'two']},
|
||||
stageVariables: {environment: 'test'},
|
||||
})
|
||||
})
|
||||
|
||||
test('lists deployed methods, Lambda integrations, and stages', async () => {
|
||||
const adapter = new AwsApiGatewayAdapter(fakeClient((command) => {
|
||||
if (command instanceof GetResourcesCommand) {
|
||||
|
||||
Reference in New Issue
Block a user