#!/bin/sh
# Jetable. Chaque route de la barre latérale, pour les trois niveaux.
set -eu

BASE=http://127.0.0.1:1355
HOST='Host: advmfr.localhost:1355'
JAR=$(mktemp -d)

signin() {
  curl -s -c "$JAR/$1.txt" -H "$HOST" -H 'Content-Type: application/json' \
    -d "{\"username\":\"$1\",\"password\":\"$2\"}" \
    "$BASE/api/auth/sign-in/username" > /dev/null
}

signin narin admin1
signin malai manager1
signin nattikan staff1

printf '%-26s %-12s %-12s %s\n' route admin manager staff
for route in /tasks /review /tasks/new /positions /admin/people /admin/holidays \
             /admin/recurrence /preview/recurrence /preview/position; do
  a=$(curl -s -o /dev/null -w '%{http_code}' -b "$JAR/narin.txt" -H "$HOST" "$BASE$route")
  m=$(curl -s -o /dev/null -w '%{http_code}' -b "$JAR/malai.txt" -H "$HOST" "$BASE$route")
  s=$(curl -s -o /dev/null -w '%{http_code}' -b "$JAR/nattikan.txt" -H "$HOST" "$BASE$route")
  printf '%-26s %-12s %-12s %s\n' "$route" "$a" "$m" "$s"
done

rm -rf "$JAR"
