@@ -354,3 +354,151 @@ describe("GET /repos/:owner/:repo/git/refs/:ref (#21)", () => {
354354 }
355355 } ) ;
356356} ) ;
357+
358+ describe ( "GET /orgs/:org/teams/:team_slug*" , ( ) => {
359+ it ( "Throws no error for github.com users" , async ( ) => {
360+ const mock = fetchMock
361+ . sandbox ( )
362+ . getOnce ( "https://api.github.com/orgs/my-org/teams/my-team" , {
363+ status : 200 ,
364+ body : { id : 123 } ,
365+ } ) ;
366+
367+ const octokitPatched = new OctokitWithPlugin ( {
368+ request : {
369+ fetch : mock ,
370+ } ,
371+ } ) ;
372+
373+ const { data } = await octokitPatched . request (
374+ "GET /orgs/:org/teams/:team_slug" ,
375+ {
376+ org : "my-org" ,
377+ team_slug : "my-team" ,
378+ }
379+ ) ;
380+
381+ expect ( data ) . toStrictEqual ( { id : 123 } ) ;
382+ } ) ;
383+
384+ it ( "Throws no error for github.com users" , async ( ) => {
385+ const mock = fetchMock
386+ . sandbox ( )
387+ . getOnce ( "https://api.github.com/orgs/my-org/teams/my-team" , {
388+ status : 404 ,
389+ body : { error : "not found" } ,
390+ } ) ;
391+
392+ const octokitPatched = new OctokitWithPlugin ( {
393+ request : {
394+ fetch : mock ,
395+ } ,
396+ } ) ;
397+
398+ try {
399+ await octokitPatched . request ( "GET /orgs/:org/teams/:team_slug" , {
400+ org : "my-org" ,
401+ team_slug : "my-team" ,
402+ } ) ;
403+ throw new Error ( "should not resolve" ) ;
404+ } catch ( error ) {
405+ expect ( error . status ) . toEqual ( 404 ) ;
406+ }
407+ } ) ;
408+
409+ it ( "'GET /orgs/:org/teams/:team_slug': Throws a helpful error for GitHub Enterprise Server 2.20 users" , async ( ) => {
410+ const mock = fetchMock
411+ . sandbox ( )
412+ . getOnce ( "https://ghes.acme-inc.test/api/v3/orgs/my-org/teams/my-team" , {
413+ status : 404 ,
414+ body : { error : "Not found" } ,
415+ headers : {
416+ "X-GitHub-Enterprise-Version" : "2.20.0" ,
417+ } ,
418+ } ) ;
419+
420+ const octokitPatched = new OctokitWithPlugin ( {
421+ baseUrl : "https://ghes.acme-inc.test/api/v3" ,
422+ request : {
423+ fetch : mock ,
424+ } ,
425+ } ) ;
426+
427+ try {
428+ await octokitPatched . request ( "GET /orgs/:org/teams/:team_slug" , {
429+ org : "my-org" ,
430+ team_slug : "my-team" ,
431+ } ) ;
432+ throw new Error ( "Should not resolve" ) ;
433+ } catch ( error ) {
434+ expect ( error . status ) . toEqual ( 404 ) ;
435+ expect ( error . message ) . toEqual (
436+ `"GET /orgs/:org/teams/:team_slug" is not supported in your GitHub Enterprise Server version. Please replace with octokit.request("GET /teams/:team_id", { team_id })`
437+ ) ;
438+ }
439+ } ) ;
440+
441+ it ( "'GET /orgs/:org/teams/:team_slug': 500 error" , async ( ) => {
442+ const mock = fetchMock
443+ . sandbox ( )
444+ . getOnce ( "https://ghes.acme-inc.test/api/v3/orgs/my-org/teams/my-team" , {
445+ status : 500 ,
446+ } ) ;
447+
448+ const octokitPatched = new OctokitWithPlugin ( {
449+ baseUrl : "https://ghes.acme-inc.test/api/v3" ,
450+ request : {
451+ fetch : mock ,
452+ } ,
453+ } ) ;
454+
455+ try {
456+ await octokitPatched . request ( "GET /orgs/:org/teams/:team_slug" , {
457+ org : "my-org" ,
458+ team_slug : "my-team" ,
459+ } ) ;
460+ throw new Error ( "Should not resolve" ) ;
461+ } catch ( error ) {
462+ expect ( error . status ) . toEqual ( 500 ) ;
463+ }
464+ } ) ;
465+
466+ it ( "'GET /orgs/:org/teams/:team_slug/discussions/:discussion_number/comments': Throws a helpful error for GitHub Enterprise Server 2.20 users" , async ( ) => {
467+ const mock = fetchMock
468+ . sandbox ( )
469+ . getOnce (
470+ "https://ghes.acme-inc.test/api/v3/orgs/my-org/teams/my-team/discussions/123/comments" ,
471+ {
472+ status : 404 ,
473+ body : { error : "Not found" } ,
474+ headers : {
475+ "X-GitHub-Enterprise-Version" : "2.20.0" ,
476+ } ,
477+ }
478+ ) ;
479+
480+ const octokitPatched = new OctokitWithPlugin ( {
481+ baseUrl : "https://ghes.acme-inc.test/api/v3" ,
482+ request : {
483+ fetch : mock ,
484+ } ,
485+ } ) ;
486+
487+ try {
488+ await octokitPatched . request (
489+ "GET /orgs/:org/teams/:team_slug/discussions/:discussion_number/comments" ,
490+ {
491+ org : "my-org" ,
492+ team_slug : "my-team" ,
493+ discussion_number : 123 ,
494+ }
495+ ) ;
496+ throw new Error ( "Should not resolve" ) ;
497+ } catch ( error ) {
498+ expect ( error . status ) . toEqual ( 404 ) ;
499+ expect ( error . message ) . toEqual (
500+ `"GET /orgs/:org/teams/:team_slug/discussions/:discussion_number/comments" is not supported in your GitHub Enterprise Server version. Please replace with octokit.request("GET /teams/:team_id/discussions/:discussion_number/comments", { team_id })`
501+ ) ;
502+ }
503+ } ) ;
504+ } ) ;
0 commit comments