Skip to content

Rizan node.js w2 #18

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rizan-ibrahim
Copy link

No description provided.

@eidosam eidosam self-assigned this Feb 26, 2025
@eidosam eidosam added To review Week 2 Week 2 assignment labels Feb 26, 2025

Choose a reason for hiding this comment

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

This has a few issues.

  1. Missing await on request.post("/weather")

  2. The test is calling request.post("/weather") but does not await it. It should be await request(app).post("/weather").
    Incorrect weatherText check in 404 case

  3. Your test expects response.body.weatherText to be "city is not found!", but if your server returns { message: "city is not found!" }, then response.body.weatherText will be undefined. Make sure your test matches the actual response structure.

  4. Hardcoded weather response format

The test expects "The temperature in Amsterdam is" but weather responses can vary. If your API returns structured JSON with temperature and description, test for that instead of checking a sentence.

Choose a reason for hiding this comment

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

If keys.API_KEY is undefined, your API request will fail silently.
You should return a 500 error if the key is missing.

Choose a reason for hiding this comment

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

exposing an API key in your source code is a security risk.

Anyone can steal and misuse it.

The best practice is to hide the API key.

npm install dotenv

Move API key to a .env file (create this in your project root):

and write in it:

API_KEY=afc0f7157bda937505e237c68802afa5

then you can import the dotenv to securely import that api key. Something like this below.

import dotenv from 'dotenv';
dotenv.config();

export const keys = {
API_KEY: process.env.API_KEY
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
To review Week 2 Week 2 assignment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants