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

Wrap published post details #64

Merged
merged 4 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/commands/create-post.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/**
* Create a Post
*
* @param postData {
* `postType` - Post type,
* `title` - Post Title,
* `content` - Post Content,
* `status` - Post Status,
* `beforeSave` - Callable function hook
* }
* @param postData - Post data
*
* @returns Wraps post data object. See WP_REST_Posts_Controller::prepare_item_for_response
* for the reference of post object contents:
* https://github.com/WordPress/WordPress/blob/master/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
*
* @example
* Create a Post
* Create a Post and get ID
* ```
* cy.createPost({
* title: 'Test Post',
* content: 'Test Content'
* })
* }).then(post => {
* const id = post.id;
* });
* ```
*
* @example
Expand Down Expand Up @@ -99,10 +99,24 @@ export const createPost = ({
cy.get('.editor-post-publish-panel__toggle').should('be.enabled');
cy.get('.editor-post-publish-panel__toggle').click();

cy.intercept({ method: 'POST' }, req => {
const body: {
status: string;
title: string;
} = req.body;
if (body.status === 'publish' && body.title === title) {
req.alias = 'publishPost';
}
});

cy.get('.editor-post-publish-button').click();

cy.get('.components-snackbar, .components-notice.is-success').should(
'be.visible'
);

cy.wait('@publishPost').then(response => {
cy.wrap(response.response?.body);
});
}
};
15 changes: 15 additions & 0 deletions tests/cypress/integration/create-post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,19 @@ describe('Command: createPost', () => {
.find('.post-state')
.should('contain.text', 'Sticky');
});

it('Should be able to get published post details', () => {
const postTitle = 'Post ' + randomName();
const postContent = 'Content ' + randomName();
cy.createPost({
title: postTitle,
content: postContent,
}).then(post => {
assert(post.title.raw === postTitle, 'Post title is the same');
assert(
post.content.rendered.includes(postContent),
'Post content is the same'
);
});
});
});