import supertest from 'supertest';
import 'jest-extended';
import app from '../../src/app';

const request = supertest(app);

const testNom1 = 'Jean-Marc';

describe('baseRoute', () => {

  it('devrait avoir un contenu HTML', async () => {
    const response = await request.get('/');
    expect(response.status).toBe(200);
    expect(response.type).toBe("text/html");
  });

});

describe('/stats', () => {

  it('devrait avoir un contenu HTML', async () => {
    const response = await request.get('/stats');
    await expect(response.status).toBe(200);
    await expect(response.type).toBe("text/html");
  });

});

describe('/login (déjà connecté)',() => {

  it('devrait avoir un contenu HTML', async () => {
    const response = await request.get('/login');
    await expect(response.status).toBe(302);
    await expect(response.text).toBe("Found. Redirecting to /");
  });

});

describe('/logout', () => {

  it('devrait avoir un contenu HTML', async () => {
    const response = await request.get('/logout');
    await expect(response.status).toBe(302);
    await expect(response.text).toBe("Found. Redirecting to /");
  });

});

describe('/login (déconnecté)', () => {

  it('devrait avoir un contenu HTML', async () => {
    const response = await request.get('/login');
    await expect(response.status).toBe(200);
    await expect(response.type).toBe("text/html");
  });

});

describe('GET /bo/gu/s/URL/', () => {
  it(`devrait répondre avec une mauvaise demande lorsque l'URL est mauvais`, async () => {
    const response = await request.get('/bo/gu/s/URL/' + testNom1);
    await expect(response.status).toBe(404);
  });
});
