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

describe('getFlightDepartureCityCode', () => {
    const scheduledDeparture1 = {
        scheduled: {
            cityCode: 'MOW',
        },
    };
    const latestDeparture1 = {
        scheduled: {
            cityCode: 'MOW',
        },
        latest: {
            cityCode: 'LED',
        },
    };
    const scheduledDeparture2 = {
        scheduled: {
            cityCode: 'KUF',
        },
    };
    const latestDeparture2 = {
        scheduled: {
            cityCode: 'KUF',
        },
        latest: {
            cityCode: 'KZN',
        },
    };

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

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

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

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

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

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

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

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