package de.thpeetz.kontor.comics.repository;

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

import java.util.List;
import java.util.stream.Collectors;

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;

@SpringBootTest
class WorktypeRepositoryTest {

    @Autowired
    private WorktypeRepository worktypeRepository;

    @Test
    void findWorktypeByName() {
        Worktype found = worktypeRepository.findByName("Writer");
        assertNotNull(found);
        Worktype notFound = worktypeRepository.findByName("er");
        assertNull(notFound);
    }

    @Test
    void findWorktypeByNameIgnoreCase() {
        List<Worktype> worktypes = worktypeRepository.findByNameIgnoreCase("Writer".toLowerCase());
        assertNotNull(worktypes);
        assertEquals(1, worktypes.size());
        assertEquals("Writer", worktypes.get(0).getName());
    }

    @Test
    void searchWorktype() {
        List<Worktype> worktypes = worktypeRepository.search("er");
        assertEquals(3, worktypes.size());
        assertTrue(worktypes.stream().map(worktype -> worktype.getName()).collect(Collectors.toList()).contains("Writer"));
    }
}
