package de.thpeetz.kontor.comics.repository;

import static org.junit.jupiter.api.Assertions.*;

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 StoryArcRepositoryTest {

    @Autowired
    private StoryArcRepository storyArcRepository;

    @Autowired
    private ComicService comicService;

    @Test
    void testSearch() {
        List<StoryArc> storyArcs = storyArcRepository.search("Learn");
        assertNotNull(storyArcs);
        assertEquals(1, storyArcs.size());
    }

    @Test
    void findByComic() {
        Comic comic = TestConstants.getComicWithStoryArcs(comicService);
        List<StoryArc> storyArcs = storyArcRepository.findByComic(comic);
        assertNotNull(storyArcs);
        assertEquals(3, storyArcs.size());
    }

    @Test
    void findByNameAndComic() {
        Comic comic = TestConstants.getComicWithStoryArcs(comicService);
        StoryArc storyArc = storyArcRepository.findByNameAndComic("Higher Learning", comic);
        assertNotNull(storyArc);
        assertEquals("Emma Frost", storyArc.getComic().getTitle());
    }
}
