|
| 1 | +const { getEventSourceNameBasedOnEvent } = require("./utils"); |
| 2 | + |
| 3 | +/** |
| 4 | +This is an event delivered by `sam local start-api`, |
| 5 | +using Type:HttpApi, with SAM CLI version 1.18.0. |
| 6 | +*/ |
| 7 | +const sam_httpapi_event = { |
| 8 | + version: "2.0", |
| 9 | + routeKey: "GET /", |
| 10 | + rawPath: "/", |
| 11 | + rawQueryString: "", |
| 12 | + cookies: [], |
| 13 | + headers: { |
| 14 | + Host: "localhost:9000", |
| 15 | + "User-Agent": "curl/7.64.1", |
| 16 | + Accept: "*/*", |
| 17 | + "X-Forwarded-Proto": "http", |
| 18 | + "X-Forwarded-Port": "9000", |
| 19 | + }, |
| 20 | + queryStringParameters: {}, |
| 21 | + requestContext: { |
| 22 | + accountId: "123456789012", |
| 23 | + apiId: "1234567890", |
| 24 | + http: { |
| 25 | + method: "GET", |
| 26 | + path: "/", |
| 27 | + protocol: "HTTP/1.1", |
| 28 | + sourceIp: "127.0.0.1", |
| 29 | + userAgent: "Custom User Agent String", |
| 30 | + }, |
| 31 | + requestId: "aacf57f7-2fce-4069-a1f2-7cb4726dc028", |
| 32 | + routeKey: "GET /", |
| 33 | + stage: null, |
| 34 | + }, |
| 35 | + body: "", |
| 36 | + pathParameters: {}, |
| 37 | + stageVariables: null, |
| 38 | + isBase64Encoded: false, |
| 39 | +}; |
| 40 | + |
| 41 | +describe("getEventSourceNameBasedOnEvent", () => { |
| 42 | + test("throws error on empty event", () => { |
| 43 | + expect(() => getEventSourceNameBasedOnEvent({ event: {} })).toThrow( |
| 44 | + "Unable to determine event source based on event." |
| 45 | + ); |
| 46 | + }); |
| 47 | + |
| 48 | + test("recognizes sam local HttpApi event", () => { |
| 49 | + const result = getEventSourceNameBasedOnEvent({ event: sam_httpapi_event }); |
| 50 | + expect(result).toEqual("AWS_API_GATEWAY_V2"); |
| 51 | + }); |
| 52 | +}); |
0 commit comments