@@ -535,6 +535,100 @@ describe('/api/lists/:id', () => {
535
535
} ) ;
536
536
} ) ;
537
537
538
+ describe ( '/api/legacy-ids' , ( ) => {
539
+ describe ( 'GET' , ( ) => {
540
+ const test = ( ) => ratelimitBypass ( request ( ) . get ( '/api/legacy-ids' ) ) ;
541
+ it ( 'returns an OK status code' , done => {
542
+ test ( ) . end ( ( err , res ) => {
543
+ expect ( res ) . to . have . status ( 200 ) ;
544
+ done ( ) ;
545
+ } ) ;
546
+ } ) ;
547
+ it ( 'has a permissive CORS header' , done => {
548
+ test ( ) . end ( ( err , res ) => {
549
+ expect ( res ) . to . have . header ( 'Access-Control-Allow-Origin' , '*' ) ;
550
+ done ( ) ;
551
+ } ) ;
552
+ } ) ;
553
+ it ( 'returns a valid JSON body' , done => {
554
+ test ( ) . end ( ( err , res ) => {
555
+ expect ( res ) . to . be . json ;
556
+ done ( ) ;
557
+ } ) ;
558
+ } ) ;
559
+ it ( 'contains an object of strings' , done => {
560
+ test ( ) . end ( ( err , res ) => {
561
+ expect ( res . body ) . to . be . a ( 'object' ) ;
562
+ const entries = Object . values ( res . body ) ;
563
+ entries . forEach ( entry => {
564
+ expect ( entry ) . to . be . a ( 'string' ) ;
565
+ } ) ;
566
+ done ( ) ;
567
+ } ) ;
568
+ } ) ;
569
+ } ) ;
570
+
571
+ describe ( 'GET (Ratelimited)' , ( ) => {
572
+ const test = ( ) => request ( ) . get ( '/api/legacy-ids' ) ;
573
+ it ( 'ratelimits spam requests' , done => {
574
+ resetRatelimits ( ) . end ( ( ) => {
575
+ test ( ) . end ( ( ) => {
576
+ } ) ;
577
+ setTimeout ( ( ) => {
578
+ test ( ) . end ( ( err , res ) => {
579
+ expect ( res ) . to . have . status ( 429 ) ;
580
+ expect ( res ) . to . be . json ;
581
+
582
+ expect ( res . body ) . to . have . property ( 'error' , true ) ;
583
+ expect ( res . body ) . to . have . property ( 'status' , 429 ) ;
584
+
585
+ expect ( res . body ) . to . have . property ( 'retry_after' ) ;
586
+ expect ( res . body . retry_after ) . to . be . a ( 'number' ) ;
587
+
588
+ expect ( res . body ) . to . have . property ( 'ratelimit_reset' ) ;
589
+ expect ( res . body . ratelimit_reset ) . to . be . a ( 'number' ) ;
590
+
591
+ expect ( res . body ) . to . have . property ( 'ratelimit_ip' ) ;
592
+ expect ( res . body . ratelimit_ip ) . to . be . a ( 'string' ) ;
593
+
594
+ expect ( res . body ) . to . have . property ( 'ratelimit_route' , '/api/legacy-ids' ) ;
595
+ expect ( res . body ) . to . have . property ( 'ratelimit_bot_id' , '' ) ;
596
+ done ( ) ;
597
+ } ) ;
598
+ } , 200 ) ;
599
+ } ) ;
600
+ } ) ;
601
+ it ( 'does not ratelimit requests spaced correctly' , function ( done ) {
602
+ checks . ratelimit ( this , 1 , test , done ) ;
603
+ } ) ;
604
+ } ) ;
605
+
606
+ describe ( 'POST' , ( ) => {
607
+ const test = ( ) => ratelimitBypass ( request ( ) . post ( '/api/legacy-ids' ) ) ;
608
+ it ( 'returns a Not Found status code' , done => {
609
+ test ( ) . end ( ( err , res ) => {
610
+ expect ( res ) . to . have . status ( 404 ) ;
611
+ done ( ) ;
612
+ } ) ;
613
+ } ) ;
614
+ it ( 'has a permissive CORS header' , done => {
615
+ test ( ) . end ( ( err , res ) => {
616
+ expect ( res ) . to . have . header ( 'Access-Control-Allow-Origin' , '*' ) ;
617
+ done ( ) ;
618
+ } ) ;
619
+ } ) ;
620
+ it ( 'returns an error JSON body' , done => {
621
+ test ( ) . end ( ( err , res ) => {
622
+ expect ( res ) . to . be . json ;
623
+ expect ( res . body ) . to . have . property ( 'error' , true ) ;
624
+ expect ( res . body ) . to . have . property ( 'status' , 404 ) ;
625
+ expect ( res . body ) . to . have . property ( 'message' , 'Endpoint not found' ) ;
626
+ done ( ) ;
627
+ } ) ;
628
+ } ) ;
629
+ } ) ;
630
+ } ) ;
631
+
538
632
describe ( '/api/count' , ( ) => {
539
633
describe ( 'GET' , ( ) => {
540
634
const test = ( ) => ratelimitBypass ( request ( ) . get ( '/api/count' ) ) ;
@@ -1332,97 +1426,3 @@ describe('/api/bots/:id', () => {
1332
1426
} ) ;
1333
1427
} ) ;
1334
1428
} ) ;
1335
-
1336
- describe ( '/api/legacy-ids' , ( ) => {
1337
- describe ( 'GET' , ( ) => {
1338
- const test = ( ) => ratelimitBypass ( request ( ) . get ( '/api/legacy-ids' ) ) ;
1339
- it ( 'returns an OK status code' , done => {
1340
- test ( ) . end ( ( err , res ) => {
1341
- expect ( res ) . to . have . status ( 200 ) ;
1342
- done ( ) ;
1343
- } ) ;
1344
- } ) ;
1345
- it ( 'has a permissive CORS header' , done => {
1346
- test ( ) . end ( ( err , res ) => {
1347
- expect ( res ) . to . have . header ( 'Access-Control-Allow-Origin' , '*' ) ;
1348
- done ( ) ;
1349
- } ) ;
1350
- } ) ;
1351
- it ( 'returns a valid JSON body' , done => {
1352
- test ( ) . end ( ( err , res ) => {
1353
- expect ( res ) . to . be . json ;
1354
- done ( ) ;
1355
- } ) ;
1356
- } ) ;
1357
- it ( 'contains an object of strings' , done => {
1358
- test ( ) . end ( ( err , res ) => {
1359
- expect ( res . body ) . to . be . a ( 'object' ) ;
1360
- const entries = Object . values ( res . body ) ;
1361
- entries . forEach ( entry => {
1362
- expect ( entry ) . to . be . a ( 'string' ) ;
1363
- } ) ;
1364
- done ( ) ;
1365
- } ) ;
1366
- } ) ;
1367
- } ) ;
1368
-
1369
- describe ( 'GET (Ratelimited)' , ( ) => {
1370
- const test = ( ) => request ( ) . get ( '/api/legacy-ids' ) ;
1371
- it ( 'ratelimits spam requests' , done => {
1372
- resetRatelimits ( ) . end ( ( ) => {
1373
- test ( ) . end ( ( ) => {
1374
- } ) ;
1375
- setTimeout ( ( ) => {
1376
- test ( ) . end ( ( err , res ) => {
1377
- expect ( res ) . to . have . status ( 429 ) ;
1378
- expect ( res ) . to . be . json ;
1379
-
1380
- expect ( res . body ) . to . have . property ( 'error' , true ) ;
1381
- expect ( res . body ) . to . have . property ( 'status' , 429 ) ;
1382
-
1383
- expect ( res . body ) . to . have . property ( 'retry_after' ) ;
1384
- expect ( res . body . retry_after ) . to . be . a ( 'number' ) ;
1385
-
1386
- expect ( res . body ) . to . have . property ( 'ratelimit_reset' ) ;
1387
- expect ( res . body . ratelimit_reset ) . to . be . a ( 'number' ) ;
1388
-
1389
- expect ( res . body ) . to . have . property ( 'ratelimit_ip' ) ;
1390
- expect ( res . body . ratelimit_ip ) . to . be . a ( 'string' ) ;
1391
-
1392
- expect ( res . body ) . to . have . property ( 'ratelimit_route' , '/api/legacy-ids' ) ;
1393
- expect ( res . body ) . to . have . property ( 'ratelimit_bot_id' , '' ) ;
1394
- done ( ) ;
1395
- } ) ;
1396
- } , 200 ) ;
1397
- } ) ;
1398
- } ) ;
1399
- it ( 'does not ratelimit requests spaced correctly' , function ( done ) {
1400
- checks . ratelimit ( this , 1 , test , done ) ;
1401
- } ) ;
1402
- } ) ;
1403
-
1404
- describe ( 'POST' , ( ) => {
1405
- const test = ( ) => ratelimitBypass ( request ( ) . post ( '/api/legacy-ids' ) ) ;
1406
- it ( 'returns a Not Found status code' , done => {
1407
- test ( ) . end ( ( err , res ) => {
1408
- expect ( res ) . to . have . status ( 404 ) ;
1409
- done ( ) ;
1410
- } ) ;
1411
- } ) ;
1412
- it ( 'has a permissive CORS header' , done => {
1413
- test ( ) . end ( ( err , res ) => {
1414
- expect ( res ) . to . have . header ( 'Access-Control-Allow-Origin' , '*' ) ;
1415
- done ( ) ;
1416
- } ) ;
1417
- } ) ;
1418
- it ( 'returns an error JSON body' , done => {
1419
- test ( ) . end ( ( err , res ) => {
1420
- expect ( res ) . to . be . json ;
1421
- expect ( res . body ) . to . have . property ( 'error' , true ) ;
1422
- expect ( res . body ) . to . have . property ( 'status' , 404 ) ;
1423
- expect ( res . body ) . to . have . property ( 'message' , 'Endpoint not found' ) ;
1424
- done ( ) ;
1425
- } ) ;
1426
- } ) ;
1427
- } ) ;
1428
- } ) ;
0 commit comments