Skip to content

Conversation

@Mitlosh
Copy link

@Mitlosh Mitlosh commented Oct 6, 2025

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

I’m requesting changes because there are critical blockers that violate the specified requirements and will cause tests to fail.

  • Non-GET handling: For unsupported methods you currently do res.statusCode = 404 and res.end('Not Found'). The spec requires JSON responses with Content-Type: application/json. Please send a JSON body (e.g., { errors: [{ message: 'Not Found' }] }) and set headers via res.writeHead(404, 'Not Found', { 'Content-Type': 'application/json' }) [see current lines with res.statusCode = 404; res.end('Not Found');].
  • URL parsing: You’re using new URL(...), but the requirement is to split req.url by ? and then use URLSearchParams. Replace with: const [path, queryString] = req.url.split('?'); const params = new URLSearchParams(queryString || ''); const toCase = params.get('toCase'); const text = decodeURIComponent((path || '/').slice(1)); and update references accordingly.
  • Function call order: convertToCase must be called as convertToCase(toCase, text), not convertToCase(text, toCase). This currently breaks conversions.
  • Success response shape: After fixing the call, avoid spreading the result object directly. Build the JSON explicitly with originalCase: result.originalCase, targetCase: toCase, originalText: text, and convertedText: result.convertedText to match the required schema.

Everything else (validation, status codes on success and errors) looks solid. Addressing the above will align your server with the spec and unblock the tests. Keep going—you’re 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

Comment on lines 9 to 11
if (req.method !== 'GET') {
res.statusCode = 404;
res.end('Not Found');

Choose a reason for hiding this comment

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

Non-GET requests are handled by returning plain text with no Content-Type and res.statusCode = 404 + res.end('Not Found'). The spec requires that the server should always respond with JSON (set Content-Type: application/json). Even for unsupported methods, return a JSON body (for example an errors array) and set the appropriate status and status text. Update this block to send a JSON response and include Content-Type: 'application/json' in headers.

Current lines: res.statusCode = 404; and res.end('Not Found');

Comment on lines 17 to 18
const base = `http://${req.headers.host || 'localhost'}`;
const parsed = new URL(req.url, base);

Choose a reason for hiding this comment

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

The implementation uses the URL constructor to parse req.url (creating parsed), but the task explicitly requires splitting req.url by ? and using URLSearchParams on the query string. Please change the parsing to follow the required approach:

const [path, queryString] = req.url.split('?');
const params = new URLSearchParams(queryString || '');
const toCase = params.get('toCase');
const text = decodeURIComponent((path || '/').slice(1));

This must replace the new URL(...) usage so the implementation matches the description exactly (see the task description for parsing guidance).

Comment on lines 20 to 21
const toCase = parsed.searchParams.get('toCase');
const text = decodeURIComponent(parsed.pathname.slice(1));

Choose a reason for hiding this comment

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

Related to the previous comment: the code reads parsed.searchParams.get('toCase') and parsed.pathname.slice(1) which comes from the URL object. Instead, after splitting req.url by ?, use new URLSearchParams(queryString) and read toCase with params.get('toCase'). Also ensure text is taken from the first part (path) with the leading / removed and decoded. This is required by the description; please update lines accordingly.

return;
}

const convertedText = convertToCase(text, toCase);

Choose a reason for hiding this comment

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

The call to convertToCase uses the wrong parameter order. The description states the function accepts two params: the case name first, and the text second: convertToCase(caseName, text). Your code calls convertToCase(text, toCase). This must be changed to convertToCase(toCase, text) so the business logic is invoked correctly. Additionally, name the returned value something like result or conversionResult (it currently uses convertedText which is confusing because the function returns an object with convertedText inside it).

Comment on lines +61 to +64
JSON.stringify({
...convertedText,
targetCase: toCase,
originalText: text,

Choose a reason for hiding this comment

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

On success you spread the returned object (...convertedText) into the response. That relies on convertToCase returning an object with originalCase and convertedText (which is correct), but because of the wrong call order above the return will be incorrect. After fixing the call to convertToCase(toCase, text), rename the variable to e.g. result and construct the response explicitly so the returned JSON contains exactly these fields: originalCase (from result.originalCase), targetCase (the requested toCase), originalText (the extracted text), and convertedText (from result.convertedText). This will ensure the response exactly matches the required schema.

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

Decision: Request Changes — there are critical blockers that will cause incorrect behavior and failing tests.

  • Critical: In src/createServer.js, the call to convertToCase uses the wrong argument order (currently convertToCase(text, toCase)), but the requirement is convertToCase(caseName, text). This leads to wrong conversions. Fix by calling const result = convertToCase(toCase, text) and then use result.originalCase and result.convertedText when building the response.
  • Critical: For non-GET requests, the response uses 404 with status message 'Bad request' and a body that isn’t in the { errors: [...] } shape. Update to a consistent error response per requirements (e.g., 405 'Method Not Allowed' with {'errors': [{'message': 'Method Not Allowed'}]}), or if you choose 404, use 'Not Found' and still return the errors array.
  • Improvement: On success, explicitly construct the JSON response instead of spreading the result. For example: set status 200 'OK' and return { originalCase: result.originalCase, targetCase: toCase, originalText: text, convertedText: result.convertedText }.

You’ve done a solid job on URL parsing, validation, and JSON headers. Addressing the above will align the implementation with the spec and should make tests pass. Keep it up!


✨ 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

return;
}

const convertedText = convertToCase(text, toCase);

Choose a reason for hiding this comment

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

The call to convertToCase on this line uses the wrong argument order and the variable name is misleading. The task requires calling convertToCase(caseName, text) (case name first, then text). Right now you call convertToCase(text, toCase). This will produce incorrect conversions and fail tests. Also convertToCase returns an object ({ originalCase, convertedText }), so the variable should be named accordingly (e.g., result). Consider changing to:

const result = convertToCase(toCase, text);

and then use result.originalCase and result.convertedText when building the response. This matches the required function signature and return shape.

Comment on lines 10 to 11
res.writeHead(404, 'Bad request', { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: 'Only GET method is supported' }));

