package de.thpeetz.kontor.comics.repository;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.List;

import de.thpeetz.kontor.comics.data.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import de.thpeetz.kontor.comics.TestConstants;
import de.thpeetz.kontor.comics.services.ComicService;

@SpringBootTest
class IssueRepositoryTest {

    @Autowired
    private IssueRepository issueRepository;

    @Autowired
    private ComicService comicService;

    @Test
    void testFindByComic() {
        Comic comic = TestConstants.getComicWithIssues(comicService);
        List<Issue> issues = issueRepository.findByComic(comic);
        assertEquals(TestConstants.BATTLE_POPE_ISSUE_COUNT, issues.size());
    }

    @Test
    void testFindByComicAndIssueNumber() {
        Comic comic = TestConstants.getComicWithIssues(comicService);
        Issue issue = issueRepository.findByComicAndIssueNumber(comic, "12");
        assertNotNull(issue);
        assertFalse(issue.getIsRead());
    }

    @Test
    void testSearch() {
        List<Issue> issues = issueRepository.search("2");
        assertEquals(187, issues.size());
    }
}
