-
Notifications
You must be signed in to change notification settings - Fork 998
Develop #1004
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?
Develop #1004
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 am requesting changes because there are critical issues that violate the required implementation details and will cause tests to fail. Specifically:
- In
src/createServer.js, the URL parsing must follow the spec: splitreq.urlby?intopathandqueryString, extracttextfrompath(remove leading/), and useconst params = new URLSearchParams(queryString || '')withparams.get('toCase'). Using theURLconstructor andurl.searchParamsdoes not meet the requirement. - The call to
convertToCaseuses the wrong argument order. Per the spec, it should beconvertToCase(caseName, text), so update the call toconvertToCase(toCase, text)to avoid incorrect outputs. - When returning validation errors, you must set both status code and status text exactly:
res.writeHead(400, 'Bad request', { 'Content-Type': 'application/json' }). Similarly, for success responses, explicitly setres.writeHead(200, 'OK', { 'Content-Type': 'application/json' }).
Everything else (error messages, response JSON shape, headers, export) looks good. Fixing the above will align the server with the checklist and allow the tests to pass. Keep up the good work—these are straightforward adjustments to make.
✨ 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
|
|
||
| function createServer() { | ||
| return http.createServer((req, res) => { | ||
| const url = new URL(req.url, `http://${req.headers.host}`); |
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 task requires splitting req.url by ? and using new URLSearchParams(queryString) to read the toCase value. This line uses the WHATWG URL constructor and url.searchParams instead of the exact required parsing approach. Update the code to: - split req.url by ? into path and queryString - extract text from the path (remove leading /) - create const params = new URLSearchParams(queryString || '') and use params.get('toCase') as required by the Implementation Details / Validation flow.
| } | ||
|
|
||
| try { | ||
| const { originalCase, 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.
You call convertToCase(text, toCase) here, but the specification requires convertToCase(caseName, text) (first argument = case name, second = text). This reversed order will produce incorrect results or runtime errors. Call convertToCase(toCase, text) so the function receives caseName first as required.
src/createServer.js
Outdated
| } | ||
|
|
||
| if (errors.length > 0) { | ||
| res.writeHead(400, { 'Content-Type': 'application/json' }); |
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.
When returning validation errors you must set HTTP status code and status text to exactly 400 and "Bad request" (the Implementation Details require the status text). Use the writeHead overload that accepts a status message, for example: res.writeHead(400, 'Bad request', { 'Content-Type': 'application/json' }). Currently the code only supplies headers, which will use Node's default status message (not the exact required text).
src/createServer.js
Outdated
| convertedText, | ||
| }; | ||
|
|
||
| res.writeHead(200, { 'Content-Type': 'application/json' }); |
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 requirements state the server must set the status text for successful responses to "OK". While Node's default for 200 is OK, to strictly follow the spec make the status text explicit by calling res.writeHead(200, 'OK', { 'Content-Type': 'application/json' }) before sending the success response.
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.
LGTM!
No description provided.