Choose a reason for hiding this comment

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

Non-GET handling currently does res.writeHead(404, 'Bad request', ...) and sends a body { message: 'Only GET method is supported' }. Two problems:

  • The status code (404) and status message ('Bad request') are inconsistent. If you want 404 use 'Not Found', or better use 405 'Method Not Allowed' with an appropriate message.
  • The project requires the server always respond with JSON. For consistency with validation errors it's better to return an errors array (for example: { errors: [{ message: 'Method Not Allowed' }] }).

Update this branch so the status code, status message and JSON body are consistent and always follow the JSON errors format used elsewhere.

Comment on lines +62 to +64
...convertedText,
targetCase: toCase,
originalText: text,

Choose a reason for hiding this comment

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

On success you spread the result object into the response (...convertedText) and then add targetCase and originalText. Once you fix the convertToCase call (see earlier comment) it's clearer and safer to explicitly construct the response JSON to match the required schema:

res.writeHead(200, 'OK', { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
  originalCase: result.originalCase,
  targetCase: toCase,
  originalText: text,
  convertedText: result.convertedText,
}));

This ensures the response fields are exactly as the spec requires and avoids relying on spreading.

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

Educational approval to help you progress while learning. You’ve implemented the server flow well: parsing the URL, validating inputs, and returning JSON with appropriate status codes. However, there are three critical fixes needed:

  1. Wrong argument order to convertToCase (src/createServer.js, around the conversion call) — it should be convertToCase(toCase, text) because the function expects (caseName, text). Also, capture the returned object (e.g., const result = convertToCase(toCase, text)) and use result.originalCase and result.convertedText.
  2. Non-GET response shape (src/createServer.js, in the method check) — return { errors: [{ message: 'Method Not Allowed' }] } with status 405 and Content-Type: application/json to match the required error schema.
  3. Success response construction (src/createServer.js, when sending 200) — instead of spreading the conversion result, explicitly return { originalCase: result.originalCase, targetCase: toCase, originalText: text, convertedText: result.convertedText } to satisfy the exact schema.

Minor improvement: ensure the 405 status message matches the code (“Method Not Allowed”). You’re very close—nice work on validation and headers; fix the above and your implementation should pass the tests. Keep going—you’ve got this!


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

Footnotes

  1. Rate AI review example

Comment on lines +9 to +13
if (req.method !== 'GET') {
res.writeHead(405, 'Method Not Allowed', {
'Content-Type': 'application/json',
});
res.end(JSON.stringify({ message: 'Only GET method is supported' }));

Choose a reason for hiding this comment

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

Non-GET handling returns a JSON object { message: 'Only GET method is supported' } instead of the required error shape. The project requires consistent JSON error responses (an errors array of objects { message }). Update this branch to set an appropriate status (405 is fine) and return a body shaped like:

{ "errors": [ { "message": "Method Not Allowed" } ] }

Also ensure Content-Type remains application/json and status message matches the code if you rely on it.

return;
}

const convertedText = convertToCase(text, toCase);

Choose a reason for hiding this comment

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

Critical: convertToCase is called with the wrong argument order. The business logic expects (caseName, text). Change this call to pass toCase first and text second. Also the function returns an object like { originalCase, convertedText } — capture it in a variable (e.g. const result = convertToCase(toCase, text)) and use result.originalCase and result.convertedText when building the response body.

Comment on lines +63 to +66
JSON.stringify({
...convertedText,
targetCase: toCase,
originalText: text,

Choose a reason for hiding this comment

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

Response construction: currently you spread convertedText into the response (...convertedText). After fixing the convertToCase call and naming its result (e.g. result), explicitly construct the success JSON to exactly match the required schema:

{
  originalCase: result.originalCase,
  targetCase: toCase,
  originalText: text,
  convertedText: result.convertedText
}

This avoids relying on the shape produced by convertToCase and ensures tests that assert specific field order/values pass.

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