Skip to content

Refactor tests for expense submission endpoints#199

Merged
marina-tilniak merged 1 commit intomate-academy:masterfrom
mykhalenych:patch-1
Apr 21, 2026
Merged

Refactor tests for expense submission endpoints#199
marina-tilniak merged 1 commit intomate-academy:masterfrom
mykhalenych:patch-1

Conversation

@mykhalenych
Copy link
Copy Markdown
Contributor

No description provided.

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 the HTTP server implementation is incomplete/broken, which prevents the tests from running successfully and blocks the task’s core functionality.

Critical issues that must be fixed:

  1. In src/createServer.js (around the export at the bottom of the file, e.g. lines 10–20), createServer() is currently returning undefined, so the tests fail with TypeError: Cannot read properties of undefined (reading 'listen'); you need to import http, call http.createServer(app) (where app is your request handler), and return that Server instance, then export createServer in the way the tests import it.
  2. The request handler (likely in src/app.js, around the main http.createServer callback or exported function) must implement the required routes: GET / should respond with status 200, Content-Type: text/html, and an HTML form that includes inputs named date, title, and amount; POST /add-expense must parse both application/x-www-form-urlencoded and application/json bodies, validate that all three fields are present, write valid JSON data to db/expense.json only when the input is valid, and send back an HTML page containing formatted JSON (e.g. JSON.stringify(data, null, 2) inside <pre>); any other path must return a 404 status with a non-empty body.
  3. For invalid POST requests missing any required field, ensure you respond with status 400 and do not change the existing contents of db/expense.json (the tests pre-populate this file and then check that it remains untouched in error cases), so your validation logic should short‑circuit before any file write.

Minor improvements:

  • Make sure you set appropriate headers (especially Content-Type: text/html for HTML responses and a reasonable content type for errors) and keep responses simple but non-empty for 400 and 404 cases.

Once you adjust createServer to return a proper http.Server and implement the route behavior above, your solution should align well with the test expectations, and you’re very close—use the failing test messages as a guide to refine the last details.


✨ 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

@marina-tilniak marina-tilniak merged commit 5b67ffc into mate-academy:master Apr 21, 2026
1 check failed
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