@@ -517,6 +517,111 @@ describe('module/api', function() {
517517 } ) ;
518518 } ) ;
519519
520+ describe ( '#confirm' , function ( ) {
521+ describe ( 'with unknown project' , function ( ) {
522+ it ( 'should 400 with message' , function ( ) {
523+ storageStub . hasProject = this . sinon . stub ( ) . resolves ( false ) ;
524+
525+ return api . post ( '/api/confirm' )
526+ . send ( {
527+ project : 'project' ,
528+ build : 'build'
529+ } )
530+ . expect ( 400 )
531+ . expect ( function ( data ) {
532+ var body = data . body ;
533+ assert . equal ( body . status , 'failure' ) ;
534+ assert . equal ( body . message , 'unknown project' ) ;
535+ } ) ;
536+ } ) ;
537+ } ) ;
538+
539+ describe ( 'with unknown build' , function ( ) {
540+ it ( 'should 400 with message' , function ( ) {
541+ storageStub . hasProject = this . sinon . stub ( ) . resolves ( true ) ;
542+ storageStub . hasBuild = this . sinon . stub ( ) . resolves ( false ) ;
543+
544+ return api . post ( '/api/confirm' )
545+ . send ( {
546+ project : 'project' ,
547+ build : 'build'
548+ } )
549+ . expect ( 400 )
550+ . expect ( function ( data ) {
551+ var body = data . body ;
552+ assert . equal ( body . status , 'failure' ) ;
553+ assert . equal ( body . message , 'unknown build' ) ;
554+ } ) ;
555+ } ) ;
556+ } ) ;
557+
558+ describe ( 'with known project and build' , function ( ) {
559+ var stub ;
560+ var buildInfo ;
561+
562+ beforeEach ( function ( ) {
563+ buildInfo = {
564+ project : 'project' ,
565+ head : 'head' ,
566+ status : 'failed' ,
567+ diffs : {
568+ 'Chrome 28' : [
569+ 'homepage.navbar.700.png' ,
570+ 'homepage.navbar.1300.png' ,
571+ 'homepage.search.700.png' ,
572+ 'homepage.search.1300.png'
573+ ] ,
574+ 'IE 8' : [
575+ 'homepage.navbar.700.png' ,
576+ 'homepage.search.700.png'
577+ ]
578+ }
579+ } ;
580+
581+ storageStub . hasProject = this . sinon . stub ( ) . resolves ( true ) ;
582+ storageStub . hasBuild = this . sinon . stub ( ) . resolves ( true ) ;
583+ storageStub . updateBuildInfo = this . sinon . stub ( ) . resolves ( ) ;
584+ storageStub . getBuildInfo = this . sinon . stub ( ) . resolves ( buildInfo ) ;
585+
586+ instance = api . post ( '/api/confirm' )
587+ . send ( {
588+ project : 'project' ,
589+ build : 'build'
590+ } ) ;
591+ } ) ;
592+
593+ it ( 'should be 200 with success' , function ( ) {
594+ return instance
595+ . expect ( 200 )
596+ . expect ( function ( data ) {
597+ var body = data . body ;
598+ assert . equal ( body . status , 'success' ) ;
599+ } ) ;
600+ } ) ;
601+
602+ it ( 'should call storage.updateBuildInfo' , function ( ) {
603+ return instance . expect ( function ( ) {
604+ buildInfo . status = 'approved' ;
605+
606+ assert . calledOnce ( storageStub . updateBuildInfo . withArgs ( buildInfo ) ) ;
607+ } ) ;
608+ } ) ;
609+
610+ it ( 'should call actions.setBuildStatus' , function ( ) {
611+ return instance
612+ . expect ( function ( ) {
613+ assert . calledOnce ( actionsStub . setBuildStatus
614+ . withArgs ( {
615+ project : 'project' ,
616+ sha : 'head' ,
617+ status : 'success'
618+ } )
619+ ) ;
620+ } ) ;
621+ } ) ;
622+ } ) ;
623+ } ) ;
624+
520625 describe ( '#getImage' , function ( ) {
521626 it ( 'should call getImage' , function ( ) {
522627 storageStub . getImage = this . sinon . stub ( ) ;
0 commit comments