import { Leg, OperatorModel } from '../models-legacy';
import { CodesharingPipe } from './codesharing.pipe';

describe('CodesharingPipe', () => {
    let pipe: CodesharingPipe;

    beforeEach(() => {
        pipe = new CodesharingPipe();
    });

    it('should return proper codeshare operators with correct formatting', () => {
        const testCases = [
            {
                legs: undefined,
                expected: '',
            },
            {
                legs: null,
                expected: '',
            },
            {
                legs: [{ departure: {} } as Leg, { arrival: {} } as Leg] as Leg[],
                expected: '',
            },
            {
                legs: [{ departure: {}, operatingBy: {} } as Leg, { arrival: {} } as Leg] as Leg[],
                expected: '',
            },
            {
                legs: [
                    { operatingBy: { operators: [{ carrier: 'AM', flightNumber: '1234' }] as OperatorModel[] } } as Leg,
                    { arrival: {} } as Leg,
                ] as Leg[],
                expected: 'AM 1234',
            },
            {
                legs: [
                    {
                        operatingBy: {
                            operators: [
                                { carrier: 'AM', flightNumber: '1234' },
                                { carrier: 'FV', flightNumber: '5678' },
                            ] as OperatorModel[],
                        },
                    } as Leg,
                    { arrival: {} } as Leg,
                ] as Leg[],
                expected: 'AM 1234, FV 5678',
            },
            {
                legs: [
                    {
                        operatingBy: {
                            operators: [
                                { carrier: 'AM', flightNumber: '1234' },
                                { carrier: 'FV', flightNumber: '5678' },
                            ] as OperatorModel[],
                        },
                    } as Leg,
                    { operatingBy: { operators: [{ carrier: 'NV', flightNumber: '3456' }] as OperatorModel[] } } as Leg,
                ] as Leg[],
                expected: 'AM 1234, FV 5678, NV 3456',
            },
        ];

        testCases.forEach((testCase) => {
            expect(pipe.transform(testCase.legs)).toEqual(testCase.expected);
        });
    });
});
