Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda