Unit test failure and credentials

where can i see the environment variables or credentials in the repo i am not good in coding. Can i use my own crtedentials to execute the code? This is for solar-system nodejs and mongodb source code. Its getting failed in testing phase as i am using my own credenetials.

please help

The Github Actions course has it in one of their labs (not sure what course you’re doing). You can also find it discussed in this thread here.

i am doing jenkins pipelines course.

i tred using the below credentials also as per the lab, but still giving authentication issues.
mongodb+srv://supercluster.d83jj.mongodb.net/SuperData
superuser
superpassword

Case is wrong on the password; it’s actually SuperPassword

yeah got it . Thanks. now the application is runing on my local machine, but there is some problem in the application. Whenever i am giving any number within 0-8 it is throwing error.
for my application when i am checking dependency issue it was showing critical for mongoose as well. so i made two changes in the dependency after which the critical went away.
my dependencies:
@babel/traverse”: “^7.23.2”,
“mongoose”: “^6.13.8”,

above 2 dependencies were throign critical issues with versions so i updated.

is it because there is no data in the db? i need to seed the data to the db? Can you clarify? But there are no such seeding steps shown in the lab. when they started the application it was working well and good.

The database has data in it. Most likely there’s still an issue with your credentials. You do need to make sure that Jenkins is configured to put the URL, the username and the password into the environment. Again, case matters for the paramters.

above are the credentials i am using. this i am running directly in server not using jenkins.

You might be using the wrong addtional options. Here’s what I start with:

mongoose.connect(process.env.MONGO_URI, {
    user: process.env.MONGO_USERNAME,
    pass: process.env.MONGO_PASSWORD,
    useNewUrlParser: true,
    useUnifiedTopology: true
}, function(err) {
    if (err) {
        console.log("error!! " + err)
    } else {
      //  console.log("MongoDB Connection Successful")
    }
})

You’ve diverged from that a fair bit, and I’d guess that’s your problem. Why not try:

mongoose.connect("mongodb+srv://supercluster.d83jj.mongodb.net/superData", {
    user: "superuser",
    pass: "SuperPassword",
    useNewUrlParser: true,
    useUnifiedTopology: true
}, function(err) {
    if (err) {
        console.log("error!! " + err)
    } else {
      console.log("MongoDB Connection Successful")
    }
})

and see if that works. Once it works, start “improving” it as you like.

i tried all possible ways including the one u mentioned above. Not at all getting. Let me know one thing do i need to do any mongodb installation in my server or so for this project? Not sure where it is going wrong. If you proper github, can u send me i will clone that and try.

Is therre any specific node versions required?
ubuntu@ip-172-31-17-111:~/solar-system$ nodejs --version
v18.19.1
ubuntu@ip-172-31-17-111:~/solar-system$ npm --version
9.2.0

this is what i have.

It works for me almost without modifications:

  1. git clone https://github.com/sidd-harth/solar-system
  2. cd solar-system
  3. npm install
  4. Now, to make it obvious that we’re running the test, I change the script in package.json for “test” to this: "test": "mocha app-test.js --timeout 10000 --exit". This is to use the default reporter, which is easier to see in the command line.
  5. I source a file to add the credentials to the environment:
       export MONGO_URI="mongodb+srv://supercluster.d83jj.mongodb.net/superData"
       export MONGO_USERNAME=superuser
       export MONGO_PASSWORD=SuperPassword
    
  6. I run npm test and get successful output:
        $ npm test
    
        > Solar [email protected] test
        > mocha app-test.js --timeout 10000  --exit
    
        Server successfully running on port - 3000
    
    
          Planets API Suite
            Fetching Planet Details
        (node:38937) [DEP0170] DeprecationWarning: The URL mongodb://supercluster-shard-00-00.d83jj.mongodb.net:27017,supercluster-shard-00-01.d83jj.mongodb.net:27017,supercluster-shard-00-02.d83jj.mongodb.net:27017/superData?authSource=admin&replicaSet=atlas-11b0vt-shard-0&ssl=true is invalid. Future versions of Node.js will throw an error.
        (Use `node --trace-deprecation ...` to show where the warning was created)
              ✔ it should fetch a planet named Mercury (1013ms)
              ✔ it should fetch a planet named Venus (86ms)
              ✔ it should fetch a planet named Earth (84ms)
              ✔ it should fetch a planet named Mars (88ms)
              ✔ it should fetch a planet named Jupiter (89ms)
              ✔ it should fetch a planet named Satrun (89ms)
              ✔ it should fetch a planet named Uranus (92ms)
              ✔ it should fetch a planet named Neptune (87ms)
    
          Testing Other Endpoints
            it should fetch OS Details
              ✔ it should fetch OS details
            it should fetch Live Status
              ✔ it checks Liveness endpoint
            it should fetch Ready Status
              ✔ it checks Readiness endpoint
    
    
          11 passing (2s)
    

So things work very directly for me. The one thing to check is to make sure you actually have network access to the Atlas database, perhaps by using mongosh

Finally got it. The database name case was the issue. Thanks for your responses and assistance.