package com.vaessl.app.search;

import static com.vaessl.app.Mockdata.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import com.vaessl.app.exception.ConnectionNotFoundException;
import com.vaessl.app.homebox.HomeboxItemClient;
import static com.vaessl.app.shared.ServiceType.HOMEBOX;


@ExtendWith(MockitoExtension.class)
class HomeboxSearchProviderTest {

    @Mock
    private HomeboxItemClient client;

    @InjectMocks
    private HomeboxSearchProvider provider;

    @Test
    void shouldReturnConnectionNotFoundException() {

        Pageable pageable = PageRequest.of(0, 10);
        SearchRequest request = new SearchRequest(MOCK_URL, MOCK_USER, "", HOMEBOX, false);

        when(client.hbResponse(request, "", pageable)).thenThrow(new ConnectionNotFoundException());

        assertThrows(ConnectionNotFoundException.class,
                () -> provider.getSearchResults(request, pageable));
    }
}
