import { RouteType } from '@typings/enums';
import { getFlightFirstLeg } from '@utils/flight/legs/first-leg';
import { IWithLeg } from '@utils/flight/legs/types';

describe('getFlightFirstLeg', () => {
    const direct: IWithLeg = {
        routeType: RouteType.DIRECT,
        leg: {
            index: 0,
        } as any,
    };

    const multiLeg: IWithLeg = {
        routeType: RouteType.MULTI_LEG,
        legs: [
            {
                index: 0,
            },
            {
                index: 1,
            },
        ] as any,
    };

    const connecting1: IWithLeg = {
        routeType: RouteType.CONNECTING,
        flights: [direct, multiLeg] as any,
    };

    const connecting2: IWithLeg = {
        routeType: RouteType.CONNECTING,
        flights: [multiLeg, direct] as any,
    };

    it('should extract first leg from direct flight', () => {
        expect(getFlightFirstLeg(direct)).toBe(direct.leg);
    });

    it('should extract first leg from multi leg flight', () => {
        expect(getFlightFirstLeg(multiLeg)).toBe(multiLeg.legs[0]);
    });

    it('should extract first leg from connecting flight with first direct flight', () => {
        expect(getFlightFirstLeg(connecting1)).toBe(direct.leg);
    });

    it('should extract first leg from connecting flight with first multi leg flight', () => {
        expect(getFlightFirstLeg(connecting2)).toBe(multiLeg.legs[0]);
    });
});
