Esempio n. 1
0
		it( 'should dispatch an error notice and subscribe action using next', () => {
			const dispatch = spy();
			receivePostEmailUnsubscriptionError( { dispatch }, { payload: { blogId: 1234 } }, null );
			expect( dispatch ).to.have.been.calledWithMatch( {
				notice: {
					text: 'Sorry, we had a problem unsubscribing. Please try again.',
				},
			} );
			expect( dispatch ).to.have.been.calledWith( local( subscribeToNewPostEmail( 1234 ) ) );
		} );
Esempio n. 2
0
export function receiveUpdatePostEmailSubscriptionError(
	{ dispatch },
	{ payload: { blogId }, meta: { previousState } }
) {
	dispatch(
		errorNotice(
			translate( 'Sorry, we had a problem updating that subscription. Please try again.' )
		)
	);
	dispatch( local( updateNewPostEmailSubscription( blogId, previousState ) ) );
}
Esempio n. 3
0
export const updateCommentLikes = (
	{ dispatch },
	{ siteId, postId, commentId },
	{ like_count },
) =>
	dispatch(
		local( {
			type: COMMENTS_UNLIKE,
			siteId,
			postId,
			commentId,
			like_count,
		} ),
	);
Esempio n. 4
0
	it( 'should dispatch an like action to rollback optimistic update', () => {
		const dispatch = spy();

		handleUnlikeFailure( { dispatch }, { siteId: SITE_ID, postId: POST_ID, commentId: 1 } );

		expect( dispatch ).to.have.been.calledTwice;
		expect( dispatch ).to.have.been.calledWith(
			local( {
				type: COMMENTS_LIKE,
				siteId: SITE_ID,
				postId: POST_ID,
				commentId: 1,
			} ),
		);
	} );
Esempio n. 5
0
export function receivePostEmailSubscription( store, action, response ) {
	// validate that it worked
	const subscribed = !! ( response && response.subscribed );
	if ( ! subscribed ) {
		// shoot. something went wrong.
		receivePostEmailSubscriptionError( store, action );
		return;
	}
	// pass this on, but tack in the delivery_frequency that we got back from the API
	store.dispatch(
		local(
			updateNewPostEmailSubscription(
				action.payload.blogId,
				get( response, [ 'subscription', 'delivery_frequency' ] )
			)
		)
	);
}
Esempio n. 6
0
	it( 'should dispatch a comment like update action', () => {
		const dispatch = spy();

		updateCommentLikes( { dispatch }, { siteId: SITE_ID, postId: POST_ID, commentId: 1 }, {
			like_count: 4,
		} );

		expect( dispatch ).to.have.been.calledOnce;
		expect( dispatch ).to.have.been.calledWith(
			local( {
				type: COMMENTS_UNLIKE,
				siteId: SITE_ID,
				postId: POST_ID,
				commentId: 1,
				like_count: 4,
			} ),
		);
	} );
Esempio n. 7
0
export function receivePostEmailUnsubscriptionError( { dispatch }, action ) {
	dispatch(
		errorNotice( translate( 'Sorry, we had a problem unsubscribing. Please try again.' ) )
	);
	dispatch( local( subscribeToNewPostEmail( action.payload.blogId ) ) );
}
Esempio n. 8
0
export const handleUnlikeFailure = ( { dispatch }, { siteId, postId, commentId } ) => {
	// revert optimistic update on error
	dispatch( local( { type: COMMENTS_LIKE, siteId, postId, commentId } ) );
	// dispatch a error notice
	dispatch( errorNotice( translate( 'Could not unlike this comment' ) ) );
};