Information Security Projects - Stock Price Checker

Tell us what’s happening:
Hello! I’m having an issue passing this test. Here is the situation:

  • The project passes all inbuilt tests locally, and can access all stock information.
  • The project, when uploaded to replit.com, when running passes all inbuilt tests and can access stock information.
  • Then this Replit link is pasted into the FCC test, and is in NODE_ENV=test, then no FCC challenges pass and the inbuilt tests timeout.
  • When NODE_ENV is anything but test, then all FCC challenges pass EXCEPT the last one, “All 5 functional tests are complete and passing.”, due to disabling the testing.

I have tried adding longer timeout values to server.js like so:

const listener = app.listen(process.env.PORT || 3000, function () {
  console.log('Your app is listening on port ' + listener.address().port);
  if (process.env.NODE_ENV === 'test') {
    console.log('Running Tests...');
    setTimeout(function () {
      try {
        runner.run();
      } catch (e) {
        console.log('Tests are not valid:');
        console.error(e);
      }
    }, 9500); // Increased from 3000
  }
});

And also within each test, like so:

test("Viewing one stock: GET request to /api/stock-prices", function (done) {
      chai
        .request(server)
        .get("/api/stock-prices/")
        .set("content-type", "application/json")
        .query({ stock: "GOOG" })
        .end(function (err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.body.stockData.stock, "GOOG");
          assert.exists(res.body.stockData.price, "GOOG has a price");
          done();
        });
    }).timeout(5000);

If anyone can help me with this I would really appreciate it.

Nick

Your project link(s)

solution: https://replit.com/@newsworthy/stockchecker-1

githubLink: GitHub - Newsworthy/StockChecker

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36

Challenge: Information Security Projects - Stock Price Checker

Link to the challenge:

1 Like

I just got same problem bro…

1 Like

+1

Anybody could figure it out? Everything works for me except the last test - I tried to check the web requests, and the get-test ( User

curl “https://boilerplate-project-stockchecker-1.egorm2.repl.co/_api/get-tests” -H “User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0” -H “Accept: /” -H “Accept-Language: en-US,en;q=0.5” -H “Accept-Encoding: gzip, deflate, br” -H “Referer: https://www.freecodecamp.org/” -H “Origin: https://www.freecodecamp.org” -H “Connection: keep-alive” -H “Sec-Fetch-Dest: empty” -H “Sec-Fetch-Mode: cors” -H “Sec-Fetch-Site: cross-site” -H “If-None-Match: W/”“18-LBCk8AUyxWRHlNU0M3rkMOn1Li8"”" -H “TE: trailers”)

returns this status:

{“status”:“unavailable”} if I try to run it from terminal… Could it be an issue with the FCC site?

I had the same problem so I revisited the lessons and found the answer. You have to add “.keepOpen()” after chai.request(server) this will keep the server open for fcc testing otherwise server gets closed after the test completion.Here’s an example for this:-

chai
      .request(server)
      .keepOpen()
      .get("/api/stock-prices/")
      .query({ stock: "TSLA", like: true })
      .end((err, res) => {
        assert.equal(res.status, 200);
        assert.equal(res.body.stockData.stock, "TSLA");
        assert.equal(res.body.stockData.likes, 1);
        assert.exists(res.body.stockData.price, "tsla price exists");
        done();
      })

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.