Refactor tests for expense submission endpoints#199
Refactor tests for expense submission endpoints#199marina-tilniak merged 1 commit intomate-academy:masterfrom
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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:
- In
src/createServer.js(around the export at the bottom of the file, e.g. lines 10–20),createServer()is currently returningundefined, so the tests fail withTypeError: Cannot read properties of undefined (reading 'listen'); you need to importhttp, callhttp.createServer(app)(whereappis your request handler), and return thatServerinstance, then exportcreateServerin the way the tests import it. - The request handler (likely in
src/app.js, around the mainhttp.createServercallback 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 nameddate,title, andamount;POST /add-expensemust parse bothapplication/x-www-form-urlencodedandapplication/jsonbodies, validate that all three fields are present, write valid JSON data todb/expense.jsononly 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. - 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/htmlfor 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.
No description provided.