@@ -4,24 +4,25 @@ const fetchMock = require('fetch-mock/es5/server')
44const sinonChai = require ( 'sinon-chai' )
55
66const octokitRequest = require ( '..' )
7+ const mockable = require ( '../lib/fetch' )
78
89chai . use ( sinonChai )
910const expect = chai . expect
10- const originalFetch = octokitRequest . fetch
11+ const originalFetch = mockable . fetch
1112
1213const pkg = require ( '../package.json' )
1314const userAgent = `octokit-request.js/${ pkg . version } ${ getUserAgent ( ) } `
1415
1516describe ( 'octokitRequest()' , ( ) => {
1617 afterEach ( ( ) => {
17- octokitRequest . fetch = originalFetch
18+ mockable . fetch = originalFetch
1819 } )
1920 it ( 'is a function' , ( ) => {
2021 expect ( octokitRequest ) . to . be . a ( 'function' )
2122 } )
2223
2324 it ( 'README example' , ( ) => {
24- octokitRequest . fetch = fetchMock . sandbox ( )
25+ mockable . fetch = fetchMock . sandbox ( )
2526 . mock ( 'https://api.github.com/orgs/octokit/repos?type=private' , [ ] , {
2627 headers : {
2728 accept : 'application/vnd.github.v3+json' ,
@@ -44,7 +45,7 @@ describe('octokitRequest()', () => {
4445 } )
4546
4647 it ( 'README example alternative' , ( ) => {
47- octokitRequest . fetch = fetchMock . sandbox ( )
48+ mockable . fetch = fetchMock . sandbox ( )
4849 . mock ( 'https://api.github.com/orgs/octokit/repos?type=private' , [ ] , {
4950 headers : {
5051 accept : 'application/vnd.github.v3+json' ,
@@ -53,7 +54,7 @@ describe('octokitRequest()', () => {
5354 }
5455 } )
5556
56- octokitRequest . fetch = fetchMock . sandbox ( )
57+ mockable . fetch = fetchMock . sandbox ( )
5758 . mock ( 'https://api.github.com/orgs/octokit/repos?type=private' , [ ] )
5859
5960 return octokitRequest ( {
@@ -72,7 +73,7 @@ describe('octokitRequest()', () => {
7273 } )
7374
7475 it ( 'Request with body' , ( ) => {
75- octokitRequest . fetch = fetchMock . sandbox ( )
76+ mockable . fetch = fetchMock . sandbox ( )
7677 . mock ( 'https://api.github.com/repos/octocat/hello-world/issues' , 201 , {
7778 headers : {
7879 'content-type' : 'application/json; charset=utf-8'
@@ -102,7 +103,7 @@ describe('octokitRequest()', () => {
102103 } )
103104
104105 it ( 'Put without request body' , ( ) => {
105- octokitRequest . fetch = fetchMock . sandbox ( )
106+ mockable . fetch = fetchMock . sandbox ( )
106107 . mock ( 'https://api.github.com/user/starred/octocat/hello-world' , 204 , {
107108 headers : {
108109 'content-length' : 0
@@ -123,7 +124,7 @@ describe('octokitRequest()', () => {
123124 } )
124125
125126 it ( 'HEAD requests (octokit/rest.js#841)' , ( ) => {
126- octokitRequest . fetch = fetchMock . sandbox ( )
127+ mockable . fetch = fetchMock . sandbox ( )
127128 . head ( 'https://api.github.com/repos/whatwg/html/pulls/1' , {
128129 status : 200 ,
129130 headers : {
@@ -163,7 +164,7 @@ describe('octokitRequest()', () => {
163164 } )
164165
165166 it . skip ( 'Binary response with redirect (🤔 unclear how to mock fetch redirect properly)' , ( ) => {
166- octokitRequest . fetch = fetchMock . sandbox ( )
167+ mockable . fetch = fetchMock . sandbox ( )
167168 . get ( 'https://codeload.github.com/octokit-fixture-org/get-archive/legacy.tar.gz/master' , {
168169 status : 200 ,
169170 body : Buffer . from ( '1f8b0800000000000003cb4f2ec9cfce2cd14dcbac28292d4ad5cd2f4ad74d4f2dd14d2c4acec82c4bd53580007d060a0050bfb9b9a90203c428741ac2313436343307222320dbc010a8dc5c81c194124b8905a5c525894540a714e5e797e05347481edd734304e41319ff41ae8e2ebeae7ab92964d801d46f66668227fe0d4d51e3dfc8d0c8d808284f75df6201233cfe951590627ba01d330a46c1281805a3806e000024cb59d6000a0000' , 'hex' ) ,
@@ -188,7 +189,7 @@ describe('octokitRequest()', () => {
188189 // TODO: fails with "response.buffer is not a function" in browser
189190 if ( ! process . browser ) {
190191 it ( 'Binary response' , ( ) => {
191- octokitRequest . fetch = fetchMock . sandbox ( )
192+ mockable . fetch = fetchMock . sandbox ( )
192193 . get ( 'https://codeload.github.com/octokit-fixture-org/get-archive/legacy.tar.gz/master' , {
193194 status : 200 ,
194195
@@ -206,7 +207,7 @@ describe('octokitRequest()', () => {
206207 }
207208
208209 it ( '304 etag' , ( ) => {
209- octokitRequest . fetch = fetchMock . sandbox ( )
210+ mockable . fetch = fetchMock . sandbox ( )
210211 . get ( ( url , { headers } ) => {
211212 return url === 'https://api.github.com/orgs/myorg' &&
212213 headers [ 'if-none-match' ] === 'etag'
@@ -227,7 +228,7 @@ describe('octokitRequest()', () => {
227228 } )
228229
229230 it ( 'Not found' , ( ) => {
230- octokitRequest . fetch = fetchMock . sandbox ( )
231+ mockable . fetch = fetchMock . sandbox ( )
231232 . get ( 'path:/orgs/nope' , 404 )
232233
233234 return octokitRequest ( 'GET /orgs/:org' , {
@@ -244,7 +245,7 @@ describe('octokitRequest()', () => {
244245 } )
245246
246247 it ( 'non-JSON response' , ( ) => {
247- octokitRequest . fetch = fetchMock . sandbox ( )
248+ mockable . fetch = fetchMock . sandbox ( )
248249 . get ( 'path:/repos/octokit-fixture-org/hello-world/contents/README.md' , {
249250 status : 200 ,
250251 body : '# hello-world' ,
@@ -284,7 +285,7 @@ describe('octokitRequest()', () => {
284285 }
285286
286287 it ( 'custom user-agent' , ( ) => {
287- octokitRequest . fetch = fetchMock . sandbox ( )
288+ mockable . fetch = fetchMock . sandbox ( )
288289 . get ( ( url , { headers } ) => headers [ 'user-agent' ] === 'funky boom boom pow' , 200 )
289290
290291 return octokitRequest ( 'GET /' , {
@@ -295,7 +296,7 @@ describe('octokitRequest()', () => {
295296 } )
296297
297298 it ( 'passes node-fetch options to fetch only' , ( ) => {
298- octokitRequest . fetch = ( url , options ) => {
299+ mockable . fetch = ( url , options ) => {
299300 expect ( url ) . to . equal ( 'https://api.github.com/' )
300301 expect ( options . timeout ) . to . equal ( 100 )
301302 return Promise . reject ( new Error ( 'ok' ) )
0 commit comments