@@ -356,60 +356,53 @@ test('Send - bad urls', t => {
356356//////////////////////////////
357357// Routes - Applications landing
358358//////////////////////////////
359- test . cb ( 'All applications route' , t => {
359+ test ( 'All applications route' , t => {
360360 const request = httpMocks . createRequest ( reqObj ) ;
361361
362362 const response = httpMocks . createResponse ( { eventEmitter : EventEmitter } ) ;
363363 applications . routes . all ( request , response ) ;
364364 response . render ( ) ;
365+ const data = response . _getRenderData ( ) ;
366+ const app = data . applications . find ( ( ap ) => {
367+ return ap . name === 'Foo First Application' ;
368+ } ) ;
365369
366- response . on ( 'end' , ( ) => {
367- const data = response . _getRenderData ( ) ;
368- const app = data . applications . find ( ( ap ) => {
369- return ap . name === 'Foo First Application' ;
370- } ) ;
371-
372- t . is ( response . statusCode , 200 , 'Should be a 200 response' ) ;
373- t . is ( app . name , 'Foo First Application' , 'includes form with inputs' ) ;
374-
375- t . is ( _ . get ( app , 'responses.live[0].response' , null ) , 200 , 'includes live response' ) ;
376- t . true ( _ . isDate ( new Date ( _ . get ( app , 'responses.live[0].timestamp' , null ) ) ) , 'includes live timestamp which is a date' ) ;
377- t . is ( _ . get ( app , 'responses.updated[0].response' , null ) , 200 , 'includes updated response' ) ;
378- t . true ( _ . isDate ( new Date ( _ . get ( app , 'responses.updated[0].timestamp' , null ) ) ) , 'includes updated timestamp which is a date' ) ;
379- t . is ( _ . get ( app , 'responses.sunset[0].response' , null ) , 200 , 'includes sunset response' ) ;
380- t . true ( _ . isDate ( new Date ( _ . get ( app , 'responses.sunset[0].timestamp' , null ) ) ) , 'includes sunset timestamp which is a date' ) ;
370+ t . is ( response . statusCode , 200 , 'Should be a 200 response' ) ;
371+ t . is ( app . name , 'Foo First Application' , 'includes form with inputs' ) ;
381372
382- t . end ( ) ;
383- } ) ;
384- response . end ( ) ;
373+ t . is ( _ . get ( app , 'responses.live[0].response' , null ) , 200 , 'includes live response' ) ;
374+ t . true ( _ . isDate ( new Date ( _ . get ( app , 'responses.live[0].timestamp' , null ) ) ) , 'includes live timestamp which is a date' ) ;
375+ t . is ( _ . get ( app , 'responses.updated[0].response' , null ) , 200 , 'includes updated response' ) ;
376+ t . true ( _ . isDate ( new Date ( _ . get ( app , 'responses.updated[0].timestamp' , null ) ) ) , 'includes updated timestamp which is a date' ) ;
377+ t . is ( _ . get ( app , 'responses.sunset[0].response' , null ) , 200 , 'includes sunset response' ) ;
378+ t . true ( _ . isDate ( new Date ( _ . get ( app , 'responses.sunset[0].timestamp' , null ) ) ) , 'includes sunset timestamp which is a date' ) ;
385379} ) ;
386380
387381//////////////////////////////
388382// Routes - New Application
389383//////////////////////////////
390- test . cb ( 'New application route' , t => {
384+ test ( 'New application route' , t => {
391385 const req = _ . cloneDeep ( reqObj ) ;
392386 req . url = '/applications/add' ;
393387
394388 const request = httpMocks . createRequest ( req ) ;
395389
396390 const response = httpMocks . createResponse ( { eventEmitter : EventEmitter } ) ;
397- applications . routes . add ( request , response ) ;
391+ const resp = applications . routes . add ( request , response ) ;
398392 response . render ( ) ;
399393
400- response . on ( 'end' , ( ) => {
394+ return resp . then ( ( ) => {
401395 const data = response . _getRenderData ( ) ;
402396
403397 t . is ( response . statusCode , 200 , 'Should be a 200 response' ) ;
404398 t . true ( _ . includes ( data . form . html , 'name="sunset-endpoint--url"' ) , 'includes form with inputs' ) ;
405- t . end ( ) ;
406399 } ) ;
407400} ) ;
408401
409402//////////////////////////////
410403// Routes - Single application
411404//////////////////////////////
412- test . cb ( 'Single application route' , t => {
405+ test ( 'Single application route' , t => {
413406 const req = _ . cloneDeep ( reqObj ) ;
414407 req . url = '/applications/1' ;
415408 req . params . id = 1 ;
@@ -420,7 +413,7 @@ test.cb('Single application route', t => {
420413 const resp = applications . routes . one ( request , response ) ;
421414 response . render ( ) ;
422415
423- response . on ( 'end' , ( ) => {
416+ return resp . then ( ( ) => {
424417 const data = response . _getRenderData ( ) ;
425418
426419 t . is ( response . statusCode , 200 , 'Should be a 200 response' ) ;
@@ -435,11 +428,6 @@ test.cb('Single application route', t => {
435428 t . is ( data . config . toString ( ) , config . applications . toString ( ) , 'includes config for applications' ) ;
436429 t . is ( data . app . name , 'Foo First Application' , 'includes data from database' ) ;
437430 t . is ( data . button , 'update' , 'includes `update` as text for button' ) ;
438-
439- return resp . then ( res => {
440- t . is ( res , true , 'should return true' ) ;
441- t . end ( ) ;
442- } ) ;
443431 } ) ;
444432} ) ;
445433
@@ -464,7 +452,7 @@ test.cb('Single application route - bad id', t => {
464452 response . render ( ) ;
465453} ) ;
466454
467- test . cb ( 'Single application route - error on save' , t => {
455+ test ( 'Single application route - error on save' , t => {
468456 const req = _ . cloneDeep ( reqObj ) ;
469457 req . url = '/applications/3' ;
470458 req . params . id = 3 ;
@@ -482,25 +470,23 @@ test.cb('Single application route - error on save', t => {
482470 const request = httpMocks . createRequest ( req ) ;
483471
484472 const response = httpMocks . createResponse ( { eventEmitter : EventEmitter } ) ;
485- applications . routes . one ( request , response ) ;
473+ const resp = applications . routes . one ( request , response ) ;
486474 response . render ( ) ;
487475
488- response . on ( 'end' , ( ) => {
476+ return resp . then ( ( ) => {
489477 const data = response . _getRenderData ( ) ;
490478
491479 t . is ( response . statusCode , 200 , 'Should be a 200 response' ) ;
492480
493481 // form shows error
494482 t . regex ( data . form . html , / < p c l a s s = " f o r m - - a l e r t " r o l e = " a l e r t " f o r = " ( [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 1 - 5 ] [ 0 - 9 a - f ] { 3 } - [ 8 9 a b ] [ 0 - 9 a - f ] { 3 } - [ 0 - 9 a - f ] { 12 } ) " > F i e l d i s r e q u i r e d t o b e s a v e d ! < \/ p > / g, 'includes form alert' ) ;
495-
496- t . end ( ) ;
497483 } ) ;
498484} ) ;
499485
500486//////////////////////////////
501487// Routes - Secret
502488//////////////////////////////
503- test . cb ( 'Create new secret' , t => {
489+ test ( 'Create new secret' , t => {
504490 const req = _ . cloneDeep ( reqObj ) ;
505491 req . method = 'POST' ;
506492 req . headers . referrer = '/applications/1' ;
@@ -512,18 +498,12 @@ test.cb('Create new secret', t => {
512498 const resp = applications . routes . secret ( request , response , next ) ;
513499 response . render ( ) ;
514500
515- return response . on ( 'end' , ( ) => {
516- t . is ( response . statusCode , 302 , 'Should be a 302 response' ) ;
517- t . is ( response . _getRedirectUrl ( ) , '/applications/1' , 'should redirect to edit url' ) ;
518-
519- return resp . then ( res => {
520- t . not ( res , dbmocks . rows [ 0 ] [ 'client-secret' ] , 'should be a new client secret' ) ;
521- t . end ( ) ;
522- } ) ;
501+ return resp . then ( res => {
502+ t . not ( res , dbmocks . rows [ 0 ] [ 'client-secret' ] , 'should be a new client secret' ) ;
523503 } ) ;
524504} ) ;
525505
526- test . cb ( 'Create new secret - bad id kills db' , t => {
506+ test ( 'Create new secret - bad id kills db' , t => {
527507 const req = _ . cloneDeep ( reqObj ) ;
528508 req . method = 'POST' ;
529509 req . headers . referrer = '/applications/break' ;
@@ -534,9 +514,8 @@ test.cb('Create new secret - bad id kills db', t => {
534514 const response = httpMocks . createResponse ( { eventEmitter : EventEmitter } ) ;
535515 const resp = applications . routes . secret ( request , response , next ) ;
536516
537- resp . then ( res => {
517+ return resp . then ( res => {
538518 t . true ( _ . includes ( res . message , 'update "applications" set "client-secret"' ) , 'postgres error' ) ;
539- t . end ( ) ;
540519 } ) ;
541520} ) ;
542521
@@ -565,7 +544,7 @@ test.cb('Create new secret - bad referrer', t => {
565544//////////////////////////////
566545// Routes - Save application
567546//////////////////////////////
568- test . cb ( 'Save new app: name required' , t => {
547+ test ( 'Save new app: name required' , t => {
569548 const req = _ . cloneDeep ( reqObj ) ;
570549 req . method = 'POST' ;
571550 req . session . referrer = '/applications/add' ;
@@ -577,16 +556,13 @@ test.cb('Save new app: name required', t => {
577556
578557 const response = httpMocks . createResponse ( { eventEmitter : EventEmitter } ) ;
579558 applications . routes . save ( request , response ) ;
580-
581- response . on ( 'end' , ( ) => {
582- t . is ( response . statusCode , 302 , 'Should be a 302 response' ) ;
583- t . is ( response . _getRedirectUrl ( ) , '/applications/add' ) ;
584- t . end ( ) ;
585- } ) ;
586559 response . render ( ) ;
560+
561+ t . is ( response . statusCode , 302 , 'Should be a 302 response' ) ;
562+ t . is ( response . _getRedirectUrl ( ) , '/applications/add' ) ;
587563} ) ;
588564
589- test . cb ( 'Save existing app: name required' , t => {
565+ test ( 'Save existing app: name required' , t => {
590566 const req = _ . cloneDeep ( reqObj ) ;
591567 req . method = 'POST' ;
592568 req . session . referrer = '/applications/123' ;
@@ -599,12 +575,8 @@ test.cb('Save existing app: name required', t => {
599575 const response = httpMocks . createResponse ( { eventEmitter : EventEmitter } ) ;
600576 applications . routes . save ( request , response ) ;
601577
602- response . on ( 'end' , ( ) => {
603- t . is ( response . statusCode , 302 , 'Should be a 302 response' ) ;
604- t . is ( response . _getRedirectUrl ( ) , '/applications/123' ) ;
605- t . end ( ) ;
606- } ) ;
607- response . render ( ) ;
578+ t . is ( response . statusCode , 302 , 'Should be a 302 response' ) ;
579+ t . is ( response . _getRedirectUrl ( ) , '/applications/123' ) ;
608580} ) ;
609581
610582test . cb ( 'Delete existing application' , t => {
0 commit comments