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

Issue31 mock tests #32

Merged
merged 4 commits into from
Jun 6, 2018
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
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Authors@R: c(person("Gabriela", "De Queiroz", email = "[email protected]", ro
person("Olga", "Mierzwa-Sulima", email = "[email protected]", role = c("aut")),
person("Lucy", "D'Agostino McGowan", email = "[email protected]", role = c("aut")),
person("Claudia", "Vitolo", role = c("aut")),
person("Michael", "Beigelmacher", role = c("ctb")))
person("Michael", "Beigelmacher", role = c("ctb")),
person("Augustina", "Ragwitz", email="[email protected]", role = c("ctb")))
Description: Provides access to data from 'meetup.com' (see https://www.meetup.com/meetup_api/ for more information).
License: MIT + file LICENSE
Depends:
Expand All @@ -19,6 +20,7 @@ Imports:
tibble
RoxygenNote: 6.0.1
Suggests: testthat,
here,
knitr,
rmarkdown
Roxygen: list(markdown = TRUE)
Expand Down
Binary file added tests/testdata/httr_get_find_groups.rda
Binary file not shown.
Binary file added tests/testdata/httr_get_get_events.rda
Binary file not shown.
33 changes: 27 additions & 6 deletions tests/testthat/test-find_groups.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
context("find_groups")

test_that("Exact query rladieslondon returns 1 group", {
skip_on_travis()
skip_on_cran()
meetup_groups <- find_groups(api_key = Sys.getenv("MEETUP_KEY"),
text = "rladieslondon")
expect_equal(dim(meetup_groups), c(1, 12))
test_that("find_groups() success case", {

meetup_groups <- with_mock(
`httr::GET` = function(url, query, ...) {
load(here::here("tests/testdata/httr_get_find_groups.rda"))
return(req)
},
meetup_groups <- find_groups(api_key = "R-Ladies FTW!")
)

expect_equal(nrow(meetup_groups), 1, label="check find_groups() returns one result")
expect_equal(meetup_groups$name, "R-Ladies London", label="check find_groups() content (name)")
})

test_that("find_groups() with parameters", {

meetup_groups <- with_mock(
`httr::GET` = function(url, query, ...) {
load(here::here("tests/testdata/httr_get_find_groups.rda"))
return(req)
},
meetup_groups <- find_groups(api_key = "R-Ladies FTW!",
text = "hihi", radius = "foo")
)

expect_equal(nrow(meetup_groups), 1, label="check find_groups() returns one result")
expect_equal(meetup_groups$name, "R-Ladies London", label="check find_groups() content (name)")
})
34 changes: 20 additions & 14 deletions tests/testthat/test-get_events.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
context("get_events")

test_that(".quick_fetch() works properly", {
skip_on_travis()
skip_on_cran()
api_key <- Sys.getenv("MEETUP_KEY")
event_status <- "past"
urlname <- Sys.getenv("MEETUP_NAME")
meetup_api_prefix <- "https://api.meetup.com/"
api_url <- paste0(meetup_api_prefix, urlname, "/events")
test_that("get_events() success case", {
meetup_events <- with_mock(
`httr::GET` = function(url, query, ...) {
load(here::here("tests/testdata/httr_get_get_events.rda"))
return(req)
},
meetup_events <- get_events(api_key="yay",
urlname = "<3",
event_status = "upcoming")
)

res <- .quick_fetch(api_url = api_url,
api_key = api_key,
event_status = event_status)
total_records <- as.integer(res$headers$`x-total-count`)
length_results <- length(res$result)
expect_equal(total_records,length_results)
expect_equal(nrow(meetup_events), 1, label="check get_events() returns one result")
expect_equal(meetup_events$status, "upcoming", label="check get_events() content (status)")
})

# TODO: multiple statuses

# TODO: event type is not allowed

# TODO: "urlname is missing"


19 changes: 19 additions & 0 deletions tests/testthat/test-internals.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
context("internals")

test_that(".quick_fetch() success case", {
res <- with_mock(
`httr::GET` = function(url, query, ...) {
load(here::here("tests/testdata/httr_get_find_groups.rda"))
return(req)
},
res <- .quick_fetch(api_url = "fake url", # intentionally invalid as there is currently no validation
api_key = "I <3 R-Ladies")
)

expect_equal(names(res), c("result", "headers"), info="check .quick_fetch() return value")
expect_equal(res$headers$`content-type`, "application/json;charset=utf-8", info="check .quick_fetch() header content-type")
})

# TODO .fetch_results()

# TODO .fetch_results() no api key