Skip to content

solution#178

Open
snezhana-recruit wants to merge 2 commits intomate-academy:masterfrom
snezhana-recruit:master
Open

solution#178
snezhana-recruit wants to merge 2 commits intomate-academy:masterfrom
snezhana-recruit:master

Conversation

@snezhana-recruit
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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:

  1. 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 the Content-Type header to text/html and wrap the JSON string in a basic HTML structure (e.g., using <pre> tags).

  2. Inconsistent Test Assertion: In tests/formDataServer.test.js, the assertion expect(response.data).toStrictEqual(expense) is now incorrect. Since the server should return an HTML string, you need to update this to check that the response.data string contains the expected JSON data, perhaps using a string matching method like toContain().

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example


expect(response.headers['content-type']).toBe('application/json');
expect(response.headers['content-type']).toBe('text/html');
expect(response.data).toStrictEqual(expense);

Choose a reason for hiding this comment

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

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');

Choose a reason for hiding this comment

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

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));

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants