#!/bin/sh
# Jetable. La vue admin avec plusieurs departements, et la colonne qui apparait.
set -eu

BASE=http://127.0.0.1:4214
JAR=$(mktemp -d)/j.txt

curl -s -c "$JAR" -o /dev/null -H 'Content-Type: application/json' \
  -d '{"username":"narin","password":"admin1"}' \
  "$BASE/api/auth/sign-in/username"

body() {
  curl -s -b "$JAR" "$BASE$1" \
    | sed -n 's/.*<main[^>]*>\(.*\)<\/main>.*/\1/p' \
    | sed 's/<[^>]*>/\n/g' | grep -v '^[[:space:]]*$'
}

echo "=== un seul departement, pas de colonne Department ==="
body '/team?dept=Top+management' | head -12

echo
echo "=== trois departements, colonne Department attendue ==="
body '/team?dept=Top+management&dept=Casting&dept=Sample' | head -14

echo
echo "=== le meme, en-tetes seulement ==="
body '/team?dept=Top+management&dept=Casting&dept=Sample' | grep -c "Department" || echo "0"
