-
Notifications
You must be signed in to change notification settings - Fork 10
Alaa nasher w2 node.js #15
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: main
Are you sure you want to change the base?
Alaa nasher w2 node.js #15
Conversation
Removed specific source directories and added keys.js to .gitignore.
RHSebregts
left a comment
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.
Hi Alaa,
Great work here! I left some remarks, but based on what I'm seeing here it seems like you have a good grasp on the basics of API's. Your test suite is also very good! There are some small changes you could make, to polish it even more.
Happy coding!
| app.post("/weather", async (req, res) => { | ||
| const { cityName } = req.body; | ||
| if (!cityName || cityName.trim() === "") { | ||
| return res.status(400).json({ msg: "City name is required." }); |
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.
nice guard clause!
| try { | ||
| const response = await fetch(url); | ||
| if (!response.ok) { | ||
| return res.status(400).json({ weatherText: "City is not found!" }); |
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.
Since we're already in a try-catch we could also throw here.
| }); | ||
|
|
||
| describe("Test POST /weather", () => { | ||
| test("Return city name is required.", async () => { |
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.
I really like how this test is using the AAA principle. This makes it very readable, great!
| const res = await request.post("/weather").send({ cityName: city }); | ||
|
|
||
| expect(res.statusCode).toBe(200); | ||
| expect(res.body.main.temp).toBe(286.78); |
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.
We could also test for the city name here, to make sure we get all the correct data.
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.
This is a good test suite, well done! One small thing you could change is the order and grouping of the tests. You can put multiple tests into one describe block, which makes it easier to see which tests belong together, and cleans up your test logs a bit. It's also good to pick an order for tests, group them by end point and then either start with the happy path test and then error cases, or the other way around.
No description provided.