Add regression tests for script helpers

This commit is contained in:
Simon 2026-04-11 09:26:04 +01:00
parent 8b8255bab5
commit b09eb2c473

View file

@ -0,0 +1,44 @@
test_that("sourced getStationData handles request failure without attached httr", {
helper_env <- new.env(parent = globalenv())
sys.source(testthat::test_path("..", "..", "R", "getStationData.R"), envir = helper_env)
helper_env$request_api <- function(...) NULL
expect_null(
helper_env$getStationData(
start_date = "2024-01-01",
end_date = "2024-01-02",
station_id = "12345678",
headers = list(),
timesleep = 0
)
)
})
test_that("getAllFromCoord returns NULL when every station fetch fails", {
helper_env <- new.env(parent = globalenv())
sys.source(testthat::test_path("..", "..", "R", "getAllFromCoord.R"), envir = helper_env)
helper_env$getIdFromCoords <- function(...) {
data.frame(
Id_station = c("1001", "1002"),
Nom_usuel = c("Station A", "Station B"),
stringsAsFactors = FALSE
)
}
helper_env$getStationData <- function(...) NULL
expect_null(
helper_env$getAllFromCoord(
coord = c(44.85, 5.84),
start_date = "2024-01-01",
end_date = "2024-01-02",
allstations = data.frame(),
headers = list(),
btw_station_sleep = 0,
within_statio_sleep = 0
)
)
})