import { TestBed } from '@angular/core/testing';
import { OnlineBoardRequestParserService } from '@online-board/services/request/request-parser.service';
import { OnlineBoardUrlParserService } from '@online-board/services/url/url-parser.service';

describe('OnlineBoardRequestParserService', () => {
    let service: OnlineBoardRequestParserService;

    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [
                OnlineBoardRequestParserService,
                OnlineBoardUrlParserService,
            ],
        });

        service = TestBed.inject(OnlineBoardRequestParserService);
    });

    it('should parse arrival request without time range', () => {
        const request = 'onlineboard-arrival-SVO-20220305';
        expect(service.parse(request)).toEqual({
            type: 'route',
            params: {
                arrival: 'SVO',
                date: new Date(2022, 2, 5),
                timeFrom: undefined,
                timeTo: undefined,
            },
        });
    });

    it('should parse arrival request with time range', () => {
        const request = 'onlineboard-arrival-SVO-20220305-06002200';
        expect(service.parse(request)).toEqual({
            type: 'route',
            params: {
                arrival: 'SVO',
                date: new Date(2022, 2, 5),
                timeFrom: '0600',
                timeTo: '2200',
            },
        });
    });

    it('should parse departure request without time range', () => {
        const request = 'onlineboard-departure-SVO-20220305';
        expect(service.parse(request)).toEqual({
            type: 'route',
            params: {
                departure: 'SVO',
                date: new Date(2022, 2, 5),
                timeFrom: undefined,
                timeTo: undefined,
            },
        });
    });

    it('should parse departure request with time range', () => {
        const request = 'onlineboard-departure-SVO-20220305-06002200';
        expect(service.parse(request)).toEqual({
            type: 'route',
            params: {
                departure: 'SVO',
                date: new Date(2022, 2, 5),
                timeFrom: '0600',
                timeTo: '2200',
            },
        });
    });

    it('should parse route request without time range', () => {
        const request = 'onlineboard-route-MOW-LED-20220305';
        expect(service.parse(request)).toEqual({
            type: 'route',
            params: {
                departure: 'MOW',
                arrival: 'LED',
                date: new Date(2022, 2, 5),
                timeFrom: undefined,
                timeTo: undefined,
            },
        });
    });

    it('should parse route request with time range', () => {
        const request = 'onlineboard-route-MOW-LED-20220305-06002200';
        expect(service.parse(request)).toEqual({
            type: 'route',
            params: {
                departure: 'MOW',
                arrival: 'LED',
                date: new Date(2022, 2, 5),
                timeFrom: '0600',
                timeTo: '2200',
            },
        });
    });

    it('should parse flight number request', () => {
        const request = 'onlineboard-flight-SU1210-20220305';
        expect(service.parse(request)).toEqual({
            type: 'flight-number',
            params: {
                flightNumber: '1210',
                carrier: 'SU',
                date: new Date(2022, 2, 5),
            },
        });
    });
});
