-
Notifications
You must be signed in to change notification settings - Fork 998
solution #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
solution #999
Conversation
There was a problem hiding this 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 = 404andres.end('Not Found'). The spec requires JSON responses withContent-Type: application/json. Please send a JSON body (e.g.,{ errors: [{ message: 'Not Found' }] }) and set headers viares.writeHead(404, 'Not Found', { 'Content-Type': 'application/json' })[see current lines withres.statusCode = 404; res.end('Not Found');]. - URL parsing: You’re using
new URL(...), but the requirement is to splitreq.urlby?and then useURLSearchParams. 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:
convertToCasemust be called asconvertToCase(toCase, text), notconvertToCase(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, andconvertedText: result.convertedTextto 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
src/createServer.js
Outdated
| if (req.method !== 'GET') { | ||
| res.statusCode = 404; | ||
| res.end('Not Found'); |
There was a problem hiding this comment.
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');
src/createServer.js
Outdated
| const base = `http://${req.headers.host || 'localhost'}`; | ||
| const parsed = new URL(req.url, base); |
There was a problem hiding this comment.
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).
src/createServer.js
Outdated
| const toCase = parsed.searchParams.get('toCase'); | ||
| const text = decodeURIComponent(parsed.pathname.slice(1)); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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).
| JSON.stringify({ | ||
| ...convertedText, | ||
| targetCase: toCase, | ||
| originalText: text, |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 toconvertToCaseuses the wrong argument order (currentlyconvertToCase(text, toCase)), but the requirement isconvertToCase(caseName, text). This leads to wrong conversions. Fix by callingconst result = convertToCase(toCase, text)and then useresult.originalCaseandresult.convertedTextwhen building the response. - Critical: For non-GET requests, the response uses
404with 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 choose404, use'Not Found'and still return theerrorsarray. - 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
| return; | ||
| } | ||
|
|
||
| const convertedText = convertToCase(text, toCase); |
There was a problem hiding this comment.
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.
src/createServer.js
Outdated
| res.writeHead(404, 'Bad request', { 'Content-Type': 'application/json' }); | ||
| res.end(JSON.stringify({ message: 'Only GET method is supported' })); |
There was a problem hiding this comment.
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
errorsarray (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.
| ...convertedText, | ||
| targetCase: toCase, | ||
| originalText: text, |
There was a problem hiding this comment.
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.
There was a problem hiding this 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:
- Wrong argument order to
convertToCase(src/createServer.js, around the conversion call) — it should beconvertToCase(toCase, text)because the function expects(caseName, text). Also, capture the returned object (e.g.,const result = convertToCase(toCase, text)) and useresult.originalCaseandresult.convertedText. - Non-GET response shape (src/createServer.js, in the method check) — return
{ errors: [{ message: 'Method Not Allowed' }] }with status 405 andContent-Type: application/jsonto match the required error schema. - 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
| if (req.method !== 'GET') { | ||
| res.writeHead(405, 'Method Not Allowed', { | ||
| 'Content-Type': 'application/json', | ||
| }); | ||
| res.end(JSON.stringify({ message: 'Only GET method is supported' })); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
| JSON.stringify({ | ||
| ...convertedText, | ||
| targetCase: toCase, | ||
| originalText: text, |
There was a problem hiding this comment.
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.
No description provided.