Bug fix UI crash when url is unrechable (#1642)

* feat: Add URL  reachability check in ConvertWebsiteToPDF

* Add tests for URL reachability in ConvertWebsiteToPdfTest

* test: Update URL in ConvertWebsiteToPdfTest for testing
This commit is contained in:
Diallo
2024-08-08 22:35:15 +02:00
committed by GitHub
parent 771b312ee8
commit 148feda83f
3 changed files with 76 additions and 13 deletions

View File

@@ -0,0 +1,41 @@
package stirling.software.SPDF.controller.api.converters;
import org.junit.jupiter.api.Test;
import org.springframework.http.ResponseEntity;
import stirling.software.SPDF.model.api.converters.UrlToPdfRequest;
import static org.junit.jupiter.api.Assertions.*;
public class ConvertWebsiteToPdfTest {
@Test
public void test_exemption_is_thrown_when_invalid_url_format_provided() {
String invalid_format_Url = "invalid-url";
// Arrange
ConvertWebsiteToPDF convertWebsiteToPDF = new ConvertWebsiteToPDF();
UrlToPdfRequest request = new UrlToPdfRequest();
request.setUrlInput(invalid_format_Url);
// Act
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> {
convertWebsiteToPDF.urlToPdf(request);
});
// Assert
assertEquals("Invalid URL format provided.", thrown.getMessage());
}
@Test
public void test_exemption_is_thrown_when_url_is_not_reachable() {
String unreachable_Url = "https://www.googleeeexyz.com";
// Arrange
ConvertWebsiteToPDF convertWebsiteToPDF = new ConvertWebsiteToPDF();
UrlToPdfRequest request = new UrlToPdfRequest();
request.setUrlInput(unreachable_Url);
// Act
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> {
convertWebsiteToPDF.urlToPdf(request);
});
// Assert
assertEquals("URL is not reachable, please provide a valid URL.", thrown.getMessage());
}
}