Skip to content

solution#1144

Open
artembaranovsky1 wants to merge 2 commits into
mate-academy:masterfrom
artembaranovsky1:develop
Open

solution#1144
artembaranovsky1 wants to merge 2 commits into
mate-academy:masterfrom
artembaranovsky1:develop

Conversation

@artembaranovsky1

Copy link
Copy Markdown

No description provided.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am requesting changes because one explicit functional requirement from the checklist is not yet met, which makes this a blocking issue. The server is required to set both the HTTP status code and status text explicitly: 200 with status text "OK" for successful responses, and 400 with status text "Bad request" for validation errors ([CHECKLIST ITEM #9] and [CHECKLIST ITEM #16]). Currently, in src/createServer.js and src/validateRequest.js you only set the status code (e.g. res.statusCode = 400 or res.writeHead(200, { ... })) and omit the explicit status message, so the behavior relies on Node’s defaults instead of conforming to the requirement.

To fix this, update your responses to use the writeHead overload that includes the status message, for example:

  • For errors (e.g. where validation fails in createServer or validateRequest): res.writeHead(400, 'Bad request', { 'Content-Type': 'application/json' });
  • For success (where you return the conversion result): res.writeHead(200, 'OK', { 'Content-Type': 'application/json' });

Everything else—URL parsing, validation messages, JSON response shapes, and use of convertToCase/detectCase—is correctly implemented and aligned with the task. As a minor, non-blocking improvement, you can also remove or actually use the unused PORT parameter in createServer to keep the API clear. Once you explicitly set the status text in both success and error paths, your solution should fully satisfy the requirements. Keep up the good work; you’re very close to completion.


✨ 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

const targetCase = normalizedUrl.searchParams.get('toCase');
const originalText = normalizedUrl.pathname.slice(1);

return { targetCase, originalText };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The PORT parameter is unused. While not breaking functionality, it’s misleading; either remove it or use it where the server is actually started so the function signature reflects its behavior.

Comment thread src/createServer.js Outdated
const errors = validateRequest(originalText, targetCase);

if (errors.length > 0) {
res.statusCode = 400;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For error responses, the checklist requires status code 400 with status text Bad request. Here you only set statusCode; consider using res.writeHead(400, 'Bad request', { 'Content-Type': 'application/json' }) or setting res.statusMessage = 'Bad request' before ending the response.

Comment thread src/createServer.js Outdated
const { convertedText } = convertToCase(originalText, targetCase);
const originalCase = detectCase(originalText);

res.writeHead(200, { 'Content-Type': 'application/json' });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Successful responses must be 200 with status text OK according to the requirements. Here you’re only passing the status code; update this to include the status text (e.g. res.writeHead(200, 'OK', { 'Content-Type': 'application/json' })).

Comment thread src/validateRequest.js
Comment on lines +13 to +17

if (!toCase) {
errors.push({
message:
'"toCase" query param is required. Correct request is: ' +

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The error response correctly sets status code 400 and JSON content type, and returns the required { errors: [...] } payload, but checklist items #15 and #16 also require the status text to be explicitly set to "Bad request". In Node you can satisfy this by using res.writeHead(400, 'Bad request', { 'Content-Type': 'application/json' }) instead of only setting statusCode.

Comment thread src/validateRequest.js
}

if (toCase && !cases.includes(toCase)) {
errors.push({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For successful responses checklist item #9 requires status 200 with status text "OK". Here you set only the status code and headers; consider using the writeHead overload that includes the status message, e.g. res.writeHead(200, 'OK', { 'Content-Type': 'application/json' }), to fully match the requirement.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am approving your solution because it now fully matches the functional and technical requirements for the case-conversion server. Your createServer implementation correctly uses Node’s http module, delegates parsing to getRequestData, and calls validateRequest before invoking convertToCase, all in the expected control flow. Validation covers all required rules (missing text, missing toCase, unsupported case) and returns an array of errors, and the error responses use status 400 with status text "Bad request" and the correct JSON shape { "errors": [ { "message": ... } ] }. On the success path, you call convertToCase(originalText, targetCase) and include originalCase, targetCase, originalText, and convertedText in the 200 "OK" JSON response, always setting Content-Type: application/json. There are no remaining critical or blocking issues; any remaining differences would be purely stylistic and not required for this task. Nicely done bringing everything in line with the specification and supporting multiple validation errors cleanly.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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