@cumulusds/aws-apig-bypass 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- printWidth: 120
3
- };
@@ -1,145 +0,0 @@
1
- // @flow
2
-
3
- import type { APIGatewayHandlerClient } from "../../src/create-client";
4
- import { createAPIGatewayEvent, createClient } from "../../src";
5
- import { LambdaInvokeError } from "../../src/create-lambda-client";
6
-
7
- type ClientPayload = {};
8
-
9
- describe("createClient", () => {
10
- const FunctionName = "service-stage-function";
11
- const data = { hello: "world" };
12
- const body = JSON.stringify(data);
13
-
14
- function createLambdaClient({ StatusCode, Payload = JSON.stringify({ statusCode: 200, body }), LogResult = null }) {
15
- // $FlowFixMe
16
- const resolvedValue: Lambda$InvocationResponse = { StatusCode, Payload, LogResult };
17
-
18
- // $FlowFixMe[incompatible-call]
19
- const invoke = jest.fn(() => ({
20
- promise: jest.fn().mockResolvedValue(resolvedValue)
21
- }));
22
- const Lambda = {
23
- invoke
24
- };
25
- return { invoke, Lambda };
26
- }
27
-
28
- describe("when function exists", () => {
29
- describe("with invocation StatusCode 200", () => {
30
- const { invoke, Lambda } = createLambdaClient({ StatusCode: 200 });
31
-
32
- it("invokes the Lambda function", async () => {
33
- const client: APIGatewayHandlerClient<ClientPayload> = createClient<ClientPayload>({
34
- Lambda,
35
- FunctionName
36
- });
37
- const request = createAPIGatewayEvent();
38
- expect(await client(request)).toEqual({ data, headers: {}, status: 200 });
39
- expect(invoke).toHaveBeenCalledWith({ FunctionName, Payload: JSON.stringify(request) });
40
- });
41
-
42
- it("is unsuccessful given no request", () => {
43
- const client = createClient<ClientPayload>({
44
- Lambda,
45
- FunctionName
46
- });
47
- // $FlowFixMe[incompatible-call] this test calls the client with an invalid (undefined) argument to test a runtime error-handling branch that is not accessible with a valid argument
48
- return expect(client()).rejects.toEqual(new Error("Cannot stringify value"));
49
- });
50
- });
51
-
52
- it("is successful with payload statusCode 500", () => {
53
- const { Lambda } = createLambdaClient({
54
- StatusCode: 200,
55
- Payload: JSON.stringify({ statusCode: 500, body })
56
- });
57
- const client = createClient<ClientPayload>({
58
- Lambda,
59
- FunctionName
60
- });
61
- const request = createAPIGatewayEvent({
62
- pathParameters: {
63
- site: "sts-playground-test",
64
- jointIdentifierId: "1234"
65
- }
66
- });
67
- return expect(client(request)).resolves.toEqual({ data, headers: {}, status: 500 });
68
- });
69
-
70
- it("is unsuccessful with base64-encoded response", () => {
71
- const { Lambda } = createLambdaClient({
72
- StatusCode: 200,
73
- Payload: JSON.stringify({ statusCode: 500, isBase64Encoded: true, body: Buffer.from(body).toString("base64") })
74
- });
75
- const client = createClient<ClientPayload>({
76
- Lambda,
77
- FunctionName
78
- });
79
- const request = createAPIGatewayEvent({
80
- pathParameters: {
81
- site: "sts-playground-test",
82
- jointIdentifierId: "1234"
83
- }
84
- });
85
- return expect(client(request)).rejects.toEqual(
86
- new Error("A base64 encoded response from API Gateway handler was received, but is not supported.")
87
- );
88
- });
89
-
90
- it("is unsuccessful with AWS Lambda API StatusCode 500", () => {
91
- const { Lambda } = createLambdaClient({ StatusCode: 500, LogResult: "Ym9ya2Vu" });
92
- const client = createClient<ClientPayload>({
93
- Lambda,
94
- FunctionName
95
- });
96
- const request = createAPIGatewayEvent({
97
- pathParameters: {
98
- site: "sts-playground-test",
99
- jointIdentifierId: "1234"
100
- }
101
- });
102
- return expect(client(request)).rejects.toEqual(
103
- new LambdaInvokeError({
104
- StatusCode: 500,
105
- LogResult: "Ym9ya2Vu",
106
- Payload: JSON.stringify({ statusCode: 200, body })
107
- })
108
- );
109
- });
110
-
111
- it("is unsuccessful with undefined StatusCode", () => {
112
- const { Lambda } = createLambdaClient({});
113
- const client = createClient<ClientPayload>({
114
- Lambda,
115
- FunctionName
116
- });
117
- const request = createAPIGatewayEvent({
118
- pathParameters: {
119
- site: "sts-playground-test",
120
- jointIdentifierId: "1234"
121
- }
122
- });
123
- return expect(client(request)).rejects.toEqual(
124
- new LambdaInvokeError({ Payload: JSON.stringify({ statusCode: 200, body }) })
125
- );
126
- });
127
-
128
- it("is unsuccessful with no request payload", () => {
129
- const { Lambda } = createLambdaClient({ StatusCode: 200, Payload: null });
130
- const client = createClient<ClientPayload>({
131
- Lambda,
132
- FunctionName
133
- });
134
- const request = createAPIGatewayEvent({
135
- pathParameters: {
136
- site: "sts-playground-test",
137
- jointIdentifierId: "1234"
138
- }
139
- });
140
- return expect(client(request)).rejects.toEqual(
141
- new Error("AWS Lambda invocation API returned the wrong payload type 'object'; expected 'string'")
142
- );
143
- });
144
- });
145
- });
File without changes
File without changes