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

describe('getFlightArrivalCity', () => {
    const scheduledArrival1 = {
        scheduled: {
            city: 'Moscow',
        },
    };
    const latestArrival1 = {
        scheduled: {
            city: 'Moscow',
        },
        latest: {
            city: 'London',
        },
    };
    const scheduledArrival2 = {
        scheduled: {
            city: 'Samara',
        },
    };
    const latestArrival2 = {
        scheduled: {
            city: 'Samara',
        },
        latest: {
            city: 'Kazan',
        },
    };

    const directScheduled: IWithLeg = {
        routeType: RouteType.DIRECT,
        leg: {
            arrival: scheduledArrival1,
        } as any,
    };
    const directLatest: IWithLeg = {
        routeType: RouteType.DIRECT,
        leg: {
            arrival: latestArrival1,
        } as any,
    };
    const multiLegScheduled: IWithLeg = {
        routeType: RouteType.MULTI_LEG,
        legs: [
            {
                arrival: scheduledArrival1,
            },
            {
                arrival: scheduledArrival2,
            },
        ] as any,
    };
    const multiLegLatest: IWithLeg = {
        routeType: RouteType.MULTI_LEG,
        legs: [
            {
                arrival: latestArrival1,
            },
            {
                arrival: latestArrival2,
            },
        ] 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(getFlightArrivalCity(directScheduled)).toBe('Moscow');
    });

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

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

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

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

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

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

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