@@ -492,6 +492,75 @@ describe('.createApiServer', () => {
492492 } ) ;
493493 } ) ;
494494 } ) ;
495+
496+ describe ( 'requesting room' , ( ) => {
497+ let db ;
498+ beforeEach ( ( ) => {
499+ delete process . env . API_SECRET ;
500+ db = {
501+ get : async ( ) => {
502+ return {
503+ players : {
504+ '0' : {
505+ id : 0 ,
506+ credentials : 'SECRET1' ,
507+ } ,
508+ '1' : {
509+ id : 1 ,
510+ credentials : 'SECRET2' ,
511+ } ,
512+ } ,
513+ } ;
514+ } ,
515+ set : async ( ) => { } ,
516+ list : async ( ) => {
517+ return [
518+ 'bar:bar-0' ,
519+ 'bar:bar-0:metadata' ,
520+ 'foo:foo-0' ,
521+ 'foo:foo-0:metadata' ,
522+ 'bar:bar-1' ,
523+ 'bar:bar-1:metadata' ,
524+ ] ;
525+ } ,
526+ } ;
527+ } ) ;
528+
529+ describe ( 'when given room ID' , async ( ) => {
530+ let response ;
531+ let room ;
532+ beforeEach ( async ( ) => {
533+ let games = [ Game ( { name : 'foo' } ) , Game ( { name : 'bar' } ) ] ;
534+ let app = createApiServer ( { db, games } ) ;
535+ response = await request ( app . callback ( ) ) . get ( '/games/bar/bar-0' ) ;
536+ room = JSON . parse ( response . text ) ;
537+ } ) ;
538+
539+ test ( 'returns game ids' , async ( ) => {
540+ expect ( room . roomID ) . toEqual ( 'bar-0' ) ;
541+ } ) ;
542+
543+ test ( 'returns player names' , async ( ) => {
544+ expect ( room . players ) . toEqual ( [ { id : 0 } , { id : 1 } ] ) ;
545+ } ) ;
546+ } ) ;
547+
548+ describe ( 'when given a non-existent room ID' , async ( ) => {
549+ let response ;
550+ beforeEach ( async ( ) => {
551+ db . get = async ( ) => {
552+ return null ;
553+ } ;
554+ let games = [ Game ( { name : 'foo' } ) ] ;
555+ let app = createApiServer ( { db, games } ) ;
556+ response = await request ( app . callback ( ) ) . get ( '/games/bar/doesnotexist' ) ;
557+ } ) ;
558+
559+ test ( 'throws error 404' , async ( ) => {
560+ expect ( response . status ) . toEqual ( 404 ) ;
561+ } ) ;
562+ } ) ;
563+ } ) ;
495564} ) ;
496565
497566describe ( '.addApiToServer' , ( ) => {
0 commit comments