adding a real test Method for API gateway
This commit is contained in:
@@ -169,6 +169,34 @@ describe('API Gateway CORS routes', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('API Gateway method test routes', () => {
|
||||
test('dispatches the AWS TestInvokeMethod input without requiring a stage', async () => {
|
||||
const calls: unknown[] = []
|
||||
const app = appWithRoutes([mockAdapter('aws', {
|
||||
service: 'apigateway',
|
||||
testApiGatewayMethod: async (apiId, input) => {
|
||||
calls.push({apiId, input})
|
||||
return {statusCode: 200, body: '{}', headers: {}, multiValueHeaders: {}, log: 'ok', latency: 4}
|
||||
},
|
||||
})])
|
||||
|
||||
const response = await app.request('/api/clouds/aws/services/apigateway/resources/api-123/methods/test', {
|
||||
method: 'POST', headers: {'content-type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
resourceId: 'resource-456', httpMethod: 'POST', pathWithQueryString: '/orders?dryRun=true', body: '{}',
|
||||
headers: {'content-type': 'application/json'}, multiValueHeaders: {'x-tag': ['one', 'two']}, stageVariables: {environment: 'test'},
|
||||
}),
|
||||
})
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
expect(await response.json()).toEqual({statusCode: 200, body: '{}', headers: {}, multiValueHeaders: {}, log: 'ok', latency: 4})
|
||||
expect(calls).toEqual([{apiId: 'api-123', input: {
|
||||
resourceId: 'resource-456', httpMethod: 'POST', pathWithQueryString: '/orders?dryRun=true', body: '{}',
|
||||
headers: {'content-type': 'application/json'}, multiValueHeaders: {'x-tag': ['one', 'two']}, stageVariables: {environment: 'test'},
|
||||
}}])
|
||||
})
|
||||
})
|
||||
|
||||
describe('S3 website routes', () => {
|
||||
test('routes normalized website configuration lifecycle requests through the storage adapter', async () => {
|
||||
const calls: Array<{operation: string; args: unknown[]}> = []
|
||||
|
||||
@@ -589,6 +589,25 @@ export function createCloudRoutes(injectedService?: CloudProxyService) {
|
||||
})
|
||||
})
|
||||
|
||||
app.post('/:cloud/services/apigateway/resources/:id/methods/test', async (c) => {
|
||||
const cloud = c.req.param('cloud') as CloudProvider
|
||||
if (cloud !== 'aws') return c.json({error: 'Unknown cloud or service'}, 404)
|
||||
|
||||
return withRuntime(c, async () => {
|
||||
const input = await c.req.json<Record<string, unknown>>()
|
||||
const result = await svc(c).testApiGatewayMethod(cloud, c.req.param('id'), {
|
||||
resourceId: typeof input.resourceId === 'string' ? input.resourceId : '',
|
||||
httpMethod: typeof input.httpMethod === 'string' ? input.httpMethod : '',
|
||||
pathWithQueryString: typeof input.pathWithQueryString === 'string' ? input.pathWithQueryString : '',
|
||||
body: typeof input.body === 'string' ? input.body : '',
|
||||
headers: stringHeaders(input.headers),
|
||||
multiValueHeaders: stringArrayHeaders(input.multiValueHeaders),
|
||||
stageVariables: stringHeaders(input.stageVariables),
|
||||
})
|
||||
return c.json(result)
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/:cloud/services/storage/resources/:id/lambda-triggers', async (c) => {
|
||||
const cloud = c.req.param('cloud') as CloudProvider
|
||||
if (cloud !== 'aws') return c.json({error: 'Unknown cloud or service'}, 404)
|
||||
@@ -1178,6 +1197,13 @@ function stringHeaders(value: unknown): Record<string, string> {
|
||||
return Object.fromEntries(entries) as Record<string, string>
|
||||
}
|
||||
|
||||
function stringArrayHeaders(value: unknown): Record<string, string[]> {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return {}
|
||||
return Object.fromEntries(Object.entries(value).flatMap(([name, values]) =>
|
||||
Array.isArray(values) && values.every((header) => typeof header === 'string') ? [[name, values]] : [],
|
||||
))
|
||||
}
|
||||
|
||||
function decodeBase64(value: unknown, field: string, maxLength: number): Uint8Array {
|
||||
if (typeof value !== 'string') throw new ValidationError(`${field} must be a base64 string`)
|
||||
if (value.length > maxLength) throw new ValidationError(`${field} is too large`)
|
||||
|
||||
Reference in New Issue
Block a user