Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
mocha/chai testing hangs on await tojson().fromFile, postman passes

So, basically I am developing my first MERN stack project in which I have an api endpoint which resets the collection vehicles. I delete the data from the collection, then I parse the data from a csv and convert them to json and insert the new data. When running my backend code, everything runs smoothly in postman and robo3T. But when I run my testing code, the execution hangs at the instruction:
const vehicles_model = await tojson().fromFile(vehicles_csv);
and consequently the testing fails (res.status 500 is returned). Also, while running the testing code, the endpoint fails to run in postman, as well. What am I doing wrong?
PS: It is my first time writing on stackoverflow, if I haven't made the problem clear, I'll be happy to elaborate :)

this is my endpoint

exports.postResetVehicles = async (req, res) => {
   const vehicles_csv = "vehicles.csv";
   try {
       Vehicles.deleteMany({}).then(function () {
          console.log("Data deleted and");
       });

       const vehicles_model = await tojson().fromFile(vehicles_csv);

       Vehicles.insertMany(vehicles_model).then(function () {
           console.log("data inserted"); // Success
           console.log("=>Data reseted");
       }).catch(function (error) {
           console.log(error); // Failure
       });
       return res.status(200).json({ "status": "OK" });
   } catch (err) {
       return res.status(500).json({ "status": "failed", "error": err });
   }
};

and this is my testing code

describe("Testing 'admin/resetvehicles'", () => {
    it("should succeed if Vehicles collection is reset", async () => {
        const response = await request(app).post(
            "/interoperability/api/admin/resetvehicles"
        );
        expect(response.status).to.equal(200)
    });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!