elm-pages-v3-beta/tests/SetCookieTest.elm

89 lines
2.7 KiB
Elm
Raw Normal View History

2021-12-24 06:25:51 +03:00
module SetCookieTest exposing (all)
import Expect
import Server.SetCookie exposing (..)
import Test exposing (Test, describe, test)
import Time
all : Test
all =
describe "SetCookie"
[ test "simple value" <|
\() ->
setCookie "sessionId" "38afes7a8"
2021-12-24 07:04:49 +03:00
|> nonSecure
2021-12-24 06:25:51 +03:00
|> toString
|> Expect.equal "sessionId=38afes7a8"
, test "with expiration" <|
\() ->
setCookie "id" "a3fWa"
2021-12-24 07:04:49 +03:00
|> nonSecure
2021-12-24 06:25:51 +03:00
|> withExpiration (Time.millisToPosix 1445412480000)
|> toString
|> Expect.equal "id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT"
, test "http-only, multiple values" <|
\() ->
setCookie "id" "a3fWa"
2021-12-24 07:04:49 +03:00
|> nonSecure
2021-12-24 06:25:51 +03:00
|> withExpiration (Time.millisToPosix 1445412480000)
|> httpOnly
|> toString
|> Expect.equal "id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; HttpOnly"
, test "immediate expiration" <|
\() ->
setCookie "id" "a3fWa"
2021-12-24 07:04:49 +03:00
|> nonSecure
2021-12-24 06:25:51 +03:00
|> withImmediateExpiration
|> toString
|> Expect.equal "id=a3fWa; Expires=Thu, 01 Jan 1970 00:00:00 GMT"
, test "with path" <|
\() ->
setCookie "id" "a3fWa"
2021-12-24 07:04:49 +03:00
|> nonSecure
2021-12-24 06:25:51 +03:00
|> withPath "/"
|> toString
|> Expect.equal "id=a3fWa; Path=/"
, test "with max-age" <|
\() ->
setCookie "id" "a3fWa"
2021-12-24 07:04:49 +03:00
|> nonSecure
2021-12-24 06:25:51 +03:00
|> withMaxAge 123
|> toString
|> Expect.equal "id=a3fWa; Max-Age=123"
2021-12-24 06:44:52 +03:00
, test "encodes values" <|
\() ->
setCookie "id" "This needs encoding & it uses url encoding"
2021-12-24 07:04:49 +03:00
|> nonSecure
2021-12-24 06:44:52 +03:00
|> toString
|> Expect.equal "id=This%20needs%20encoding%20%26%20it%20uses%20url%20encoding"
2021-12-24 07:04:49 +03:00
, test "with domain" <|
\() ->
setCookie "id" "a3fWa"
|> nonSecure
|> withDomain "example.com"
|> toString
|> Expect.equal "id=a3fWa; Domain=example.com"
, test "secure" <|
\() ->
setCookie "id" "a3fWa"
|> toString
|> Expect.equal "id=a3fWa; Secure"
2021-12-24 06:25:51 +03:00
]
{-
- [X] Format dates from Time.Posix
2021-12-24 06:44:52 +03:00
- [X] UrlEncode values
2021-12-24 06:25:51 +03:00
2021-12-24 07:04:49 +03:00
- [X] Secure
2021-12-24 06:44:52 +03:00
- [X] Path
2021-12-24 07:04:49 +03:00
- [X] Domain
- [X] Max-Age
2021-12-24 06:25:51 +03:00
- [ ] SameSite
-}