diff --git a/tests/testthat/tests-perform_request.R b/tests/testthat/tests-perform_request.R index 30443eb..f3925e0 100644 --- a/tests/testthat/tests-perform_request.R +++ b/tests/testthat/tests-perform_request.R @@ -21,16 +21,21 @@ test_that("perform_request handles error responses", { }) test_that("perform_request validates per_page parameter", { + skip_if_offline() + expect_error(perform_request("countries", per_page = 50000)) expect_silent(perform_request("countries", per_page = 1000)) }) test_that("perform_request validates max_tries parameter", { + skip_if_offline() + expect_error(perform_request("countries", max_tries = -100)) expect_silent(perform_request("countries", max_tries = 2)) }) test_that("validate_per_page handles valid per_page values", { + expect_error(validate_per_page(-1000)) expect_silent(validate_per_page(1000)) expect_silent(validate_per_page(1)) expect_silent(validate_per_page(32500)) @@ -83,9 +88,7 @@ test_that("is_request_error identifies error responses correctly", { }) test_that("perform_request handles API errors gracefully", { - mock_req <- create_request( - "https://api.worldbank.org/v2", "nonexistent", NULL, 1000, NULL, NULL - ) - mock_resp <- structure(list(status_code = 404), class = "httr2_response") + skip_if_offline() + expect_error(perform_request("nonexistent"), "HTTP 404 Not Found.") }) diff --git a/tests/testthat/tests-wdi_get.R b/tests/testthat/tests-wdi_get.R index 193c5ac..1b77e86 100644 --- a/tests/testthat/tests-wdi_get.R +++ b/tests/testthat/tests-wdi_get.R @@ -35,6 +35,8 @@ test_that("wdi_get handels invalid progress input", { }) test_that("wdi_get creates valid output structure for single indicator", { + skip_if_offline() + result <- wdi_get( geographies = "USA", indicators = "NY.GDP.MKTP.CD", @@ -48,6 +50,8 @@ test_that("wdi_get creates valid output structure for single indicator", { }) test_that("wdi_get_creates valid output structure for multiple indicators", { + skip_if_offline() + result <- wdi_get( geographies = "USA", indicators = c("NY.GDP.MKTP.CD", "SP.POP.TOTL"), @@ -62,11 +66,15 @@ test_that("wdi_get_creates valid output structure for multiple indicators", { }) test_that("wdi_get returns a tibble", { + skip_if_offline() + result <- wdi_get("USA", "NY.GDP.PCAP.KD") expect_s3_class(result, "tbl_df") }) test_that("wdi_get handles single indicator, geography & default parameters", { + skip_if_offline() + result <- wdi_get("USA", "NY.GDP.PCAP.KD") expected_colnames <- c("indicator_id", "geography_id", "year", "value") expect_true(all(expected_colnames %in% colnames(result))) @@ -75,6 +83,8 @@ test_that("wdi_get handles single indicator, geography & default parameters", { }) test_that("wdi_get handles multiple indicators and multiple geographies", { + skip_if_offline() + result <- wdi_get(c("USA", "CAN"), c("NY.GDP.PCAP.KD", "SP.POP.TOTL")) expected_colnames <- c("indicator_id", "geography_id", "year", "value") expect_true(all(expected_colnames %in% colnames(result))) @@ -83,6 +93,8 @@ test_that("wdi_get handles multiple indicators and multiple geographies", { }) test_that("wdi_get handles different date ranges and frequencies", { + skip_if_offline() + result_annual <- wdi_get( "USA", "NY.GDP.PCAP.KD", start_date = 2010, end_date = 2015, frequency = "annual" @@ -102,6 +114,8 @@ test_that("wdi_get handles different date ranges and frequencies", { }) test_that("wdi_get handles format parameter (long and wide)", { + skip_if_offline() + result_long <- wdi_get("USA", "NY.GDP.PCAP.KD", format = "long") result_wide <- wdi_get("USA", "NY.GDP.PCAP.KD", format = "wide") diff --git a/tests/testthat/tests-wdi_get_geographies.R b/tests/testthat/tests-wdi_get_geographies.R index fa00c5d..858780f 100644 --- a/tests/testthat/tests-wdi_get_geographies.R +++ b/tests/testthat/tests-wdi_get_geographies.R @@ -16,13 +16,11 @@ test_that("wdi_get_geographies handles invalid per_page input", { ) }) -test_that("wdi_get_geographies returns a tibble", { - result <- wdi_get_geographies() - expect_s3_class(result, "tbl_df") -}) +test_that("wdi_get_geographies returns a tibble with correct column names", { + skip_if_offline() -test_that("wdi_get_geographies has correct columns", { result <- wdi_get_geographies() + expect_s3_class(result, "tbl_df") expected_colnames <- c( "geography_id", "geography_name", "geography_iso2code", "geography_type", "region_id", "region_name", "region_iso2code", "admin_region_id", @@ -76,6 +74,8 @@ test_that("wdi_get_geographies handles type conversions and missing values", { }) test_that("wdi_get_geographies handles different language inputs", { + skip_if_offline() + result <- wdi_get_geographies(language = "fr") expected_colnames <- c( diff --git a/tests/testthat/tests-wdi_get_income_levels.R b/tests/testthat/tests-wdi_get_income_levels.R index 18a7d3c..965be15 100644 --- a/tests/testthat/tests-wdi_get_income_levels.R +++ b/tests/testthat/tests-wdi_get_income_levels.R @@ -1,10 +1,8 @@ -test_that("wdi_get_income_levels returns a tibble", { - result <- wdi_get_income_levels() - expect_s3_class(result, "tbl_df") -}) +test_that("wdi_get_income_levels returns a tibble with correct column names", { + skip_if_offline() -test_that("wdi_get_income_levels has correct columns", { result <- wdi_get_income_levels() + expect_s3_class(result, "tbl_df") expected_colnames <- c( "income_level_id", "income_level_iso2code", "income_level_name" ) @@ -30,6 +28,8 @@ test_that("wdi_get_income_levels trims whitespace in character columns", { }) test_that("wdi_get_income_levels handles different language inputs", { + skip_if_offline() + result <- wdi_get_income_levels(language = "es") expected_colnames <- c( "income_level_id", "income_level_iso2code", "income_level_name" diff --git a/tests/testthat/tests-wdi_get_indicators.R b/tests/testthat/tests-wdi_get_indicators.R index 076b307..8b4b922 100644 --- a/tests/testthat/tests-wdi_get_indicators.R +++ b/tests/testthat/tests-wdi_get_indicators.R @@ -16,13 +16,12 @@ test_that("wdi_get_indicators handles invalid per_page input", { ) }) -test_that("wdi_get_indicators returns a tibble", { +test_that("wdi_get_indicators returns a tibble with correct column names", { + skip_if_offline() + result <- wdi_get_indicators() expect_s3_class(result, "tbl_df") -}) -test_that("wdi_get_indicators has correct columns", { - result <- wdi_get_indicators() expected_colnames <- c( "indicator_id", "indicator_name", "source_id", "source_name", "source_note", "source_organization", "topics" @@ -60,6 +59,8 @@ test_that("wdi_get_indicators handles type conversions and missing values", { }) test_that("wdi_get_indicators handles different language inputs", { + skip_if_offline() + result <- wdi_get_indicators(language = "es") expected_colnames <- c( "indicator_id", "indicator_name", "source_id", "source_name", diff --git a/tests/testthat/tests-wdi_get_languages.R b/tests/testthat/tests-wdi_get_languages.R index 82a31df..197cde0 100644 --- a/tests/testthat/tests-wdi_get_languages.R +++ b/tests/testthat/tests-wdi_get_languages.R @@ -1,10 +1,8 @@ -test_that("wdi_get_languages returns a tibble", { - result <- wdi_get_languages() - expect_s3_class(result, "tbl_df") -}) +test_that("wdi_get_languages returns a tibble with correct column names", { + skip_if_offline() -test_that("wdi_get_languages has correct columns", { result <- wdi_get_languages() + expect_s3_class(result, "tbl_df") expected_columns <- c("language_code", "language_name", "native_form") expect_true(all(expected_columns %in% colnames(result))) }) diff --git a/tests/testthat/tests-wdi_get_lending_types.R b/tests/testthat/tests-wdi_get_lending_types.R index 3311c8d..2313354 100644 --- a/tests/testthat/tests-wdi_get_lending_types.R +++ b/tests/testthat/tests-wdi_get_lending_types.R @@ -4,13 +4,11 @@ test_that("wdi_get_lending_types handles invalid language input", { ) }) -test_that("wdi_get_lending_types returns a tibble", { - result <- wdi_get_lending_types() - expect_s3_class(result, "tbl_df") -}) +test_that("wdi_get_lending_types returns a tibble with correct column names", { + skip_if_offline() -test_that("wdi_get_lending_types has correct columns", { result <- wdi_get_lending_types() + expect_s3_class(result, "tbl_df") expected_colnames <- c( "lending_type_id", "lending_type_iso2code", "lending_type_name" ) @@ -55,6 +53,8 @@ test_that("wdi_get_lending_types handles empty data gracefully", { }) test_that("wdi_get_lending_types handles different language inputs", { + skip_if_offline() + result <- wdi_get_lending_types(language = "es") expected_colnames <- c( "lending_type_id", "lending_type_iso2code", "lending_type_name" diff --git a/tests/testthat/tests-wdi_get_regions.R b/tests/testthat/tests-wdi_get_regions.R index 5882fe4..2fed30b 100644 --- a/tests/testthat/tests-wdi_get_regions.R +++ b/tests/testthat/tests-wdi_get_regions.R @@ -4,13 +4,11 @@ test_that("wdi_get_regions handles invalid language input", { ) }) -test_that("wdi_get_regions returns a tibble", { - result <- wdi_get_regions() - expect_s3_class(result, "tbl_df") -}) +test_that("wdi_get_regions returns a tibble with correct column names", { + skip_if_offline() -test_that("wdi_get_regions has correct columns", { result <- wdi_get_regions() + expect_s3_class(result, "tbl_df") expected_colnames <- c( "region_id", "region_code", "region_iso2code", "region_name" ) @@ -74,6 +72,8 @@ test_that("wdi_get_regions handles empty data gracefully", { }) test_that("wdi_get_regions handles different language inputs", { + skip_if_offline() + result <- wdi_get_regions(language = "fr") expected_columns <- c( "region_id", "region_code", "region_iso2code", "region_name" diff --git a/tests/testthat/tests-wdi_get_sources.R b/tests/testthat/tests-wdi_get_sources.R index dc51fca..e364245 100644 --- a/tests/testthat/tests-wdi_get_sources.R +++ b/tests/testthat/tests-wdi_get_sources.R @@ -4,13 +4,11 @@ test_that("wdi_get_sources handles invalid language input", { ) }) -test_that("wdi_get_sources returns a tibble", { - result <- wdi_get_sources() - expect_s3_class(result, "tbl_df") -}) +test_that("wdi_get_sources returns a tibble with correct column names", { + skip_if_offline() -test_that("wdi_get_sources has correct columns", { result <- wdi_get_sources() + expect_s3_class(result, "tbl_df") expected_colnames <- c( "source_id", "source_code", "source_name", "update_date", "is_data_available", "is_metadata_available", "concepts" @@ -91,6 +89,8 @@ test_that("wdi_get_sources handles empty data gracefully", { }) test_that("wdi_get_sources handles different language inputs", { + skip_if_offline() + result <- wdi_get_sources(language = "es") expected_colnames <- c( "source_id", "source_code", "source_name", "update_date", diff --git a/tests/testthat/tests-wdi_get_topics.R b/tests/testthat/tests-wdi_get_topics.R index 6813378..d7a1925 100644 --- a/tests/testthat/tests-wdi_get_topics.R +++ b/tests/testthat/tests-wdi_get_topics.R @@ -4,13 +4,11 @@ test_that("wdi_get_topics handles invalid language input", { ) }) -test_that("wdi_get_topics returns a tibble", { - result <- wdi_get_topics() - expect_s3_class(result, "tbl_df") -}) +test_that("wdi_get_topics returns a tibble with correct column names", { + skip_if_offline() -test_that("wdi_get_topics has correct columns", { result <- wdi_get_topics() + expect_s3_class(result, "tbl_df") expected_colnames <- c("topic_id", "topic_name", "topic_note") expect_true(all(expected_colnames %in% colnames(result))) }) @@ -68,6 +66,8 @@ test_that("wdi_get_topics handles empty data gracefully", { }) test_that("wdi_get_topics handles different language inputs", { + skip_if_offline() + result <- wdi_get_topics(language = "fr") expected_colnames <- c("topic_id", "topic_name", "topic_note") expect_true(all(expected_colnames %in% colnames(result))) diff --git a/tests/testthat/tests-wdi_search.R b/tests/testthat/tests-wdi_search.R index dd29f0b..0728db2 100644 --- a/tests/testthat/tests-wdi_search.R +++ b/tests/testthat/tests-wdi_search.R @@ -1,5 +1,4 @@ test_that("wdi_search returns rows with specified keywords in any column", { - # Sample data frame with both plain and nested columns data <- data.frame( id = 1:3, text = c("apple pie", "banana split", "cherry tart"), diff --git a/wbwdi.Rproj b/wbwdi.Rproj index 497f8bf..3715bac 100644 --- a/wbwdi.Rproj +++ b/wbwdi.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 2c2a9fc3-1a5e-4baa-8d35-f9e3cd5bfe58 RestoreWorkspace: Default SaveWorkspace: Default