@@ -2,7 +2,39 @@ const Bottleneck = require('bottleneck')
22const expect = require ( 'chai' ) . expect
33const Octokit = require ( './octokit' )
44
5- describe ( 'Github API best practices' , function ( ) {
5+ describe ( 'General' , function ( ) {
6+ it ( 'Should be possible to disable the plugin' , async function ( ) {
7+ const octokit = new Octokit ( { throttle : { enabled : false } } )
8+
9+ const req1 = octokit . request ( 'GET /route1' , {
10+ request : {
11+ responses : [ { status : 201 , headers : { } , data : { } } ]
12+ }
13+ } )
14+
15+ const req2 = octokit . request ( 'GET /route2' , {
16+ request : {
17+ responses : [ { status : 202 , headers : { } , data : { } } ]
18+ }
19+ } )
20+
21+ const req3 = octokit . request ( 'GET /route3' , {
22+ request : {
23+ responses : [ { status : 203 , headers : { } , data : { } } ]
24+ }
25+ } )
26+
27+ await Promise . all ( [ req1 , req2 , req3 ] )
28+ expect ( octokit . __requestLog ) . to . deep . equal ( [
29+ 'START GET /route1' ,
30+ 'START GET /route2' ,
31+ 'START GET /route3' ,
32+ 'END GET /route1' ,
33+ 'END GET /route2' ,
34+ 'END GET /route3'
35+ ] )
36+ } )
37+
638 it ( 'Should require the user to pass both limit handlers' , function ( ) {
739 const message = 'You must pass the onAbuseLimit and onRateLimit error handlers'
840
@@ -14,7 +46,9 @@ describe('Github API best practices', function () {
1446 expect ( ( ) => new Octokit ( { throttle : { onRateLimit : ( ) => 1 } } ) ) . to . throw ( message )
1547 expect ( ( ) => new Octokit ( { throttle : { onAbuseLimit : ( ) => 1 , onRateLimit : ( ) => 1 } } ) ) . to . not . throw ( )
1648 } )
49+ } )
1750
51+ describe ( 'Github API best practices' , function ( ) {
1852 it ( 'Should not allow more than 1 request concurrently' , async function ( ) {
1953 const octokit = new Octokit ( { throttle : { onAbuseLimit : ( ) => 1 , onRateLimit : ( ) => 1 } } )
2054 const req1 = octokit . request ( 'GET /route1' , {
0 commit comments