package com.writeoff;

import com.writeoff.common.exception.BusinessException;
import com.writeoff.module.scheduler.repository.InMemoryAsyncJobRepository;
import com.writeoff.module.scheduler.service.AsyncJobService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class AsyncJobServiceTest {

    @Test
    void shouldEnforceIdempotency() {
        AsyncJobService asyncJobService = new AsyncJobService(new InMemoryAsyncJobRepository());
        asyncJobService.enqueue("AUDIT_REMIND", "meetingId=1", "idem-job-1");
        Assertions.assertThrows(BusinessException.class, () ->
                asyncJobService.enqueue("AUDIT_REMIND", "meetingId=1", "idem-job-1"));
    }
}
