diff --git a/R/fetch_distribution_history.R b/R/fetch_distribution_history.R index 778ac7b..9716168 100644 --- a/R/fetch_distribution_history.R +++ b/R/fetch_distribution_history.R @@ -36,7 +36,12 @@ fetch_distribution_history <- function(distributionID){ res <- qualtrics_api_request("GET", url = fetch_url) elements <- append(elements, res$result$elements) - fetch_url <- res$result$nextPage + # check for "string" placeholder from mock server: + if (res$result$nextPage == "string") { + fetch_url <- NULL + } else { + fetch_url <- res$result$nextPage + } } diff --git a/tests/testthat/test-fetch-distribution-history.R b/tests/testthat/test-fetch-distribution-history.R index 50d1e8e..30a24a7 100644 --- a/tests/testthat/test-fetch-distribution-history.R +++ b/tests/testthat/test-fetch-distribution-history.R @@ -1,11 +1,9 @@ -test_that("fetch_distribution_history() returns a tbl_df with expected column names and types", { - - skip_on_cran() - - vcr::use_cassette("fetch_distribution_history", { - x <- fetch_distribution_history("EMD_RmjB8Gfpjlki6ms") - }) +skip_on_cran() +test_that("fetch_distribution_history() returns a tbl_df with expected column names and types", { + local_mocked_bindings(glue_api_v3 = function(base_url) "https://stoplight.io/mocks/qualtricsv2/publicapidocs/60919") + + x <- fetch_distribution_history("EMD_abcdef123456789") expect_s3_class(x, c("tbl_df", "tbl", "data.frame")) expect_s3_class(x$responseCompletedAt, c("POSIXct", "POSIXt")) expect_s3_class(x$sentAt, c("POSIXct", "POSIXt"))