import { TestBed } from '@angular/core/testing';
import { OnlineBoardRequestDataResolver } from '@online-board/resolvers/request-data.resolver';
import { OnlineBoardRequestParserService } from '@online-board/services/request/request-parser.service';

describe('OnlineBoardRequestDataResolver', () => {
    let service: OnlineBoardRequestDataResolver;
    const parseMock = jasmine.createSpy('parse');

    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [
                OnlineBoardRequestDataResolver,
                {
                    provide: OnlineBoardRequestParserService,
                    useValue: {
                        parse: parseMock,
                    },
                },
            ],
        });

        service = TestBed.inject(OnlineBoardRequestDataResolver);
        parseMock.calls.reset();
    });

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

    it('should return IOnlineBoardRequestData if there is a request', () => {
        const request = 'request string';
        const parsedRequest = 'parsed request';
        parseMock.withArgs(request).and.returnValue(parsedRequest);

        expect(
            service.resolve({
                queryParams: {
                    request,
                },
            } as any),
        ).toEqual({
            raw: request,
            parsed: parsedRequest,
        } as any);
    });
});
