Untitled

 avatar
unknown
plain_text
a year ago
1.9 kB
4
Indexable
it('should return all matches', async () => {
    const req = {
        query: {}
    } as any;
    const res = {
        status: sinon.stub().returnsThis(),
        json: sinon.stub()
    } as unknown as any;

    const matche: any = ['match1', 'match2'];
    const todosOsMatchsStub = sinon.stub(matchesService, 'todosOsMatchs').resolves(matche);

    await controller.pegarTodosMatchesControler(req, res);

    if (res.status.calledWith(status2)) {
        console.log('Status correto');
    } else {
        throw new Error('Status incorreto');
    }

    if (res.json.calledWith(matche)) {
        console.log('respotsa correta');
    } else {
        throw new Error('resposta incorreta');
    }

    if (todosOsMatchsStub.calledOnce) {
        console.log('todosOsMatchsStub foi chamado uma vez');
    } else {
        throw new Error('todosOsMatchsStub nao foi chamado uma vez');
    }

    todosOsMatchsStub.restore();
});



it('Testando o retorno das patidas q nao estao em andamento', async () => {
  const req = {
      query: {
          inProgress: 'false'
      }
  } as any;
  const res = {
      status: sinon.stub().returnsThis(),
      json: sinon.stub()
  } as unknown as any;

  const matche: any = ['matche', 'matche2'];
  const progresoStub = sinon.stub(matchesService, 'pegarProgresso').resolves(matche);

  await controller.pegarProgressoControler(req, res);

  if (res.status.calledWith(status2) && res.json.calledWith(matche)) {
      console.log('O satatus e a resposta JSON estão corretos');
  } else {
      throw new Error('O satatus e a resposta JSON estão incorretos');
  }

  if (progresoStub.calledOnceWith(false)) {
      console.log('Progreso foi chamado uma vez com false');
  } else {
      throw new Error('Progreso nao foi chamado uma vez com false');
  }

  progresoStub.restore();
});
Editor is loading...
Leave a Comment