# Cookie-based sessions — Artillery's `using-cookies`.
#
# loadr keeps a per-VU cookie jar (on by default). `Set-Cookie` from the login
# response is stored and replayed automatically on every later request in that
# VU's flow, so a server-side session "just works". You can also read/write/clear
# cookies from JS (session.cookieGet / cookieSet / cookiesClear).
#
#   loadr run examples/38-cookies-session.yaml
name: cookies-session
description: per-VU cookie jar carries a login session across requests

defaults:
  http:
    base_url: https://api.example.com
    # The jar is enabled by default; shown here for clarity. Set false to send
    # no cookies and ignore Set-Cookie entirely.
    cookies: true

scenarios:
  session:
    executor: constant-vus
    vus: 5
    duration: 30s
    flow:
      # 1) Log in — the response's Set-Cookie (e.g. `session=...`) lands in the jar.
      - request:
          name: login
          method: POST
          url: /login
          body: { form: { username: demo, password: demo } }
          checks: [ { type: status, equals: 200 } ]

      # 2) The session cookie is replayed automatically — no manual header needed.
      - request:
          name: dashboard
          url: /dashboard
          checks: [ { type: status, equals: 200 } ]

      # 3) Set an extra cookie from script, then hit a page that reads it.
      - js: "session.cookieSet('experiment', 'B')"
      - request:
          name: settings
          url: /settings
          checks: [ { type: status, equals: 200 } ]

thresholds:
  checks: [ "rate>0.99" ]
