Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job setting up the server and handling the form submission! The core logic is working correctly. However, this requires a change because the server's response doesn't quite meet the project requirements.
The main issue is that on a successful POST request, your server returns a raw JSON response (Content-Type: application/json). The requirement is to return an HTML page that contains the well-formatted JSON. You'll need to adjust your response handler in src/createServer.js to send back HTML content with a Content-Type of text/html. Consequently, the test in tests/formDataServer.test.js that checks for application/json will also need to be updated to reflect the correct requirement.
Additionally, for better practice, consider using the asynchronous fs.writeFile instead of fs.writeFileSync to avoid blocking server operations.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job updating the test to check for the correct Content-Type! However, the core issue from the previous review still needs to be addressed. The server's response for a successful POST request doesn't yet meet the project's requirements, which is a critical blocker.
Here are the two main things to fix:
-
Incorrect Server Response Format: In
src/createServer.js, the server is still sending raw JSON. It needs to respond with an HTML page that contains the well-formatted JSON data. You should set theContent-Typeheader totext/htmland wrap the JSON string in a basic HTML structure (e.g., using<pre>tags). -
Inconsistent Test Assertion: In
tests/formDataServer.test.js, the assertionexpect(response.data).toStrictEqual(expense)is now incorrect. Since the server should return an HTML string, you need to update this to check that theresponse.datastring contains the expected JSON data, perhaps using a string matching method liketoContain().
Once these are addressed, your solution will be complete. You're very close!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
|
|
||
| expect(response.headers['content-type']).toBe('application/json'); | ||
| expect(response.headers['content-type']).toBe('text/html'); | ||
| expect(response.data).toStrictEqual(expense); |
There was a problem hiding this comment.
This assertion is now inconsistent with the Content-Type check on the line above. If the server correctly returns an HTML page, response.data will be a string containing HTML, not a plain JavaScript object. You should update this to check that the returned HTML string contains the well-formatted JSON data.
| fs.writeFile('db/expense.json', body); | ||
|
|
||
| res.statusCode = 200; | ||
| res.setHeader('Content-Type', 'application/json'); |
There was a problem hiding this comment.
According to the task requirements, the server should return an HTML page after a successful POST request. This Content-Type header should be set to text/html.
|
|
||
| res.statusCode = 200; | ||
| res.setHeader('Content-Type', 'application/json'); | ||
| res.end(JSON.stringify(data)); |
There was a problem hiding this comment.
The task requires returning an HTML page that contains the well-formatted JSON, not just the raw JSON data. You should wrap this JSON data within an HTML structure, for example using <pre> tags for formatting.
No description provided.