diff --git a/R/global.R b/R/global.R index 4b1698f..4b51a73 100644 --- a/R/global.R +++ b/R/global.R @@ -180,6 +180,14 @@ check_and_download_update <- function() { "infinitylists", "/releases/latest" ) + + # Simulate network down + network_down <- as.logical(Sys.getenv("NETWORK_UP", unset = TRUE)) + + if(httr::http_error(url)| network_down){ + message("No internet connection or data source down, try again later") + return(NULL) + } response <- httr::GET(url) release_data <- jsonlite::fromJSON(httr::content(response, "text")) diff --git a/tests/testthat/test-galah_download.R b/tests/testthat/test-galah_download.R index 639b2fe..6853580 100644 --- a/tests/testthat/test-galah_download.R +++ b/tests/testthat/test-galah_download.R @@ -10,3 +10,10 @@ test_that("Download exceutes", { expect_named(odonata) expect_s3_class(odonata, "tbl_df") }) + + +test_that("Fails gracefully", { + # in my tests + Sys.setenv("NETWORK_UP" = TRUE) + expect_message(check_and_download_update()) +}) \ No newline at end of file diff --git a/tests/testthat/test-spatial-global.R b/tests/testthat/test-spatial-global.R new file mode 100644 index 0000000..b9f4901 --- /dev/null +++ b/tests/testthat/test-spatial-global.R @@ -0,0 +1,49 @@ +test_that("Loading a place successfully", { + places <- list.files(system.file(package = "infinitylists", "extdata", "places")) + paths <- file.path(system.file(package = "infinitylists", "extdata", "places", places)) + + kmls <- purrr::map(paths, + ~load_place(.x) + ) + + expect_visible(purrr::map(paths, + ~load_place(.x)) + ) + + expect_type(kmls[[1]], "list") + + expect_visible(places) + expect_type(places, "character") +}) + + +test_that("Circle or buffer is added", { + # malabar + radii <- seq(10,100, by = 10) + + expect_visible(purrr::map(radii, + ~create_circle_polygon(lat = 33.9679, long = 151.2511, .x) + )) + + with_circles <- purrr::map(radii, + ~create_circle_polygon(lat = 33.9679, long = 151.2511, .x) + ) + expect_type(with_circles[[1]], "list") + + expect_error(add_buffer(with_circles, 5)) +}) + +test_that("Intersections are working", { + occ <- dplyr::tibble(lat = 33.9679, long = 151.2511) + occ_sf <- sf::st_as_sf(occ, coords = c("long", "lat"), crs = 4326) + + expect_true(points_in_target(occ_sf, create_circle_polygon(lat = 33.9679, long = 151.2511, 10))) + + expect_true(points_in_buffer(occ_sf, create_circle_polygon(lat = 33.9679, long = 151.2511, 10), buffer_size = 10)) +}) + + + + + +