import { TestBed } from '@angular/core/testing';
import { ScheduleRequestDataResolver } from '@schedule/resolvers/request-data.resolver';
import { ScheduleRequestParserService } from '@schedule/services/request/request-parser.service';

describe('ScheduleRequestDataResolver', () => {
    let service: ScheduleRequestDataResolver;
    const parseRouteRequestMock = jasmine.createSpy('parseRouteRequest');

    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [
                ScheduleRequestDataResolver,
                {
                    provide: ScheduleRequestParserService,
                    useValue: {
                        parseRouteRequest: parseRouteRequestMock,
                    },
                },
            ],
        });

        service = TestBed.inject(ScheduleRequestDataResolver);
        parseRouteRequestMock.calls.reset();
    });

    it('should return undefined if there is no request query param', () => {
        expect(service.resolve({ queryParams: {} } as any)).toBe(undefined);
    });

    it('should return schedule request data if there is request query param', () => {
        const requestString = 'schedule-route-MOW-MRS-20220520-20220526';
        const outbound = {
            departure: 'MOW',
            arrival: 'MRS',
            dateFrom: new Date(2022, 4, 20),
            dateTo: new Date(2022, 4, 26),
        };
        parseRouteRequestMock.withArgs(requestString).and.returnValue({
            outbound,
        });
        expect(
            service.resolve({
                queryParams: {
                    request: requestString,
                },
            } as any),
        ).toEqual({
            raw: requestString,
            parsed: {
                outbound,
            },
        });
    });
});
