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.Vendor;
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 VendorRepositoryTest {

    @Autowired
    private VendorRepository vendorRepository;

    @Test
    void testFindByName() {
        Vendor vendor = vendorRepository.findByName(TestConstants.TOPPS_NAME);
        assertNotNull(vendor);
        assertEquals(TestConstants.TOPPS_NAME, vendor.getName());
    }

    @Test
    void testFindByNameIgnoreCase() {
        List<Vendor> vendors = vendorRepository.findByNameIgnoreCase(TestConstants.TOPPS_NAME.toLowerCase());
        assertNotNull(vendors);
        assertEquals(1, vendors.size());
        assertEquals(TestConstants.TOPPS_NAME, vendors.get(0).getName());
    }

    @Test
    void testSearch() {
        List<Vendor> vendors = vendorRepository.search("pp");
        assertNotNull(vendors);
        assertEquals(2, vendors.size());
    }
}
