Skip to content

Commit

Permalink
test: more cookie tests #48
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Mar 27, 2022
1 parent f1fdf60 commit df3de3c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/cookie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Request cookie

Code
parser
Message <cliMessage>
i A cookie parser

35 changes: 35 additions & 0 deletions tests/testthat/test-cookie.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
test_that("Request cookie", {
# cookie set
req <- mockRequest(
cookie = "yummy_cookie=choco; tasty_cookie=strawberry"
)
expect_s3_class(req, "Request")
expect_length(req$cookie, 2L)
expect_equal(
req$cookie,
list(
yummy_cookie = "choco",
tasty_cookie = "strawberry"
)
)

# empty coookie
req <- mockRequest(cookie = "")
expect_length(req$cookie, 0L)
expect_type(req$cookie, "list")
expect_equal(req$cookie, list())

# incorrect cookie
req <- mockRequest(
cookie = "yummy_cookie=choco; tasty_cookie="
)
expect_length(req$cookie, 1L)
expect_type(req$cookie, "list")
expect_equal(
req$cookie,
list(
yummy_cookie = "choco"
)
)

# parser
fn <- function(req) {
return(req$HTTP_COOKIE)
}
parser <- as_cookie_parser(fn)
expect_snapshot(parser)
app <- Ambiorix$new()
app$use(parser)
req <- mockRequest(
cookie = "yummy_cookie=choco;"
)
expect_type(req$cookie, "character")
expect_equal(req$cookie, "yummy_cookie=choco;")
})

0 comments on commit df3de3c

Please sign in to comment.