Skip to content

Add REST API Status Checks#4918

Merged
swissspidy merged 29 commits intomainfrom
feature/status-check
Nov 11, 2020
Merged

Add REST API Status Checks#4918
swissspidy merged 29 commits intomainfrom
feature/status-check

Conversation

@spacedmonkey
Copy link
Copy Markdown
Contributor

@spacedmonkey spacedmonkey commented Oct 19, 2020

Summary

Add a basic REST API Status Checks.

Relevant Technical Choices

Added basic REST API status check. For now it just returns true but in the future, better checks can be added to make sure that all communication are working correctly. Styling will follow in #4847

To-do

User-facing changes

Testing Instructions


Fixes #4790

@spacedmonkey spacedmonkey self-assigned this Oct 19, 2020
@google-cla google-cla bot added the cla: yes label Oct 19, 2020
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 19, 2020

Size Change: +431 B (0%)

Total Size: 1.43 MB

Filename Size Change
assets/js/edit-story.js 545 kB +318 B (0%)
assets/js/stories-dashboard.js 610 kB +113 B (0%)
ℹ️ View Unchanged
Filename Size Change
assets/css/edit-story.css 909 B 0 B
assets/css/stories-dashboard.css 939 B 0 B
assets/css/web-stories-embed-block.css 515 B 0 B
assets/js/chunk-fonts-********************.js 44 kB 0 B
assets/js/chunk-web-stories-template-0-********************.js 10.2 kB 0 B
assets/js/chunk-web-stories-template-1-********************.js 10.2 kB 0 B
assets/js/chunk-web-stories-template-2-********************.js 9.97 kB 0 B
assets/js/chunk-web-stories-template-3-********************.js 10.5 kB 0 B
assets/js/chunk-web-stories-template-4-********************.js 10.6 kB 0 B
assets/js/chunk-web-stories-template-5-********************.js 6.83 kB 0 B
assets/js/chunk-web-stories-template-6-********************.js 9.87 kB 0 B
assets/js/chunk-web-stories-template-7-********************.js 9.75 kB 0 B
assets/js/chunk-web-stories-textset-0-********************.js 5.25 kB 0 B
assets/js/chunk-web-stories-textset-1-********************.js 6.58 kB 0 B
assets/js/chunk-web-stories-textset-2-********************.js 7.83 kB 0 B
assets/js/chunk-web-stories-textset-3-********************.js 15.2 kB 0 B
assets/js/chunk-web-stories-textset-4-********************.js 4.38 kB 0 B
assets/js/chunk-web-stories-textset-5-********************.js 5.68 kB 0 B
assets/js/chunk-web-stories-textset-6-********************.js 5.47 kB 0 B
assets/js/chunk-web-stories-textset-7-********************.js 10.3 kB 0 B
assets/js/web-stories-activation-notice.js 74 kB 0 B
assets/js/web-stories-embed-block.js 17.2 kB 0 B

compressed-size-action

@spacedmonkey spacedmonkey marked this pull request as ready for review October 19, 2020 17:12
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 26, 2020

Codecov Report

Merging #4918 (901407e) into main (5f6b088) will increase coverage by 0.18%.
The diff coverage is 98.03%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4918      +/-   ##
==========================================
+ Coverage   76.22%   76.40%   +0.18%     
==========================================
  Files         958      961       +3     
  Lines       16949    16996      +47     
==========================================
+ Hits        12919    12986      +67     
+ Misses       4030     4010      -20     
Flag Coverage Δ
karmatests 53.71% <35.00%> (+1.20%) ⬆️
unittests 66.38% <90.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
assets/src/edit-story/app/index.js 100.00% <ø> (ø)
assets/src/edit-story/app/api/apiProvider.js 54.54% <50.00%> (-0.22%) ⬇️
...c/edit-story/components/statusCheck/statusCheck.js 100.00% <100.00%> (ø)
...ets/src/edit-story/components/statusCheck/utils.js 100.00% <100.00%> (ø)
includes/Experiments.php 97.58% <100.00%> (+0.08%) ⬆️
includes/Plugin.php 100.00% <100.00%> (ø)
includes/REST_API/Status_Check_Controller.php 100.00% <100.00%> (ø)
includes/Story_Post_Type.php 91.25% <100.00%> (+0.03%) ⬆️
... and 5 more

actions: { getStatusCheck },
} = useAPI();

const doStatusCheck = useCallback(() => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As mentioned in #4790 (comment), to catch things like WAF blocking requests we'd need to send actual HTML markup here. Could be as simple as calling getStoryMarkup() on a stub story and sending that markup in the POST request.

And since web-stories/v1/status-check supports all request methods, we can probably even send two requests, one GET and one POST.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we can add this later. It is the basics on this feature, we can improve later.

# Conflicts:
#	assets/src/edit-story/app/api/apiProvider.js
@spacedmonkey
Copy link
Copy Markdown
Contributor Author

I have hidden the feature and submit html to the endpoint. It still needs some more testing and fix some warnings. Is what we have now what you had in mind @swissspidy ?


const doStatusCheck = useCallback(() => {
if (statusCheck && story && story.status && pages) {
const content = getStoryMarkup(story, pages, metadata, flags);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changing this to generate real markup as meant that I had to move this lower in app tree. Meaning it is running more often and we have to wait for this pieces of state to be setup. Instead of dong this, should we just mock a html string?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Makes sense. Can you ideally use getStoryMarkup() on a mock story object? No need to get story from state.

Something simple like this should be enough:

getStoryMarkup(
  {
    title: 'Status Check'
    link: 'https://example.com/',
  },
  [],
  {
    publisher: {}
  }
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But your point above, is that we need to send real data here. Is a mock object good enough here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A mock object is good enough.

getStoryMarkup() gets us good enough real data, a full HTML document.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I now mock the story data. We cab improve this later.

@swissspidy swissspidy added Pod: WP & Infra Type: Enhancement New feature or improvement of an existing feature labels Oct 28, 2020
Copy link
Copy Markdown
Collaborator

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

Requesting changes as per the comments I left before

*
* @return bool
*/
public function check_html_string( $param ) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think we need this validation callback.

If anything, the status_check method above could return the sent content or a hash of it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This validates that the string submitted is HTML. This is test for firewalls that are removing html that is submitted. I can remove this check, but I think we need to check the values submitted to the api at PHP level, otherwise what is the point of submitting them?

getStatusCheck(content)
.then(() => {
// eslint-disable-next-line no-console
console.log(__('Status Check successful.', 'web-stories'));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't love these, but they will do for now.

it('successful', () => {
setup(Promise.resolve({ success: true }));
// todo add a test here.
expect(true).toBeTrue();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@swissspidy As mentioned in sprint planning, these are the mock tests that test for nothing for now. Mocking console.log didn't make a lot of sense here. We can fix these tests when this feature is finally implemented.

@swissspidy swissspidy merged commit a0a68e9 into main Nov 11, 2020
@swissspidy swissspidy deleted the feature/status-check branch November 11, 2020 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Enhancement New feature or improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Status Check: Add REST API endpoint

3 participants