Last active
July 7, 2017 16:08
-
-
Save sirbrillig/b1231c84c98d91397ffb5b2248b06d8e to your computer and use it in GitHub Desktop.
Temporary fix for bug in wpcom-proxy-request in gravatar-upload code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 3c4a2b6c909adad9190bedcc34dec2810c5bb8a8 | |
Author: Payton Swick <[email protected]> | |
Date: Wed Jul 5 16:45:45 2017 -0400 | |
Data-layer: add temp fix for wpcom-proxy-request bug | |
See https://github.com/Automattic/wpcom-proxy-request/pull/20 | |
diff --git a/client/state/data-layer/wpcom/gravatar-upload/index.js b/client/state/data-layer/wpcom/gravatar-upload/index.js | |
index 7761d9b..bc23161 100644 | |
--- a/client/state/data-layer/wpcom/gravatar-upload/index.js | |
+++ b/client/state/data-layer/wpcom/gravatar-upload/index.js | |
@@ -30,7 +30,14 @@ export function uploadGravatar( { dispatch }, action ) { | |
}, action ) ); | |
} | |
-export function announceSuccess( { dispatch }, { file } ) { | |
+export function announceSuccess( { dispatch }, { file }, next, data ) { | |
+ // Sometimes wpcom-proxy-request reports a failed connection as a success, so | |
+ // we test for the response here. See | |
+ // https://github.com/Automattic/wp-calypso/pull/15636#issuecomment-312860944 | |
+ if ( ! data.success ) { | |
+ return announceFailure( { dispatch } ); | |
+ } | |
+ | |
const fileReader = new FileReader(); | |
fileReader.addEventListener( 'load', () => { | |
dispatch( { | |
diff --git a/client/state/data-layer/wpcom/gravatar-upload/test/index.js b/client/state/data-layer/wpcom/gravatar-upload/test/index.js | |
index f1f70a9..0526c2d 100644 | |
--- a/client/state/data-layer/wpcom/gravatar-upload/test/index.js | |
+++ b/client/state/data-layer/wpcom/gravatar-upload/test/index.js | |
@@ -64,6 +64,20 @@ describe( '#announceSuccess()', () => { | |
} ); | |
} ); | |
+ it( 'dispatches a failure action if `success` was not set', () => { | |
+ const action = { | |
+ type: 'DUMMY_ACTION', | |
+ file: 'file', | |
+ email: 'email', | |
+ }; | |
+ const dispatch = spy(); | |
+ | |
+ announceSuccess( { dispatch }, action, noop, {} ); | |
+ | |
+ expect( dispatch ).to.have.been.calledOnce; | |
+ expect( dispatch ).to.have.been.calledWith( sinon.match( { type: GRAVATAR_UPLOAD_REQUEST_FAILURE } ) ); | |
+ } ); | |
+ | |
it( 'dispatches a success action when the file is read', () => { | |
const action = { | |
type: 'DUMMY_ACTION', |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment