import { Request, Response, NextFunction } from 'express';
import 'jest-extended'
import { authenticate } from '../../src/middlewares/authenticate';

describe('vérifie l\'authentification', () => {

    it('aucun cookie dans la request', async() =>{
        let counter = 0;
        function next() {
            counter++;
        }
        await authenticate(
            {} as Request,
            {} as Response,
            next as NextFunction)
        
        await expect(counter).toBe(0);
    });

    it('authenticate est valide', async() => {
        let counter = 0;
        function next() {
            counter++;
        }
        await authenticate(
            {
                cookies: {
                    uToken: '12345'
                }
            } as Request,
            {} as Response,
            next as NextFunction)

        await expect(counter).toBe(1);
    });

    it('authenticate utilisateur non valide dans le backend', async() =>{
        //TODO
    });
    
});

