Conversation
|
Size Change: +431 B (0%) Total Size: 1.43 MB
ℹ️ View Unchanged
|
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
| actions: { getStatusCheck }, | ||
| } = useAPI(); | ||
|
|
||
| const doStatusCheck = useCallback(() => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: {}
}
);There was a problem hiding this comment.
But your point above, is that we need to send real data here. Is a mock object good enough here?
There was a problem hiding this comment.
A mock object is good enough.
getStoryMarkup() gets us good enough real data, a full HTML document.
There was a problem hiding this comment.
I now mock the story data. We cab improve this later.
swissspidy
left a comment
There was a problem hiding this comment.
Requesting changes as per the comments I left before
includes/REST_API/Status_Check.php
Outdated
| * | ||
| * @return bool | ||
| */ | ||
| public function check_html_string( $param ) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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')); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
@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.
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