import { TestBed } from '@angular/core/testing';
import { OnlineBoardDateValidationService } from '@online-board/services/date-validation.service';
import { AppSettingsService } from '@shared/services';

describe('OnlineBoardDateValidationService', () => {
    let service: OnlineBoardDateValidationService;
    const boardMinDate = new Date(2022, 4, 23);
    const boardMaxDate = new Date(2022, 4, 29);

    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [
                OnlineBoardDateValidationService,
                {
                    provide: AppSettingsService,
                    useValue: {
                        getSettings: () => {
                            return Promise.resolve({
                                boardMinDate,
                                boardMaxDate,
                            });
                        },
                    },
                },
            ],
        });

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

    it('should validate dates', async () => {
        const validDates = [
            new Date(2022, 4, 23),
            new Date(2022, 4, 25),
            new Date(2022, 4, 29),
        ];
        const invalidDates = [new Date(2022, 4, 21), new Date(2022, 4, 30)];

        const truthyResult = await Promise.all(
            validDates.map((date) => service.isDateValid(date)),
        );
        const falsyResult = await Promise.all(
            invalidDates.map((date) => service.isDateValid(date)),
        );

        expect(truthyResult.every(Boolean)).toBe(true);
        expect(falsyResult.every((res) => !res)).toBe(true);
    });
});
