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

198
Views
mocha test passed but it's not waiting for the test to fulfil the if else condition

I am trying to create a database using the first API call and the second API is getting the status of the created database. Can anyone tell why it is not waiting for the status to be passed and marking the test cases to be passed in execution?

'Verify that new database created successfully': async function () {
    //const dataStartServer = syncSuite.loginInf.endpoint;
    const request = supertest(syncSuite.list.API_URL);
    const random = Math.floor(Math.random() * 30) + 1;
    const data = {
        'notifyMe': false
    };
    const res = await request
        .post(`${pathapi.create_server}DatabaseJ Server${random}`)
        .set('Cookie', syncSuite.list.Token, 'Host', syncSuite.list.API_URL,
            'Content-Type', 'application/x-www-form-urlencoded')
        .send(data);
    // .expect(200);
    //console.log('Status of server----------------------------', res.body)

    let uuid = res.body.uuid;
    //let createdServer = res.body.name

    let attemptsLeft = 30;
    const expectedValue = 'passed';
    const delayBetweenRequest = 60000;
    async function check() {
        const status_res = await request
            .get(`${pathapi.status_path}${uuid}`)
            .set('Cookie', syncSuite.list.Token, 'Host', syncSuite.list.API_URL,
                'Content-Type', 'application/x-www-form-urlencoded')
            .send()
        // .expect(200);
        console.log('log---------------------------', status_res.body.status)
        if (status_res.body.status === expectedValue) {
            expect(status_res.body.status).to.be.eq(expectedValue)
        } else {
            attemptsLeft -= 1;
            console.log('Status of server----------------------------', status_res.body, attemptsLeft)
            if (!attemptsLeft) {
                expect(false)
            }
            else {
                setTimeout(check, delayBetweenRequest);
            }
        }
    }`enter code here`
    check();
},
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!