unique(...) (`actual`) not equal to "Protests" (`expected`).

`actual` is [32mNULL[39m
`expected` is [32ma character vector[39m ('Protests')

test_that("number of columns is correct", {
test_that("names of columns are correct", {
test_that("event_type filters work or not",{
expect_equal(unique(acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",
start_date="2022-01-01",end_date = "2022-12-31",countries = "Argentina",
event_type = "Protests", prompt = F, acled_access = F, log = F)$event_type), "Protests" )
test_that("Split calls for big calls", {
test_that("country days are calculated as expected",{
unit_test = t_end - ymd(paste0(start_year, "-01-01")))
argentina_test_call <- acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",
end_date = "2021-01-01",prompt = F, acled_access = F, log = T)
# This works locally, but fails on devtools::check() and covr::package_coverge, but not on devtools::test() and simple execution.
#   local_mocked_bindings(menu = function(choices,title=NULL) 2)
#   test_that("Users can stop a call if they need to", {
#     expect_snapshot(acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",
#                            prompt = T, acled_access = F, log = F), error = T)
expect_equal(acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",
prompt = T, acled_access = F, log = F), acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",
## Test what happens when someone requests a region and a country of another region ----
test_that("Testing that when requestion a region, and a country of another region, you get both",{
test_that("When requesting a region with a numeric input, and a country of another region, you get both",{
test_that("timestamp (numeric) actually gets used as filter", {
test_that("timestamp (string) actually gets used as filter", {
## A menu is prompted when the user provides a non-recognized timestamp, allowing users to either stop or continue----
test_that("A user can stop a call when the provided timestamp is not recognized",{
expect_error(acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",
timestamp = "muchachos", prompt = F, acled_access = F, log = F), regexp =  "User requested")
test_that("A user can ignore the provided timestamp if it is not recognized",{
expect_no_error(acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",
timestamp = "muchachos", prompt = F, acled_access = F, log = F))
## When asking for monadics, it returns monadics ----
test_that("The call actually returns monadics.", {
## Error when someone requests a region that does not exist----
test_that("Error prompted when region does not exist", {
expect_error(acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",regions = "Narnia",
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F), regexp = "One or more requested region names not in the ACLED country list.")
test_that("Error when region number does not exist", {
expect_error(acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",regions = 420,
start_date="2022-01-01",end_date = "2022-12-31",prompt = F, acled_access = F, log = F),
regexp = "One or more requested region numbers not in the ACLED country list")
## Errors when a country requested doesnt exists ----
test_that("Error when one of two countries are wrong",{
expect_error(acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",countries = c("Argentia","Bolivia"),
regexp = "One or more of the requested countries *")})
## Test what happens when someone inputs acled_access as TRUE but it includes email and key. ----
# Test errors from incorrectly input arguments. ----
test_that("acled_api() throws an error when called with invalid arguments", {
"Countries is not a valid option. Please utilize \"countries\", without capitalizing")
"Country is not a valid option. Please utilize \"countries\"")
"Region is not a valid option. Please utilize \"regions\"")
"Regions is not a valid option. Please utilize \"regions\", without capitalizing")
"Event type is not a valid option. Please utilize \"event_types\", without capitalizing")
"Start_date is not a valid option. Please utilize \"start_date\", without capitalizing")
"End_date is not a valid option. Please utilize \"end_date\", without capitalizing")
# Test errors from badly utilized acled_access and key/email combination----
test_that("If access is TRUE and credentials are null, credentials are ignored, but an error appears if Keys are empty in the enviornemt", {
log = F), regexp = "acled_access is TRUE, but email and/or key are not stored in the enviornment. Please rerun acled_access or include key and email in function")
test_that("Users gets an error when acled_access is False, but no key or email are provided.", {
end_date = "2022-12-31", prompt = F, acled_access = F), regexp = "Email address required")
expect_error(acled_api(email = "stuff",countries = "Argentina", start_date="2022-01-01",
end_date = "2022-12-31", prompt = F, acled_access = F), regexp = "Key required")
# Test error if start_date is after end_date ----
test_that("start_date is after end_date", {
acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",
log = F), regexp = "Requested \'start_date\'")})
# Error when timestamp is from a date later than today ----
test_that("timestamp is from a latter date than today." ,{
timestamp = paste0(year(now())+1, "01-01"), # Way to make it always in the future
log = F), regexp = "The timestamp cannot be" )
# Error when requesting non-existent event types ----
test_that("Error when non existent event types",{
log = F), regexp = "One or more requested event types are not in the ACLED data.")
# A message appears that acled_access is being ignored, and the proper credentials are being used.----
test_that("A warning appears that acled_access is being ignored, and the proper credentials are being used.",{
alog <- acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",
expect_message(acled_api(email = "acledexamples@gmail.com", key = "M3PWwg3DIdhHMuDiilp5",
acled_access = T, log = T), regexp = "acled_access is TRUE, but email and key are included in the function. Ignoring acled_access.")
# Ensure tables do not display blanks, and display NAs instead
test_that("Tables display NAs instead of blanks", {
expect_equal(nrow(filter(received_data, if_any(everything(), ~ sjmisc::is_empty(.x, all.na.empty = F)))), 0)