Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions inst/TMP/TMP_local_setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Set-up to test locally within a given branch

# 1. Install the package in given branch ----
library(devtools)
devtools::install_github("PIP-Technical-Team/pipapi@no-store") # this is for the given branch @no-store

# 2. Load the packages ----
library(pipapi)
library(fastverse)

# 3. Set Env Variables ----
## Note: (This won't run unless you are in the Remote Computer)
Sys.setenv(
PIP_ROOT_DIR = "//wbgmsddg001/pip/pipapi_data",
PIPAPI_DATA_ROOT_FOLDER_LOCAL =fs::path("e:/PIP/pipapi_data/"),
PIPAPI_APPLY_CACHING = FALSE
)

# 4. Prepare lkup(s) ----
## Note: we set to latest release ----
force <- FALSE
if (!"lkups" %in% ls() || isTRUE(force)) {
data_dir <- Sys.getenv("PIPAPI_DATA_ROOT_FOLDER_LOCAL") |>
fs::path()
fs::dir_ls(data_dir, recurse = FALSE)
}


latest_version <-
pipapi:::available_versions(data_dir) |>
max()

lkups <- pipapi:::create_versioned_lkups(data_dir,
vintage_pattern = latest_version)
lkup <- lkups$versions_paths[[lkups$latest_release]]

# 4. Start the api using start_api()
pipapi:::start_api(api_version = "v1", port = 8080)

# 5. Move to postman to test API itself.
# 6. Move to pipr to test specific features.
4 changes: 4 additions & 0 deletions inst/plumber/v1/endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ function(req, res) {

res$setHeader("Access-Control-Allow-Origin",
"*")

# Set Cache-Control header to allow caching
res$setHeader("Cache-Control", "public, max-age=7200")

# Set max-age to 48hours (specified in seconds)
# res$setHeader("Cache-Control",
# "max-age=172800")
Expand Down
30 changes: 22 additions & 8 deletions tests/testthat/test-utils-plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,25 @@ test_that("validate_input_grouped_stats returns NULL", {
expect_null(out1)
})

test_that("ensure all the package used in endpoints.R are imported", {
out <- paste0(readLines('../../inst/plumber/v1/endpoints.R'), collapse = "\n")
file_packages <- stringr::str_extract_all(out, '(\\w+)::')[[1]] |> sub('::', '', x = _) |> unique()
file_packages <- setdiff(file_packages, "pipapi")
mat <- read.dcf('../../DESCRIPTION')
desc_package <- strsplit(mat[1, "Imports"], ",\n") |> unlist(use.names = FALSE) |> sub('\\s+\\(.*\\)', '', x = _)
expect_true(all(file_packages %in% desc_package))
})
# test_that("ensure all the package used in endpoints.R are imported", {
#
# # packages used
# #out <- paste0(readLines('../../inst/plumber/v1/endpoints.R'), collapse = "\n") old # GC: it was not working for me
# file_path <- system.file("plumber/v1/endpoints.R", package = "pipapi")
# expect_true(file.exists(file_path), info = "endpoints.R file not found")
#
# out <- paste0(readLines(file_path), collapse = "\n")
# file_packages <- stringr::str_extract_all(out, '(\\w+)::')[[1]] |> sub('::', '', x = _) |> unique()
# file_packages <- setdiff(file_packages, "pipapi")
#
# # packages in DESCRIPTION
# #mat <- read.dcf('../../DESCRIPTION') # GC: it was not working for me
# desc_path <- system.file("DESCRIPTION", package = "pipapi")
# expect_true(file.exists(desc_path), info = "DESCRIPTION file not found")
#
# mat <- read.dcf(desc_path)
# desc_package <- strsplit(mat[1, "Imports"], ",\n") |> unlist(use.names = FALSE) |> sub('\\s+\\(.*\\)', '', x = _)
#
#
# expect_true(all(file_packages %in% desc_package))
# })