From ffca942ea45505a3f151a0252437a390c3dc209b Mon Sep 17 00:00:00 2001 From: Jerry Johnson Date: Thu, 31 Mar 2022 14:12:58 -0600 Subject: [PATCH 1/4] Ref #61 check failing tests --- tests/testthat/test-cleaning.R | 1 + tests/testthat/test-credentials.R | 12 ++++++------ tests/testthat/test-error-warning-msg.R | 10 +++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/testthat/test-cleaning.R b/tests/testthat/test-cleaning.R index f222641..5d31c85 100644 --- a/tests/testthat/test-cleaning.R +++ b/tests/testthat/test-cleaning.R @@ -35,3 +35,4 @@ testthat::test_that("Lists are removed from the contacts information", { expect_equal(ncol(get_contact_information_test), 20) expect_equal(nrow(get_contact_information_test), 1) }) + diff --git a/tests/testthat/test-credentials.R b/tests/testthat/test-credentials.R index 7ec7fa3..3be06f3 100644 --- a/tests/testthat/test-credentials.R +++ b/tests/testthat/test-credentials.R @@ -8,12 +8,12 @@ testthat::test_that("Pipeline report error with invalid credentials", { "Invalid user credentials.") }) -testthat::test_that("Account information error message with invalid credentials", { - skip_on_cran() - expect_error(get_account_information(user_code = "6A6E88", - api_token = "FBHV7C"), - "Invalid user credentials") -}) +# testthat::test_that("Account information error message with invalid credentials", { +# skip_on_cran() +# expect_error(get_account_information(user_code = "6A6E88", +# api_token = "FBHV7C"), +# "Invalid user credentials") +# }) testthat::test_that("Contact information error message with invalid credentials", { diff --git a/tests/testthat/test-error-warning-msg.R b/tests/testthat/test-error-warning-msg.R index e05f518..8fe0b58 100644 --- a/tests/testthat/test-error-warning-msg.R +++ b/tests/testthat/test-error-warning-msg.R @@ -7,11 +7,11 @@ testthat::test_that("Invalid credentials", { "Please add a valid user code" ) - expect_error( - get_account_information(user_code = "6A6E88", - api_token = "57102821"), - "Invalid user credentials" - ) + # expect_error( + # get_account_information(user_code = "6A6E88", + # api_token = "57102821"), + # "Invalid user credentials" + # ) expect_warning( get_contact_information(user_code = "6A6E88", From cbc3a39dd1f020f78c6c2e4132bcb55c310868b4 Mon Sep 17 00:00:00 2001 From: ronnyhdez Date: Thu, 31 Mar 2022 14:57:27 -0600 Subject: [PATCH 2/4] Ref #62 fix function --- R/get_account_information.R | 3 +-- tests/testthat/test-credentials.R | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/R/get_account_information.R b/R/get_account_information.R index 17f2909..e43eba3 100644 --- a/R/get_account_information.R +++ b/R/get_account_information.R @@ -18,7 +18,6 @@ NULL #' api_token = "FBHV7C") #'} #' -#' #' @export get_account_information <- function(user_code, api_token) { if (missing(user_code)) { @@ -44,7 +43,7 @@ get_account_information <- function(user_code, api_token) { account_info <- httr::content(r, "text") account_info <- jsonlite::fromJSON(account_info) - if (pipeline$Success[1] == FALSE) { + if (account_info$Success[1] == FALSE) { stop("Invalid user credentials or pipeline ID.\n Please check your user code or your api token") } diff --git a/tests/testthat/test-credentials.R b/tests/testthat/test-credentials.R index 3be06f3..7ec7fa3 100644 --- a/tests/testthat/test-credentials.R +++ b/tests/testthat/test-credentials.R @@ -8,12 +8,12 @@ testthat::test_that("Pipeline report error with invalid credentials", { "Invalid user credentials.") }) -# testthat::test_that("Account information error message with invalid credentials", { -# skip_on_cran() -# expect_error(get_account_information(user_code = "6A6E88", -# api_token = "FBHV7C"), -# "Invalid user credentials") -# }) +testthat::test_that("Account information error message with invalid credentials", { + skip_on_cran() + expect_error(get_account_information(user_code = "6A6E88", + api_token = "FBHV7C"), + "Invalid user credentials") +}) testthat::test_that("Contact information error message with invalid credentials", { From 699a14377df1a0f54c3a2a125e811ca1f47ca976 Mon Sep 17 00:00:00 2001 From: ronnyhdez Date: Thu, 31 Mar 2022 15:33:41 -0600 Subject: [PATCH 3/4] Ref #62 bug fixed in function --- tests/testthat/test-error-warning-msg.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-error-warning-msg.R b/tests/testthat/test-error-warning-msg.R index 8fe0b58..e05f518 100644 --- a/tests/testthat/test-error-warning-msg.R +++ b/tests/testthat/test-error-warning-msg.R @@ -7,11 +7,11 @@ testthat::test_that("Invalid credentials", { "Please add a valid user code" ) - # expect_error( - # get_account_information(user_code = "6A6E88", - # api_token = "57102821"), - # "Invalid user credentials" - # ) + expect_error( + get_account_information(user_code = "6A6E88", + api_token = "57102821"), + "Invalid user credentials" + ) expect_warning( get_contact_information(user_code = "6A6E88", From c5ba92f5cb1c1fd8bc3b10c35f0c13ef759f2b37 Mon Sep 17 00:00:00 2001 From: ronnyhdez Date: Thu, 31 Mar 2022 15:38:27 -0600 Subject: [PATCH 4/4] Ref #63 fix warnings --- R/get_account_information.R | 4 ++-- R/get_contact_information.R | 2 +- R/get_pipeline_report.R | 2 +- R/search_contacts.R | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/get_account_information.R b/R/get_account_information.R index e43eba3..bd05251 100644 --- a/R/get_account_information.R +++ b/R/get_account_information.R @@ -34,13 +34,13 @@ get_account_information <- function(user_code, api_token) { }) - validate_json <- jsonlite::validate(httr::content(r, "text"))[1] + validate_json <- jsonlite::validate(httr::content(r, "text", encoding = "UTF-8"))[1] if (validate_json == FALSE) { stop("Invalid user credentials.\n Please check your user code or your api token") } - account_info <- httr::content(r, "text") + account_info <- httr::content(r, "text", encoding = "UTF-8") account_info <- jsonlite::fromJSON(account_info) if (account_info$Success[1] == FALSE) { diff --git a/R/get_contact_information.R b/R/get_contact_information.R index 2944043..b8e25d7 100644 --- a/R/get_contact_information.R +++ b/R/get_contact_information.R @@ -35,7 +35,7 @@ get_contact_information <- function(user_code, api_token, contact_id = "") { ... = contact_id) }) - content <- httr::content(r, "text") + content <- httr::content(r, "text", encoding = "UTF-8") validate_json <- jsonlite::validate(content) if (validate_json == FALSE) { diff --git a/R/get_pipeline_report.R b/R/get_pipeline_report.R index 885c8f7..c74ed51 100644 --- a/R/get_pipeline_report.R +++ b/R/get_pipeline_report.R @@ -44,7 +44,7 @@ get_pipeline_report <- function(user_code, api_token, pipelineid) { stop("Invalid user credentials or pipeline ID.\n Please check your user code or your api token") } - pipeline <- jsonlite::fromJSON(httr::content(r, "text"), + pipeline <- jsonlite::fromJSON(httr::content(r, "text", encoding = "UTF-8"), simplifyVector = TRUE) if (pipeline$Success[1] == FALSE) { diff --git a/R/search_contacts.R b/R/search_contacts.R index 4d27898..b894f00 100644 --- a/R/search_contacts.R +++ b/R/search_contacts.R @@ -34,11 +34,11 @@ search_contacts <- function(user_code, api_token, search_term = "") { ... = search_term) }) - contenido <- httr::content(r, "text") + contenido <- httr::content(r, "text", encoding = "UTF-8") contenido <- jsonlite::fromJSON(contenido) contenido <- as.data.frame(contenido) - # Pull only contact names, otherwise this will pull a nested list of + # Pull only contact names, otherwise this will pull a nested list of # companies where users were assigned as independent contacts contenido <- contenido %>% filter(!is.na(Result.FirstName))