import { RouteType } from '@typings/enums';
import {
    compareFlightsByPId,
    getFlightPId,
    IWithFlightPId,
} from '@utils/flight/p-id';

const direct: IWithFlightPId = {
    routeType: RouteType.DIRECT,
    pId: '1',
};
const multiLeg: IWithFlightPId = {
    routeType: RouteType.MULTI_LEG,
    pId: '2',
};
const connecting1: IWithFlightPId = {
    routeType: RouteType.CONNECTING,
    flights: [direct, multiLeg] as any,
};
const connecting2: IWithFlightPId = {
    routeType: RouteType.CONNECTING,
    flights: [multiLeg, direct] as any,
};

describe('getFlightPId', () => {
    it('should extract flight pId from direct flight', () => {
        expect(getFlightPId(direct)).toBe('1');
    });

    it('should extract flight pId from multi leg flight', () => {
        expect(getFlightPId(multiLeg)).toBe('2');
    });

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

    it('should extract flight pId from connecting flight with first multi leg flight', () => {
        expect(getFlightPId(connecting2)).toBe('21');
    });
});

describe('compareFlightsByPId', () => {
    it('should extract flights pId', () => {
        expect(compareFlightsByPId(direct, multiLeg)).toBe(false);
        expect(compareFlightsByPId(direct, direct)).toBe(true);
        expect(compareFlightsByPId(direct, connecting1)).toBe(false);
        expect(compareFlightsByPId(connecting1, connecting1)).toBe(true);
        expect(compareFlightsByPId(connecting1, connecting2)).toBe(false);
    });
});
