import { RouteType } from '@typings/enums';
import { getFlightDepartureCity } from '@utils/flight/departure/city';
import { IWithLeg } from '@utils/flight/legs/types';

describe('getFlightDepartureCity', () => {
    const scheduledDeparture1 = {
        scheduled: {
            city: 'Moscow',
        },
    };
    const latestDeparture1 = {
        scheduled: {
            city: 'Moscow',
        },
        latest: {
            city: 'London',
        },
    };
    const scheduledDeparture2 = {
        scheduled: {
            city: 'Samara',
        },
    };
    const latestDeparture2 = {
        scheduled: {
            city: 'Samara',
        },
        latest: {
            city: 'Kazan',
        },
    };

    const directScheduled: IWithLeg = {
        routeType: RouteType.DIRECT,
        leg: {
            departure: scheduledDeparture1,
        } as any,
    };
    const directLatest: IWithLeg = {
        routeType: RouteType.DIRECT,
        leg: {
            departure: latestDeparture1,
        } as any,
    };
    const multiLegScheduled: IWithLeg = {
        routeType: RouteType.MULTI_LEG,
        legs: [
            {
                departure: scheduledDeparture2,
            },
            {
                departure: scheduledDeparture1,
            },
        ] as any,
    };
    const multiLegLatest: IWithLeg = {
        routeType: RouteType.MULTI_LEG,
        legs: [
            {
                departure: latestDeparture2,
            },
            {
                departure: latestDeparture1,
            },
        ] as any,
    };
    const connectingScheduled1: IWithLeg = {
        routeType: RouteType.CONNECTING,
        flights: [directScheduled, multiLegScheduled] as any,
    };
    const connectingLatest1: IWithLeg = {
        routeType: RouteType.CONNECTING,
        flights: [directLatest, multiLegLatest] as any,
    };
    const connectingScheduled2: IWithLeg = {
        routeType: RouteType.CONNECTING,
        flights: [multiLegScheduled, directScheduled] as any,
    };
    const connectingLatest2: IWithLeg = {
        routeType: RouteType.CONNECTING,
        flights: [multiLegLatest, directLatest] as any,
    };

    it('should extract city from direct flight without latest info', () => {
        expect(getFlightDepartureCity(directScheduled)).toBe('Moscow');
    });

    it('should extract city from direct flight with latest info', () => {
        expect(getFlightDepartureCity(directLatest)).toBe('London');
    });

    it('should extract city from multi leg flight without latest info', () => {
        expect(getFlightDepartureCity(multiLegScheduled)).toBe('Samara');
    });

    it('should extract city from multi leg flight with latest info', () => {
        expect(getFlightDepartureCity(multiLegLatest)).toBe('Kazan');
    });

    it('should extract city from connecting flight with first direct flight without latest info', () => {
        expect(getFlightDepartureCity(connectingScheduled1)).toBe('Moscow');
    });

    it('should extract city from connecting flight with first direct flight with latest info', () => {
        expect(getFlightDepartureCity(connectingLatest1)).toBe('London');
    });

    it('should extract city from connecting flight with first multi leg flight without latest info', () => {
        expect(getFlightDepartureCity(connectingScheduled2)).toBe('Samara');
    });

    it('should extract city from connecting flight with first multi leg flight with latest info', () => {
        expect(getFlightDepartureCity(connectingLatest2)).toBe('Kazan');
    });
});
