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

describe('getFlightLastLeg', () => {
    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 last leg from direct flight', () => {
        expect(getFlightLastLeg(direct)).toBe(direct.leg);
    });

    it('should extract last leg from multi leg flight', () => {
        expect(getFlightLastLeg(multiLeg)).toBe(multiLeg.legs[1]);
    });

    it('should extract last leg from connecting flight with second multi leg flight', () => {
        expect(getFlightLastLeg(connecting1)).toBe(multiLeg.legs[1]);
    });

    it('should extract last leg from connecting flight with second direct flight', () => {
        expect(getFlightLastLeg(connecting2)).toBe(direct.leg);
    });
});
