From 5946b8fdea10a0b781b0ca183b2d361ea78ed1a6 Mon Sep 17 00:00:00 2001 From: budzanowski Date: Mon, 12 Dec 2016 12:08:19 +0100 Subject: [PATCH] Adjust after review/discussion. --- client/state/themes/actions.js | 36 +++++++++++++---------------- client/state/themes/test/actions.js | 6 ++--- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/client/state/themes/actions.js b/client/state/themes/actions.js index cc84d0849ed99..d9bc5ea389cc0 100644 --- a/client/state/themes/actions.js +++ b/client/state/themes/actions.js @@ -422,27 +422,23 @@ export function installWpcomThemeOnJetpack( siteId, wpcomThemeId ) { wpcomThemeId } ); - return new Promise( ( resolve, reject ) => { - wpcom.undocumented().installThemeOnJetpack( siteId, wpcomThemeId ) - .then( ( theme ) => { - dispatch( receiveTheme( theme ) ); - dispatch( { - type: THEME_INSTALL_ON_JETPACK_REQUEST_SUCCESS, - siteId, - wpcomThemeId - } ); - resolve(); - } ) - .catch( ( error ) => { - dispatch( { - type: THEME_INSTALL_ON_JETPACK_REQUEST_FAILURE, - siteId, - wpcomThemeId, - error - } ); - reject( error ); + return wpcom.undocumented().installThemeOnJetpack( siteId, wpcomThemeId ) + .then( ( theme ) => { + dispatch( receiveTheme( theme ) ); + dispatch( { + type: THEME_INSTALL_ON_JETPACK_REQUEST_SUCCESS, + siteId, + wpcomThemeId } ); - } ); + } ) + .catch( ( error ) => { + dispatch( { + type: THEME_INSTALL_ON_JETPACK_REQUEST_FAILURE, + siteId, + wpcomThemeId, + error + } ); + } ); }; } diff --git a/client/state/themes/test/actions.js b/client/state/themes/test/actions.js index c98b9e2c1358d..28180d9a73e5f 100644 --- a/client/state/themes/test/actions.js +++ b/client/state/themes/test/actions.js @@ -681,7 +681,7 @@ describe( 'actions', () => { } ); it( 'should dispatch wpcom theme install request failure action when theme was not found', () => { - installWpcomThemeOnJetpack( 'jetpackenabledsite.com', 'typist-wpcom' )( spy ).then( () => { + return installWpcomThemeOnJetpack( 'jetpackenabledsite.com', 'typist-wpcom' )( spy ).then( () => { expect( spy ).to.have.been.calledWith( { type: THEME_INSTALL_ON_JETPACK_REQUEST_FAILURE, siteId: 'jetpackenabledsite.com', @@ -692,11 +692,11 @@ describe( 'actions', () => { } ); it( 'should dispatch wpcom theme install request failure action when theme is already installed', () => { - installWpcomThemeOnJetpack( 'jetpackenabledsite.com', 'pinboard-wpcom' )( spy ).then( () => { + return installWpcomThemeOnJetpack( 'jetpackenabledsite.com', 'pinboard-wpcom' )( spy ).then( () => { expect( spy ).to.have.been.calledWith( { type: THEME_INSTALL_ON_JETPACK_REQUEST_FAILURE, siteId: 'jetpackenabledsite.com', - themeId: 'pinboard', + wpcomThemeId: 'pinboard-wpcom', error: sinon.match( { message: 'The theme is already installed' } ), } ); } );