|
1 | 1 | const nock = require("nock");
|
| 2 | +const path = require("path"); |
2 | 3 |
|
3 | 4 | const { createLambdaFunction, Probot, ProbotOctokit } = require("../index");
|
4 | 5 | const app = require("./fixtures/app");
|
@@ -28,7 +29,7 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
|
28 | 29 | "/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments",
|
29 | 30 | (requestBody) => {
|
30 | 31 | expect(requestBody).toStrictEqual({
|
31 |
| - body: "Hello from test/fixtures/app.js", |
| 32 | + body: `Hello from test${path.sep}fixtures${path.sep}app.js`, |
32 | 33 | });
|
33 | 34 |
|
34 | 35 | return true;
|
@@ -65,7 +66,7 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
|
65 | 66 | "/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments",
|
66 | 67 | (requestBody) => {
|
67 | 68 | expect(requestBody).toStrictEqual({
|
68 |
| - body: "Hello from test/fixtures/app.js", |
| 69 | + body: `Hello from test${path.sep}fixtures${path.sep}app.js`, |
69 | 70 | });
|
70 | 71 |
|
71 | 72 | return true;
|
@@ -93,4 +94,78 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
|
93 | 94 |
|
94 | 95 | expect(mock.activeMocks()).toStrictEqual([]);
|
95 | 96 | });
|
| 97 | + |
| 98 | + test("GitHub request headers", async () => { |
| 99 | + const fn = createLambdaFunction(app, { probot }); |
| 100 | + |
| 101 | + const mock = nock("https://api.github.com") |
| 102 | + .post( |
| 103 | + "/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments", |
| 104 | + (requestBody) => { |
| 105 | + expect(requestBody).toStrictEqual({ |
| 106 | + body: `Hello from test${path.sep}fixtures${path.sep}app.js`, |
| 107 | + }); |
| 108 | + |
| 109 | + return true; |
| 110 | + } |
| 111 | + ) |
| 112 | + .reply(201, {}); |
| 113 | + |
| 114 | + const context = {}; |
| 115 | + const payload = JSON.stringify(require("./fixtures/push.json")); |
| 116 | + const signature = probot.webhooks.sign(payload); |
| 117 | + const event = { |
| 118 | + headers: { |
| 119 | + "X-Github-Delivery": "eventid123", |
| 120 | + "X-Github-Event": "push", |
| 121 | + "X-Hub-Signature": signature, |
| 122 | + }, |
| 123 | + body: payload, |
| 124 | + }; |
| 125 | + |
| 126 | + await fn(event, context); |
| 127 | + |
| 128 | + expect(context).toStrictEqual({ |
| 129 | + callbackWaitsForEmptyEventLoop: false, |
| 130 | + }); |
| 131 | + |
| 132 | + expect(mock.activeMocks()).toStrictEqual([]); |
| 133 | + }); |
| 134 | + |
| 135 | + test("camelcase request headers (#62)", async () => { |
| 136 | + const fn = createLambdaFunction(app, { probot }); |
| 137 | + |
| 138 | + const mock = nock("https://api.github.com") |
| 139 | + .post( |
| 140 | + "/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments", |
| 141 | + (requestBody) => { |
| 142 | + expect(requestBody).toStrictEqual({ |
| 143 | + body: `Hello from test${path.sep}fixtures${path.sep}app.js`, |
| 144 | + }); |
| 145 | + |
| 146 | + return true; |
| 147 | + } |
| 148 | + ) |
| 149 | + .reply(201, {}); |
| 150 | + |
| 151 | + const context = {}; |
| 152 | + const payload = JSON.stringify(require("./fixtures/push.json")); |
| 153 | + const signature = probot.webhooks.sign(payload); |
| 154 | + const event = { |
| 155 | + headers: { |
| 156 | + "X-Github-Delivery": "EventId123", |
| 157 | + "X-Github-Event": "push", |
| 158 | + "X-Hub-Signature": signature, |
| 159 | + }, |
| 160 | + body: payload, |
| 161 | + }; |
| 162 | + |
| 163 | + await fn(event, context); |
| 164 | + |
| 165 | + expect(context).toStrictEqual({ |
| 166 | + callbackWaitsForEmptyEventLoop: false, |
| 167 | + }); |
| 168 | + |
| 169 | + expect(mock.activeMocks()).toStrictEqual([]); |
| 170 | + }); |
96 | 171 | });
|
0 commit comments