@@ -11,7 +11,7 @@ import type { Api } from "../src/types.ts";
11
11
12
12
describe ( "REST API endpoint methods" , ( ) => {
13
13
it ( "README example" , async ( ) => {
14
- const mock = fetchMock . sandbox ( ) . post (
14
+ const mock = fetchMock . createInstance ( ) . post (
15
15
"path:/user/repos" ,
16
16
{ id : 1 } ,
17
17
{
@@ -25,7 +25,7 @@ describe("REST API endpoint methods", () => {
25
25
const octokit = new MyOctokit ( {
26
26
auth : "secret123" ,
27
27
request : {
28
- fetch : mock ,
28
+ fetch : mock . fetchHandler ,
29
29
} ,
30
30
} ) ;
31
31
@@ -39,13 +39,13 @@ describe("REST API endpoint methods", () => {
39
39
40
40
it ( "Required preview header" , async ( ) => {
41
41
const mock = fetchMock
42
- . sandbox ( )
42
+ . createInstance ( )
43
43
. getOnce ( "path:/codes_of_conduct" , [ { key : "mit" } ] ) ;
44
44
45
45
const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
46
46
const octokit = new MyOctokit ( {
47
47
request : {
48
- fetch : mock ,
48
+ fetch : mock . fetchHandler ,
49
49
} ,
50
50
} ) ;
51
51
@@ -56,24 +56,26 @@ describe("REST API endpoint methods", () => {
56
56
} ) ;
57
57
58
58
it ( "octokit.rest.markdown.renderRaw()" , async ( ) => {
59
- const mock = fetchMock . sandbox ( ) . postOnce (
60
- "path:/markdown/raw" ,
59
+ const mock = fetchMock . createInstance ( ) . postOnce (
60
+ ( { url, options : { body } } ) => {
61
+ if ( url === "https://api.github.com/markdown/raw" ) {
62
+ expect ( body ) . toEqual ( "# Hello, world!" ) ;
63
+ return true ;
64
+ }
65
+ return false ;
66
+ } ,
61
67
{ ok : true } ,
62
68
{
63
69
headers : {
64
70
"content-type" : "text/plain; charset=utf-8" ,
65
71
} ,
66
- matcher : ( _ , { body } ) => {
67
- expect ( body ) . toEqual ( "# Hello, world!" ) ;
68
- return true ;
69
- } ,
70
72
} ,
71
73
) ;
72
74
73
75
const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
74
76
const octokit = new MyOctokit ( {
75
77
request : {
76
- fetch : mock ,
78
+ fetch : mock . fetchHandler ,
77
79
} ,
78
80
} ) ;
79
81
@@ -89,8 +91,18 @@ describe("REST API endpoint methods", () => {
89
91
} ) ;
90
92
91
93
it ( "octokit.rest.repos.uploadReleaseAsset()" , async ( ) => {
92
- const mock = fetchMock . sandbox ( ) . postOnce (
93
- "https://uploads.github.com/repos/octocat/hello-world/releases/123/assets" ,
94
+ const mock = fetchMock . createInstance ( ) . postOnce (
95
+ ( { url, options : { body } } ) => {
96
+ const path = new URL ( url ) ;
97
+ if (
98
+ `${ path . origin } ${ path . pathname } ` ===
99
+ "https://uploads.github.com/repos/octocat/hello-world/releases/123/assets"
100
+ ) {
101
+ expect ( body ) . toEqual ( "test 1, 2" ) ;
102
+ return true ;
103
+ }
104
+ return false ;
105
+ } ,
94
106
{ ok : true } ,
95
107
{
96
108
headers : {
@@ -100,18 +112,14 @@ describe("REST API endpoint methods", () => {
100
112
name : "test.txt" ,
101
113
label : "test" ,
102
114
} ,
103
- matcher : ( _ , { body } ) => {
104
- expect ( body ) . toEqual ( "test 1, 2" ) ;
105
- return true ;
106
- } ,
107
115
} ,
108
116
) ;
109
117
110
118
const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
111
119
const octokit = new MyOctokit ( {
112
120
auth : "secret123" ,
113
121
request : {
114
- fetch : mock ,
122
+ fetch : mock . fetchHandler ,
115
123
} ,
116
124
} ) ;
117
125
@@ -135,7 +143,7 @@ describe("REST API endpoint methods", () => {
135
143
} ) ;
136
144
137
145
it ( "octokit.rest.repos.addProtectedBranchRequiredStatusChecksContexts(): `contexts` option value is sent as request body without namespace" , async ( ) => {
138
- const mock = fetchMock . sandbox ( ) . postOnce (
146
+ const mock = fetchMock . createInstance ( ) . postOnce (
139
147
"https://api.github.com/repos/octocat/hello-world/branches/latest/protection/required_status_checks/contexts" ,
140
148
{ ok : true } ,
141
149
{
@@ -147,7 +155,7 @@ describe("REST API endpoint methods", () => {
147
155
const octokit = new MyOctokit ( {
148
156
auth : "secret123" ,
149
157
request : {
150
- fetch : mock ,
158
+ fetch : mock . fetchHandler ,
151
159
} ,
152
160
} ) ;
153
161
@@ -167,14 +175,14 @@ describe("REST API endpoint methods", () => {
167
175
168
176
it ( "octokit.rest.apps.listInstallations(): method without options (octokit/rest.js#818)" , async ( ) => {
169
177
const mock = fetchMock
170
- . sandbox ( )
178
+ . createInstance ( )
171
179
. getOnce ( "https://api.github.com/app/installations" , { ok : true } ) ;
172
180
173
181
const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
174
182
const octokit = new MyOctokit ( {
175
183
auth : "secret123" ,
176
184
request : {
177
- fetch : mock ,
185
+ fetch : mock . fetchHandler ,
178
186
} ,
179
187
} ) ;
180
188
@@ -186,7 +194,7 @@ describe("REST API endpoint methods", () => {
186
194
187
195
beforeEach ( ( ) => {
188
196
const networkMock = fetchMock
189
- . sandbox ( )
197
+ . createInstance ( )
190
198
. getOnce (
191
199
"https://api.github.com/repos/octokit/plugin-rest-endpoint-methods/issues/1/labels" ,
192
200
[ { name : "mocked from network" } ] ,
@@ -195,7 +203,7 @@ describe("REST API endpoint methods", () => {
195
203
const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
196
204
octokit = new MyOctokit ( {
197
205
request : {
198
- fetch : networkMock ,
206
+ fetch : networkMock . fetchHandler ,
199
207
} ,
200
208
} ) ;
201
209
} ) ;
@@ -278,7 +286,7 @@ describe("REST API endpoint methods", () => {
278
286
// We will deprecate the `octokit.*` methods in future, but for now we just make sure they are set
279
287
280
288
it ( "legacyRestEndpointMethods" , async ( ) => {
281
- const mock = fetchMock . sandbox ( ) . post (
289
+ const mock = fetchMock . createInstance ( ) . post (
282
290
"path:/user/repos" ,
283
291
{ id : 1 } ,
284
292
{
@@ -292,7 +300,7 @@ describe("REST API endpoint methods", () => {
292
300
const octokit = new MyOctokit ( {
293
301
auth : "secret123" ,
294
302
request : {
295
- fetch : mock ,
303
+ fetch : mock . fetchHandler ,
296
304
} ,
297
305
} ) ;
298
306
0 commit comments