diff --git a/tests/testthat/_snaps/cookie.md b/tests/testthat/_snaps/cookie.md new file mode 100644 index 0000000..de61dab --- /dev/null +++ b/tests/testthat/_snaps/cookie.md @@ -0,0 +1,7 @@ +# Request cookie + + Code + parser + Message + i A cookie parser + diff --git a/tests/testthat/test-cookie.R b/tests/testthat/test-cookie.R index 7127b9b..02a5619 100644 --- a/tests/testthat/test-cookie.R +++ b/tests/testthat/test-cookie.R @@ -1,8 +1,10 @@ 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( @@ -10,4 +12,37 @@ test_that("Request cookie", { 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;") })