import { FlightStatusLogic } from './flight-status.logic';
import { RouteTypeLegacy } from '../../../shared/enumerators';
import * as moment from 'moment';
import { AppSettings } from '../../../shared/models-legacy';

describe('FlightStatusLogic', () => {
    let logic: FlightStatusLogic;
    const settings: AppSettings = {
        flightStatusAvailableFrom: 24,
    } as any;
    beforeEach(() => {
        logic = new FlightStatusLogic(settings);
    });

    it('should be not available for empty', () => {
        expect(logic.available(null as any)).toBeFalse();
    });

    it('should be not available for far future', () => {
        expect(
            logic.available({
                operatingBy: {
                    scheduled: 'SU',
                },
                routeType: RouteTypeLegacy.Direct,
                dateToSearchBy: moment().add(5, 'day').toDate(),
                leg: {
                    departure: {
                        times: {
                            scheduled: {
                                utc: moment().add(5, 'day').toDate(),
                            },
                        },
                    },
                },
            } as any),
        ).toBeFalse();
    });

    it('should be available for less than 1 day', () => {
        expect(
            logic.available({
                operatingBy: {
                    scheduled: 'SU',
                },
                routeType: RouteTypeLegacy.Direct,
                dateToSearchBy: moment().add(1, 'minute').toDate(),
                leg: {
                    departure: {
                        times: {
                            scheduled: {
                                utc: moment().add(1, 'minute').toDate(),
                            },
                        },
                    },
                },
            } as any),
        ).toBeTrue();
    });

    it('should not be available for not SU', () => {
        expect(
            logic.available({
                operatingBy: {
                    scheduled: 'AF',
                },
                routeType: RouteTypeLegacy.Direct,
                dateToSearchBy: moment().add(1, 'minute').toDate(),
                leg: {
                    departure: {
                        times: {
                            scheduled: {
                                utc: moment().add(1, 'minute').toDate(),
                            },
                        },
                    },
                },
            } as any),
        ).toBeFalse();
    });

    ['SU', 'HZ', 'FV', 'DP'].forEach((airline) => {
        it(`should be available for not ${airline}`, () => {
            expect(
                logic.available({
                    operatingBy: {
                        scheduled: airline,
                    },
                    routeType: RouteTypeLegacy.Direct,
                    dateToSearchBy: moment().add(1, 'minute').toDate(),
                    leg: {
                        departure: {
                            times: {
                                scheduled: {
                                    utc: moment().add(1, 'minute').toDate(),
                                },
                            },
                        },
                    },
                } as any),
            ).toBeTrue();
        });
    });
});
