Skip to content

Commit

Permalink
test: cookie parser #48
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Mar 26, 2022
1 parent 78a51df commit 30f29ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/request.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,15 @@ set_params <- function(path, route = NULL){
#'
#' Mock a request, used for tests.
#'
#' @param cookie Cookie string.
#'
#' @examples
#' mockRequest()
#'
#' @export
mockRequest <- function(){
mockRequest <- function(
cookie = ""
){
req <- list(
HEADERS = list(
accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
Expand All @@ -293,6 +297,7 @@ mockRequest <- function(){
`upgrade-insecure-requests` = "1",
`user-agent` = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36"
),
HTTP_COOKIE = cookie,
HTTP_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
HTTP_ACCEPT_ENCODING = "gzip, deflate, br",
HTTP_ACCEPT_LANGUAGE = "en-US,en;q=0.9",
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-cookie.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_that("Request cookie", {
req <- mockRequest(
cookie = "yummy_cookie=choco; tasty_cookie=strawberry"
)
expect_s3_class(req, "Request")
expect_equal(
req$cookie,
list(
yummy_cookie = "choco",
tasty_cookie = "strawberry"
)
)
})

0 comments on commit 30f29ea

Please sign in to comment.