Last active
June 25, 2025 17:02
-
-
Save up1/da26567d80db1de23f101c9e2f0d63bc to your computer and use it in GitHub Desktop.
Gemini-cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now that all the files are created, I will run the tests to verify the implementation. | |
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ | |
│ ⊷ Shell npx jest (Run tests with jest.) │ | |
│ │ | |
│ ... first 5 lines hidden ... │ | |
│ PASS routes/userRoutes.test.js │ | |
│ GET /users/:id │ | |
│ ✓ should return user details for a valid ID (19 ms) │ | |
│ ✓ should return 404 for a non-existent user ID (4 ms) │ | |
│ ✓ should return 500 for user ID 3 (1 ms) │ | |
│ │ | |
│ Test Suites: 1 passed, 1 total │ | |
│ Tests: 3 passed, 3 total │ | |
│ Snapshots: 0 total │ | |
│ Time: 0.236 s │ | |
│ Ran all test suites. │ | |
│ Jest did not exit one second after the test run has completed. │ | |
│ │ | |
│ 'This usually means that there are asynchronous operations that weren't stopped in your tests. │ | |
│ Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. │ | |
│ │ | |
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ทำการสร้าง REST API ด้วย nodejs 23 | |
ใช้ library ต่าง ๆ ดังนี้ | |
1. express library สำหรับพัฒน web app | |
2. ใช้งาน jest, supertest สำหรับการทดสอบ REST API | |
Project structure ของ REST API ด้วย NodeJS | |
* Controller | |
* Error handling | |
Specification ของ REST APIs เป็นดังนี้ | |
1. Get user detail by id | |
GET /users/:id | |
GET /users/1 | |
response code = 200 | |
{ | |
"id": 1, | |
"name", "user 01", | |
"email": "[email protected]" | |
} | |
GET /users/2 | |
response code = 404 | |
{ | |
"message": "User id=2 not found in system" | |
} | |
GET /users/3 | |
response code = 500 | |
{ | |
"message": "System error" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment