|
1 |
| -import type { APIGatewayProxyEvent } from 'aws-lambda'; |
2 | 1 | import { describe, expect, it } from 'vitest';
|
3 | 2 | import {
|
4 | 3 | handlerResultToProxyResult,
|
5 | 4 | handlerResultToWebResponse,
|
6 | 5 | proxyEventToWebRequest,
|
7 | 6 | webResponseToProxyResult,
|
8 | 7 | } from '../../../src/rest/index.js';
|
| 8 | +import { createTestEvent } from './helpers.js'; |
9 | 9 |
|
10 | 10 | describe('Converters', () => {
|
11 | 11 | describe('proxyEventToWebRequest', () => {
|
12 |
| - const baseEvent: APIGatewayProxyEvent = { |
13 |
| - httpMethod: 'GET', |
14 |
| - path: '/test', |
15 |
| - resource: '/test', |
16 |
| - headers: {}, |
17 |
| - multiValueHeaders: {}, |
18 |
| - queryStringParameters: null, |
19 |
| - multiValueQueryStringParameters: {}, |
20 |
| - pathParameters: null, |
21 |
| - stageVariables: null, |
22 |
| - requestContext: { |
23 |
| - accountId: '123456789012', |
24 |
| - apiId: 'test-api', |
25 |
| - httpMethod: 'GET', |
26 |
| - path: '/test', |
27 |
| - requestId: 'test-request-id', |
28 |
| - resourceId: 'test-resource', |
29 |
| - resourcePath: '/test', |
30 |
| - stage: 'test', |
31 |
| - domainName: 'api.example.com', |
32 |
| - identity: { |
33 |
| - sourceIp: '127.0.0.1', |
34 |
| - }, |
35 |
| - } as any, |
36 |
| - isBase64Encoded: false, |
37 |
| - body: null, |
38 |
| - }; |
| 12 | + const baseEvent = createTestEvent('/test', 'GET'); |
39 | 13 |
|
40 | 14 | it('converts basic GET request', () => {
|
41 | 15 | // Prepare & Act
|
@@ -65,17 +39,16 @@ describe('Converters', () => {
|
65 | 39 |
|
66 | 40 | it('uses X-Forwarded-Proto header for protocol', () => {
|
67 | 41 | // Prepare
|
68 |
| - const event = { |
69 |
| - ...baseEvent, |
70 |
| - headers: { 'X-Forwarded-Proto': 'https' }, |
71 |
| - }; |
| 42 | + const event = createTestEvent('/test', 'GET', { |
| 43 | + 'X-Forwarded-Proto': 'http', |
| 44 | + }); |
72 | 45 |
|
73 | 46 | // Act
|
74 | 47 | const request = proxyEventToWebRequest(event);
|
75 | 48 |
|
76 | 49 | // Assess
|
77 | 50 | expect(request).toBeInstanceOf(Request);
|
78 |
| - expect(request.url).toBe('https://api.example.com/test'); |
| 51 | + expect(request.url).toBe('http://api.example.com/test'); |
79 | 52 | });
|
80 | 53 |
|
81 | 54 | it('handles null values in multiValueHeaders arrays', () => {
|
|
0 commit comments