Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda