import navigator from '../../libs/navigator';
import { Request, Response, NextFunction } from 'express';

const res = { redirect: jest.fn() } as unknown as Response;
const req = {
    originalUrl: ''
} as unknown as Request
const next = jest.fn() as NextFunction;

beforeEach(() => {
    jest.clearAllMocks();
});


describe('Navigator tests', () => {
    test('postcode page proceeds to address selection', () => {
        
        req.originalUrl = '/postcode';

        navigator(req, res, next);

        expect(res.redirect).toHaveBeenCalledWith('/address-select');
    });

    test('empty page param redirects to root', () => {

        req.originalUrl = '';

        navigator(req, res, next);

        expect(res.redirect).toHaveBeenCalledWith('/');

    });
});