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

describe('getFlightArrivalCityCode', () => {
    const scheduledArrival1 = {
        scheduled: {
            cityCode: 'MOW',
        },
    };
    const latestArrival1 = {
        scheduled: {
            cityCode: 'MOW',
        },
        latest: {
            cityCode: 'LED',
        },
    };
    const scheduledArrival2 = {
        scheduled: {
            cityCode: 'KUF',
        },
    };
    const latestArrival2 = {
        scheduled: {
            cityCode: 'KUF',
        },
        latest: {
            cityCode: 'KZN',
        },
    };

    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(getFlightArrivalCityCode(directScheduled)).toBe('MOW');
    });

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

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

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

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

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

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

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