Skip to content

Commit

Permalink
fix outdated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfujs committed Jul 5, 2023
1 parent c0e17f6 commit c2a436c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 39 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/test-get_aux.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test_that("get_aux() works when calling specific tables", {
# expect_true(is.list(get_aux("tmp", simplify = FALSE)))
skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE")
expect_error(get_aux("wrong-table-name", server = "qa"))
expect_true(is.list(get_aux("wrong-table-name", simplify = FALSE, server = "qa")))
expect_true(is.list(get_aux("wrong-table-name", simplify = FALSE, server = "prod")))

# Check all tables
skip("survey_metadata gives a 500 error. Need to add functionality for list data")
Expand Down
59 changes: 21 additions & 38 deletions tests/testthat/test-get_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,8 @@ test_that("get_stats() works w/ popshare option", {
test_that("get_stats() works w/ subgroup = 'wb_regions'", {
skip_if_offline()
skip_on_cran()
skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE",
message = "pip-grp not implement on PROD yet"
)
skip_if(is.null(curl::nslookup(qa_host, error = FALSE)),
message = "Could not connect to QA host"
)
df <- get_stats("all", year = 2011, subgroup = "wb_regions", server = "qa")

df <- get_stats("all", year = 2011, subgroup = "wb_regions", server = "prod")
expect_equal(nrow(df), 10)
expect_identical(
sort(df$region_code),
Expand All @@ -83,16 +78,14 @@ test_that("get_stats() works w/ subgroup = 'none'", {
skip("Need to review to whole logic for this")
skip_if_offline()
skip_on_cran()
skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE",
message = "pip-grp not implement on PROD yet"
)
skip_if(is.null(curl::nslookup(qa_host, error = FALSE)),
message = "Could not connect to QA host"
)
df <- get_stats("all", year = 2011, subgroup = "none", server = "qa")

# skip_if(is.null(curl::nslookup(qa_host, error = FALSE)),
# message = "Could not connect to QA host"
# )
df <- get_stats("all", year = 2011, subgroup = "none", server = "prod")
expect_equal(nrow(df), 1)
expect_identical(df$region_code, "CUSTOM")
df <- get_stats(c("ARG", "BRA"), year = 2011, subgroup = "none", server = "qa")
df <- get_stats(c("ARG", "BRA"), year = 2011, subgroup = "none", server = "prod")
expect_equal(nrow(df), 1)
expect_identical(df$region_code, "CUSTOM")
})
Expand Down Expand Up @@ -149,13 +142,8 @@ test_that("get_stats() works w/ simplify = FALSE", {
test_that("get_wb() works", {
skip_if_offline()
skip_on_cran()
skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE",
message = "pip-grp not implement on PROD yet"
)
skip_if(is.null(curl::nslookup(qa_host, error = FALSE)),
message = "Could not connect to QA host"
)
df <- get_wb(year = 2011, server = "qa")

df <- get_wb(year = 2011, server = "prod")
expect_equal(nrow(df), 10)
expect_identical(
sort(df$region_code),
Expand All @@ -169,33 +157,28 @@ test_that("get_wb() works", {
test_that("get_wb() works w/ all response formats", {
skip_if_offline()
skip_on_cran()
skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE",
message = "pip-grp not implement on PROD yet"
)
skip_if(is.null(curl::nslookup(qa_host, error = FALSE)),
message = "Could not connect to QA host"
)
df <- get_wb(year = "all", format = "json", server = "qa")

df <- get_wb(year = "all", format = "json", server = "prod")
expect_true(tibble::is_tibble(df))
expect_gte(nrow(df), 3)
df <- get_wb(year = "all", format = "csv", server = "qa")
df <- get_wb(year = "all", format = "csv", server = "prod")
expect_true(tibble::is_tibble(df))
expect_gte(nrow(df), 3)
df <- get_wb(year = "all", format = "rds", server = "qa")
df <- get_wb(year = "all", format = "rds", server = "prod")
expect_true(tibble::is_tibble(df))
expect_gte(nrow(df), 3)
})

test_that("get_wb() works w/ simplify = FALSE", {
skip_if_offline()
skip_on_cran()
skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE",
message = "pip-grp not implement on PROD yet"
)
skip_if(is.null(curl::nslookup(qa_host, error = FALSE)),
message = "Could not connect to QA host"
)
res <- get_wb(year = "all", simplify = FALSE, server = "qa")
# skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE",
# message = "pip-grp not implement on PROD yet"
# )
# skip_if(is.null(curl::nslookup(qa_host, error = FALSE)),
# message = "Could not connect to QA host"
# )
res <- get_wb(year = "all", simplify = FALSE, server = "prod")
expect_true(is.list(res))
expect_identical(names(res), c("url", "status", "type", "content", "response"))
expect_identical(class(res), "pip_api")
Expand Down

0 comments on commit c2a436c

Please sign in to comment.