Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T22 Test warnings an error messages in functions #30

Merged
merged 9 commits into from
Aug 2, 2020
Merged
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
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Authors@R: c(
role = "aut",
email="frans@ixpantia.com"))
Description: Connect to the Less Annoying CRM API to get your data clean and tidy.
License: GPL + file LICENCE
License: GPL-3 | file LICENSE
URL: https://ixpantia.github.io/lacrmr/
BugReports: https://github.com/ixpantia/lacrmr/issues
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.0.2
RoxygenNote: 7.1.0
Depends:
R (>= 3.6),
magrittr
Expand All @@ -37,4 +37,6 @@ Imports:
jsonlite,
janitor,
sjmisc,
httptest
httptest,
stringr,
mockery
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export(get_contact_information)
export(get_pipeline_report)
export(search_contacts)
import(magrittr)
importFrom(dplyr,"%>%")
23 changes: 17 additions & 6 deletions R/get_contact_information.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,29 @@ get_contact_information <- function(user_code, api_token, contact_id = "") {
warning("Please add a valid user code")
} else if (missing(api_token)) {
warning("Please add a valid API token")
} else
tryCatch({
} else if (missing(contact_id)) {
warning("Please add a contact id")
} else {

tryCatch({
r <- get_request(user_code = user_code,
api_token = api_token,
api_function = 'GetContact',
api_function = "GetContact",
... = contact_id)
})

# Parse json

# Usamos datos ejemplo:

contenido <- system.file("testdata/prueba_get_contact_information.json",
package = "lacrmr")

# Parte de la funcion
contenido <- httr::content(r, "text")

contenido <- httr::content(r, "text")
contenido <- jsonlite::fromJSON(contenido,
simplifyVector = TRUE)
contenido <- jsonlite::fromJSON(contenido,
simplifyVector = TRUE)

jsonlite::toJSON(contenido, pretty = TRUE)

Expand All @@ -45,6 +55,7 @@ get_contact_information <- function(user_code, api_token, contact_id = "") {
janitor::clean_names()

return(contenido)
}

}

3 changes: 1 addition & 2 deletions R/get_pipeline_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ get_pipeline_report <- function(user_code, api_token, pipelineid) {
warning("Please add a valid pipeline ID")
} else {

tryCatch(
{
tryCatch({
r <- get_request(user_code = user_code,
api_token = api_token,
api_function = "GetPipelineReport",
Expand Down
19 changes: 19 additions & 0 deletions R/lacrmr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' \code{lacrmr} package
#'
#' Connect to the Less Annoying CRM API to get your data clean and tidy.
#'
#' See the README on
#'
#' @docType package
#' @name lacramr
#' @importFrom dplyr %>%
NULL

## quiets concerns of R CMD check re: the .'s that appear in pipelines
utils::globalVariables(c(".", "Success", "result_email", "result_phone",
"result_address", "result_website",
"result_contact_custom_fields", "Result.FirstName",
"result_email", "result_phone", "result_website",
"filter", "select", "Text", "Type", "bind_cols",
"result_custom_fields"
))
3 changes: 2 additions & 1 deletion R/search_contacts.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ search_contacts <- function(user_code, api_token, search_term = "") {
warning("Please add a valid user code")
} else if (missing(api_token)) {
warning("Please add a valid API token")
} else
} else {
tryCatch(
{
r <- get_request(user_code = user_code,
Expand Down Expand Up @@ -95,6 +95,7 @@ search_contacts <- function(user_code, api_token, search_term = "") {
select(-result_email, -result_phone, -result_website, -result_address,
-result_contact_custom_fields, -result_custom_fields)
return(contenido)
}

}

2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' GET call to lacrm API
#' @param x an integer
#' @NoRd
#' @noRd
get_request <- function(user_code, api_token, api_function, ...) {

item <- paste0(...)
Expand Down
14 changes: 0 additions & 14 deletions man/get_request.Rd

This file was deleted.

12 changes: 12 additions & 0 deletions man/lacramr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library(testthat)
library(lacrmr)
library(mockery)

test_check("lacrmr")
3 changes: 2 additions & 1 deletion tests/testthat/helper_data.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
library(mockery)
# Test data for mocks in testing functions

contact_information <- system.file("testdata/prueba_get_contact_information.json",
package = "lacrmr")

contact_information <- jsonlite::fromJSON(contact_information)


Expand Down
35 changes: 35 additions & 0 deletions tests/testthat/test-cleaning.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

context("limpieza")

testthat::test_that("List are remove from the pipeline report", {
mockery::stub(where = get_pipeline_report,
what = "jsonlite::fromJSON",
how = pipeline_data)

pipeline_test <- get_pipeline_report(user_code = "user_code_test",
api_token = "token_api_test",
pipelineid = "pipeline_test")

expect_equal(ncol(pipeline_test), 33)
expect_equal(nrow(pipeline_test), 7)

})


testthat::test_that("Lists are remove from the get contacts information", {
mockery::stub(where = get_contact_information,
what = "jsonlite::fromJSON",
how = contact_information)

mockery::stub(where = get_contact_information,
what = "get_request",
how = contact_information)

get_contact_information_test <- get_contact_information(user_code = "user_code_test",
api_token = "token_api_test",
contact_id = 123)

expect_equal(ncol(pipeline_test), 33)
expect_equal(nrow(pipeline_test), 7)

})
2 changes: 1 addition & 1 deletion tests/testthat/test-credentials.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ testthat::test_that("Contact information error message with invalid credentials"
contact_id = "Fulano"))
})

testthat::test_that("Contact information error message with invalid credentials", {
testthat::test_that("Search contacts error message with invalid credentials", {
expect_error(search_contacts(user_code = "6A6E88",
api_token = "TQ9XM",
search_term = "brenesii"))
Expand Down
16 changes: 11 additions & 5 deletions tests/testthat/test-error-warning-msg.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ 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. Please check your user code or your api token"
)

expect_warning(
get_pipeline_report(user_code = "6A6E88",
pipelineid = "57102821"),
get_contact_information(user_code = "6A6E88",
contact_id = "h5jkfgns7"),
"Please add a valid API token"
)

expect_warning(
get_pipeline_report(user_code = "6A6E88",
api_token = "96066"),
"Please add a valid pipeline ID"
search_contacts(user_code = "6A6E88",
search_term = "ixpantia"),
"Please add a valid API token"
)
})

Expand Down
16 changes: 0 additions & 16 deletions tests/testthat/test-limpiar.R

This file was deleted.