Skip to content
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

Improve unit test coverage for REST API menus endpoints. #36177

Merged
merged 2 commits into from
Nov 4, 2021

Conversation

spacedmonkey
Copy link
Member

Description

Improve unit test coverage for REST API menus endpoints.

Bug fixes and tweaks to code to improve code.

Final tweaks, before core merge.

Fixes #34992

@spacedmonkey spacedmonkey added Core REST API Task Task for Core REST API efforts REST API Interaction Related to REST API [Block] Navigation Affects the Navigation Block [Feature] Navigation Screen labels Nov 3, 2021
@spacedmonkey spacedmonkey self-assigned this Nov 3, 2021
@@ -479,21 +479,23 @@ protected function prepare_item_for_database( $request ) {
}
}

$error = new WP_Error();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed, but makes debugging easier, as you can see multiple errors in REST API response.

@@ -324,7 +324,7 @@ public function update_item( $request ) {
* Deletes a single menu item.
*
* @param WP_REST_Request $request Full details about the request.
* @return true|WP_Error True on success, or WP_Error object on failure.
* @return WP_REST_Response|WP_Error True on success, or WP_Error object on failure.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return type was wrong.

if ( 'block' === $prepared_nav_item['menu-item-type'] ) {
if ( empty( $prepared_nav_item['menu-item-content'] ) ) {
return new WP_Error( 'rest_content_required', __( 'Content required if menu item of type block.', 'gutenberg' ), array( 'status' => 400 ) );
if ( 'block' === $prepared_nav_item['menu-item-type'] && empty( $prepared_nav_item['menu-item-content'] ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for two if statements here.

$links['https://api.w.org/object'][] = array(
'href' => rest_url( $path ),
'post_type' => $menu_item->type,
$key => $type,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was incorrect, this is a bug fix.

}

if ( $path ) {
if ( $path && $type ) {
$links['https://api.w.org/object'][] = array(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyBJacobs did you want to change this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's change the type to menu-item-object

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in dc23cdc

@TimothyBJacobs
Copy link
Member

Looks good, thanks. Yeah let's just adjust that menu item link relation.

@TimothyBJacobs TimothyBJacobs merged commit b2902e7 into trunk Nov 4, 2021
@TimothyBJacobs TimothyBJacobs deleted the fix/better-unit-tests branch November 4, 2021 15:37
@github-actions github-actions bot added this to the Gutenberg 11.9 milestone Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block Core REST API Task Task for Core REST API efforts REST API Interaction Related to REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve unit test coverage for REST API menus endpoints.
2 participants