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.Card;
import de.thpeetz.kontor.tysc.data.CardSet;
import de.thpeetz.kontor.tysc.data.Rooster;
import de.thpeetz.kontor.tysc.data.Vendor;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class CardRepositoryTest {

    @Autowired
    private CardRepository cardRepository;

    @Test
    void testSearchByFields() {
        List<Card> cards = cardRepository.findAll();
        Card existingCard = cards.get(3);
        Vendor vendor = existingCard.getVendor();
        CardSet cardSet = existingCard.getCardSet();
        Rooster rooster = existingCard.getRooster();
        int cardNumber = existingCard.getCardNumber();
        int year = existingCard.getYear();
        Card card = cardRepository.search(vendor, cardSet, rooster, cardNumber, year);
        assertNotNull(card);
    }

    @Test
    void testSearch() {
        assertEquals(2, cardRepository.search("2").size());
    }
}
