Skip to content

The Solution#1112

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

The Solution#1112
1umamaster wants to merge 2 commits into
mate-academy:masterfrom
1umamaster:develop

Conversation

@1umamaster
Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings April 18, 2026 16:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements the case-transformer HTTP server endpoint, updates project tooling dependencies, and adds a GitHub Actions workflow template.

Changes:

  • Implemented createServer to parse requests, validate inputs, and return JSON conversion results/errors.
  • Upgraded @mate-academy/scripts devDependency (and updated lockfile accordingly).
  • Added .github/workflows/test.yml-template mirroring the CI workflow.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/createServer.js Adds HTTP server implementation with validation and JSON responses using convertToCase.
package.json Bumps @mate-academy/scripts to a newer version.
package-lock.json Updates lockfile entries for the new @mate-academy/scripts version.
.github/workflows/test.yml-template Adds a CI workflow template file (currently a duplicate of test.yml).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +17 to +22
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

This workflow uses deprecated/outdated action versions (actions/checkout@v2, actions/setup-node@v1). Update to currently supported majors (e.g., checkout@v4, setup-node@v4) and consider using npm ci for reproducible installs in CI.

Suggested change
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci

Copilot uses AI. Check for mistakes.
Comment thread src/createServer.js Outdated
Comment on lines +14 to +17
const url = new URL(req.url, `http://${req.headers.host}`);
const toCase = url.searchParams.get('toCase');
const text = url.pathname.slice(1);
const errors = { errors: [] };
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

new URL(req.url, �http://${req.headers.host}�) will throw if the request lacks a Host header (e.g., HTTP/1.0, some proxies, or malformed clients), which would crash the request handler. Consider using a fixed base URL (e.g., http://localhost) or a safe fallback when req.headers.host is missing, and return a 400 error if the URL can't be parsed.

Suggested change
const url = new URL(req.url, `http://${req.headers.host}`);
const toCase = url.searchParams.get('toCase');
const text = url.pathname.slice(1);
const errors = { errors: [] };
const errors = { errors: [] };
const baseUrl = `http://${req.headers.host || 'localhost'}`;
let url;
try {
url = new URL(req.url, baseUrl);
} catch (error) {
res.statusCode = 400;
res.statusMessage = 'Bad request';
res.end(
JSON.stringify({
errors: [
{
message:
'Invalid request URL. Correct request is: "/<TEXT_TO_CONVERT>?toCase=<CASE_NAME>".',
},
],
}),
);
return;
}
const toCase = url.searchParams.get('toCase');
const text = url.pathname.slice(1);

Copilot uses AI. Check for mistakes.
Comment thread src/createServer.js Outdated
Comment on lines +16 to +18
const text = url.pathname.slice(1);
const errors = { errors: [] };

Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

const text = url.pathname.slice(1) leaves percent-encoded characters intact (e.g., /hello%20world becomes hello%20world), which can lead to incorrect conversions for inputs containing spaces or non-ASCII characters. Decode the path segment (e.g., via decodeURIComponent) before passing it to convertToCase.

Suggested change
const text = url.pathname.slice(1);
const errors = { errors: [] };
const rawText = url.pathname.slice(1);
let text = '';
const errors = { errors: [] };
try {
text = decodeURIComponent(rawText);
} catch (error) {
errors.errors.push({
message:
'Text to convert contains invalid percent-encoding. Correct request is: "/<TEXT_TO_CONVERT>?toCase=<CASE_NAME>".',
});
}

Copilot uses AI. Check for mistakes.
Comment thread src/createServer.js Outdated
Comment on lines +13 to +14
const cases = ['SNAKE', 'KEBAB', 'CAMEL', 'PASCAL', 'UPPER'];
const url = new URL(req.url, `http://${req.headers.host}`);
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

cases is recreated on every request. Since this list is constant, define it once outside the request handler (and optionally use a Set for lookups) to reduce per-request allocations and keep validation logic centralized.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +3
name: Test

on:
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

test.yml-template duplicates the existing .github/workflows/test.yml but (because of its extension) won't be picked up by GitHub Actions. If it's not intentionally a reference file, it should be removed; otherwise consider moving it out of .github/workflows/ or adding a short comment explaining its purpose to avoid confusion.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@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 am requesting changes because there are still two critical mismatches with the task requirements that can cause the tests to fail.

  1. URL/query parsing method (src/createServer.js, around lines 10–25): you currently construct a new URL(req.url, ...) and use url.searchParams, but the task explicitly requires splitting req.url by '?' and using the global URLSearchParams on the query string ([CHECKLIST ITEM #23], [CHECKLIST ITEM #25], [CHECKLIST ITEM #20]). Please change this to something like:
    • const [path, queryString] = req.url.split('?');
    • const params = new URLSearchParams(queryString || '');
    • Derive text from the path part (e.g. const text = path.slice(1);).
  2. Success status text (src/createServer.js, around lines 40–55): on successful conversion you set res.statusCode = 200 but do not set res.statusMessage, while the requirements state the response must be status 200 with status text OK ([CHECKLIST ITEM #15]). Before sending a successful response, add res.statusMessage = 'OK'; for full compliance.

Aside from these two items, your server logic, validation, error handling, and integration with convertToCase look solid and match the specification well. Fixing these points should bring your implementation in line with the checklist and allow the tests to pass, so this is a good opportunity to practice following strict API and parsing requirements. Keep going—you’re very close to a fully correct solution.


✨ 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 thread src/createServer.js Outdated
Comment on lines +14 to +16
const url = new URL(req.url, `http://${req.headers.host}`);
const toCase = url.searchParams.get('toCase');
const text = url.pathname.slice(1);
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 code constructs a URL instance and uses url.searchParams to get query params and url.pathname for text. The task explicitly requires splitting req.url by ? and using the global URLSearchParams to parse the query string (see checklist items #23, #25 and #20). Please change the parsing to follow the required approach, e.g. split req.url into [path, queryString], use new URLSearchParams(queryString) and then params.get('toCase'), and derive text from the path part (slice off the leading '/').

Comment thread src/createServer.js
result.originalText = text;
result.targetCase = toCase;

res.statusCode = 200;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On success you set res.statusCode = 200 but do not set res.statusMessage. The requirements state the server should respond with status 200 and statusText OK (checklist item #15). Add res.statusMessage = 'OK' before sending the response.

Copy link
Copy Markdown

@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

Your solution is approved because the HTTP server behaves as required: it exposes a createServer function that returns an http server, always responds with Content-Type: application/json, and correctly parses the URL path and query string using req.url.split('?') and URLSearchParams. The implementation enforces that both text and toCase are provided, returns the exact specified error messages when they are missing or when toCase is not in the supported set, and responds with a 400 status and a JSON errors array in those cases. For valid input, the server calls convertToCase(text, toCase), uses its originalCase and convertedText fields, and returns the required JSON structure containing originalCase, targetCase, originalText, and convertedText with a 200 status and status message OK. The supported cases (SNAKE, KEBAB, CAMEL, PASCAL, UPPER) match the specification, and both success and error flows are covered correctly. As a small optional improvement, you could consider adding more robust handling for unexpected HTTP methods or extra paths, but this is not required for the current task. Nicely done meeting all the functional and validation requirements.


✨ 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.

3 participants