1
- const nock = require ( "nock" ) ;
2
1
const path = require ( "path" ) ;
2
+ const fetchMock = require ( "fetch-mock" ) ;
3
3
4
4
const { createLambdaFunction, Probot, ProbotOctokit } = require ( "../index" ) ;
5
5
const app = require ( "./fixtures/app" ) ;
6
6
7
- nock . disableNetConnect ( ) ;
8
-
9
7
describe ( "@probot/adapter-aws-lambda-serverless" , ( ) => {
10
8
let probot ;
11
9
@@ -21,21 +19,22 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
21
19
} ) ;
22
20
} ) ;
23
21
22
+ afterEach ( ( ) => {
23
+ fetchMock . restore ( ) ;
24
+ } ) ;
25
+
24
26
test ( "happy path" , async ( ) => {
25
27
const fn = createLambdaFunction ( app , { probot } ) ;
26
28
27
- const mock = nock ( "https://api.github.com" )
28
- . post (
29
- "/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments" ,
30
- ( requestBody ) => {
31
- expect ( requestBody ) . toStrictEqual ( {
32
- body : `Hello from test${ path . sep } fixtures${ path . sep } app.js` ,
33
- } ) ;
34
-
35
- return true ;
36
- }
37
- )
38
- . reply ( 201 , { } ) ;
29
+ const mock = fetchMock . postOnce (
30
+ {
31
+ url : "https://api.github.com/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments" ,
32
+ } ,
33
+ {
34
+ body : { } ,
35
+ status : 201 ,
36
+ }
37
+ ) ;
39
38
40
39
const context = { } ;
41
40
const payload = JSON . stringify ( require ( "./fixtures/push.json" ) ) ;
@@ -51,24 +50,28 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
51
50
52
51
await fn ( event , context ) ;
53
52
54
- expect ( mock . activeMocks ( ) ) . toStrictEqual ( [ ] ) ;
53
+ expect (
54
+ mock . called ( ( _url , options ) => {
55
+ return (
56
+ JSON . parse ( options . body ) . body ===
57
+ `Hello from test${ path . sep } fixtures${ path . sep } app.js`
58
+ ) ;
59
+ } )
60
+ ) . toBe ( true ) ;
55
61
} ) ;
56
62
57
63
test ( "lowercase request headers" , async ( ) => {
58
64
const fn = createLambdaFunction ( app , { probot } ) ;
59
65
60
- const mock = nock ( "https://api.github.com" )
61
- . post (
62
- "/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments" ,
63
- ( requestBody ) => {
64
- expect ( requestBody ) . toStrictEqual ( {
65
- body : `Hello from test${ path . sep } fixtures${ path . sep } app.js` ,
66
- } ) ;
67
-
68
- return true ;
69
- }
70
- )
71
- . reply ( 201 , { } ) ;
66
+ const mock = fetchMock . postOnce (
67
+ {
68
+ url : "https://api.github.com/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments" ,
69
+ } ,
70
+ {
71
+ body : { } ,
72
+ status : 201 ,
73
+ }
74
+ ) ;
72
75
73
76
const context = { } ;
74
77
const payload = JSON . stringify ( require ( "./fixtures/push.json" ) ) ;
@@ -84,24 +87,28 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
84
87
85
88
await fn ( event , context ) ;
86
89
87
- expect ( mock . activeMocks ( ) ) . toStrictEqual ( [ ] ) ;
90
+ expect (
91
+ mock . called ( ( _url , options ) => {
92
+ return (
93
+ JSON . parse ( options . body ) . body ===
94
+ `Hello from test${ path . sep } fixtures${ path . sep } app.js`
95
+ ) ;
96
+ } )
97
+ ) . toBe ( true ) ;
88
98
} ) ;
89
99
90
100
test ( "GitHub request headers" , async ( ) => {
91
101
const fn = createLambdaFunction ( app , { probot } ) ;
92
102
93
- const mock = nock ( "https://api.github.com" )
94
- . post (
95
- "/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments" ,
96
- ( requestBody ) => {
97
- expect ( requestBody ) . toStrictEqual ( {
98
- body : `Hello from test${ path . sep } fixtures${ path . sep } app.js` ,
99
- } ) ;
100
-
101
- return true ;
102
- }
103
- )
104
- . reply ( 201 , { } ) ;
103
+ const mock = fetchMock . postOnce (
104
+ {
105
+ url : "https://api.github.com/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments" ,
106
+ } ,
107
+ {
108
+ body : { } ,
109
+ status : 201 ,
110
+ }
111
+ ) ;
105
112
106
113
const context = { } ;
107
114
const payload = JSON . stringify ( require ( "./fixtures/push.json" ) ) ;
@@ -117,24 +124,28 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
117
124
118
125
await fn ( event , context ) ;
119
126
120
- expect ( mock . activeMocks ( ) ) . toStrictEqual ( [ ] ) ;
127
+ expect (
128
+ mock . called ( ( _url , options ) => {
129
+ return (
130
+ JSON . parse ( options . body ) . body ===
131
+ `Hello from test${ path . sep } fixtures${ path . sep } app.js`
132
+ ) ;
133
+ } )
134
+ ) . toBe ( true ) ;
121
135
} ) ;
122
136
123
137
test ( "camelcase request headers (#62)" , async ( ) => {
124
138
const fn = createLambdaFunction ( app , { probot } ) ;
125
139
126
- const mock = nock ( "https://api.github.com" )
127
- . post (
128
- "/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments" ,
129
- ( requestBody ) => {
130
- expect ( requestBody ) . toStrictEqual ( {
131
- body : `Hello from test${ path . sep } fixtures${ path . sep } app.js` ,
132
- } ) ;
133
-
134
- return true ;
135
- }
136
- )
137
- . reply ( 201 , { } ) ;
140
+ const mock = fetchMock . postOnce (
141
+ {
142
+ url : "https://api.github.com/repos/probot/adapter-adapter-aws-lambda-serverless/commits/headcommitsha123/comments" ,
143
+ } ,
144
+ {
145
+ body : { } ,
146
+ status : 201 ,
147
+ }
148
+ ) ;
138
149
139
150
const context = { } ;
140
151
const payload = JSON . stringify ( require ( "./fixtures/push.json" ) ) ;
@@ -150,6 +161,13 @@ describe("@probot/adapter-aws-lambda-serverless", () => {
150
161
151
162
await fn ( event , context ) ;
152
163
153
- expect ( mock . activeMocks ( ) ) . toStrictEqual ( [ ] ) ;
164
+ expect (
165
+ mock . called ( ( _url , options ) => {
166
+ return (
167
+ JSON . parse ( options . body ) . body ===
168
+ `Hello from test${ path . sep } fixtures${ path . sep } app.js`
169
+ ) ;
170
+ } )
171
+ ) . toBe ( true ) ;
154
172
} ) ;
155
173
} ) ;
0 commit comments