dillonkearns/elm-pages/12.3.0

Test.PagesProgram.Session

Build a session payload to seed into a signed session cookie. Pair with Test.PagesProgram.CookieJar.setSession to place the signed value into the cookie jar for a test.

import Test.BackendTask as BackendTaskTest
import Test.PagesProgram.CookieJar as CookieJar
import Test.PagesProgram.Session as Session


BackendTaskTest.init
    |> CookieJar.withCookies
        (CookieJar.init
            |> CookieJar.setSession
                { name = "mysession"
                , secret = "test-secret"
                , session =
                    Session.init
                        |> Session.withValue "userId" "42"
                        |> Session.withFlash "greeting" "Welcome back!"
                }
        )
type alias Session =
Session

A session payload: a set of persistent session values and one-shot flash values. Mirrors the shape produced by Server.Session at runtime.

Building

init : Session

An empty session with no values, ready for withValue and withFlash.

withValue : String -> String -> Session -> Session

Add a persistent session value.

withFlash : String -> String -> Session -> Session

Add a flash session value. Flash values are available on the next request only, matching Server.Session.withFlash.