package de.thpeetz.kontor.tysc.repository;

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

import java.util.List;

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

import de.thpeetz.kontor.tysc.TestConstants;

@SpringBootTest
class SportRepositoryTest {

    @Autowired
    private SportRepository sportRepository;

    @Test
    void testFindByName() {
        Sport sport = sportRepository.findByName(TestConstants.FOOTBALL_NAME);
        assertNotNull(sport);
        assertEquals(TestConstants.FOOTBALL_TEAM_COUNT, sport.getTeams().size());
        assertEquals(TestConstants.FOOTBALL_POSITION_COUNT, sport.getPositions().size());
    }

    @Test
    void testFindByNameIgnoreCase() {
        List<Sport> sports = sportRepository.findByNameIgnoreCase(TestConstants.FOOTBALL_NAME.toLowerCase());
        assertNotNull(sports);
        assertEquals(TestConstants.FOOTBALL_TEAM_COUNT, sports.get(0).getTeams().size());
    }

    @Test
    void testSearch() {
        List<Sport> sports = sportRepository.search("ball");
        assertEquals(3, sports.size());
    }
}
