-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Posts: Add posts Redux state handlers #2248
Conversation
} ).catch( done ); | ||
} ); | ||
} ); | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a great example test file and is worth publishing in a weekly digest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a great example test file and is worth publishing in a weekly digest
Thanks @dmsnell !
Related, I had struggled for a while to find a way to test the dispatch callback without relying on the return value being a promise. I think this is reflected by the requested Sinon feature at sinonjs/sinon#118, as it could allow me to write something like:
// Before:
requestSitePosts( 77203074 )( spy ).then( () => {
expect( spy ).to.have.been.calledWith( {
type: POSTS_REQUEST_FAILURE,
siteId: 77203074,
query: {},
error: sinon.match( { message: 'User cannot access this private blog.' } )
} );
done();
} ).catch( done );
// After:
const stub = sinon.stub().calledWith( {
type: POSTS_REQUEST_FAILURE,
siteId: 77203074,
query: {},
error: sinon.match( { message: 'User cannot access this private blog.' } )
} ).calls( done );
requestSitePosts( 77203074 )( stub );
Curious if anyone has encountered a similar need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just getting started in my journey to learn what sinon offers, but I'm really impressed with it. We could probably all benefit by spending some focussed time reading through their (pretty incredible) documentation.
as far as your response goes - I haven't seen many people besides you actually stubbing up calls like these, so I'm not familiar with other attempts at it.
06049fc
to
4ea186c
Compare
Simplified handling of single post received vs. multiple posts
4ea186c
to
dfc1313
Compare
Posts: Add posts Redux state handlers
Related: #708, #2167
Prerequisite of: #303
This pull request seeks to add new basic posts querying handlers to the global Redux state. This will be used in the post editor in enabling a user to search for existing content to link.
Implementation notes:
A few choices worth scrutinized review:
global_ID
, so that theitems
map could be a simple flattened object. Since post IDs are unique to a specific site,global_ID
enables us to keep all known posts more readily accessible.postsList
method). Aside from allowing multiple post queries to be performed, this also prevents unnecessary re-requests when switching back to a previously known query result.Testing instructions:
Confirm that Mocha tests pass by running
make run
in the project root directory, or directly fromclient/state/posts
.The included actions are not currently used anywhere in the application, though you should confirm that the inclusion of the
posts
reducer does not cause any errors to occur when loading any Calypso page.