Tests E2E
Vous trouverez une présentation détaillée de l'environnement de test e2e dans le fichier e2e/README.md présent dans le dépôt Git.
Lancer les test localement
- Vérifier l'existence de
.env - Vérifier la résolution de
cas.ub.local - Lancer le docker-compose présent dans
e2e/docker - Lancer le script d'initialisation des données
- Lancer les tests
Vérifier l'existence de .env
Si le fichier .env n'existe pas à la racine du projet, créez le en faisant une copie de .env.example
PLAYWRIGHT_TEST_BASE_URL=http://localhost:4200
VASCO_API_URL=http://localhost:8080
E2E_ADMIN_LOGIN=admin
E2E_ADMIN_PASSWORD=p4$$w0rd
E2E_USER_LOGIN=user_101
E2E_USER_PASSWORD=user
Vérifier la résolution de cas.ub.local
L'URL cas.ub.local doit pouvoir être résolu dans les container (c'est fait automatiquement via la déclaration du service cas.ub.local dans le docker-compose) mais aussi dans votre environnement local.
Pour cela, ajouter la ligne suivante à votre /etc/hosts
127.0.0.1 localhost cas.ub.local
Lancer le docker-compose présent dans e2e/docker
Le fichier docker-compose.yml va lancer tous les containers dans le bon ordre et attendre que le backend soit opérationnel (healthy) pour lancer dernier container init-sql qui joue les script d'insertion de données nécessaires aux tests et qui ne sont pas réalisable via des appels aux endpoint (ex : modification du mot de passe d'un compte local)
cd e2e/docker && docker compose up -d
Lancer le script d'initialisation des données
Le backend étant lancé, on va faire une série d'appels curl vers ce dernier pour initialiser les données pour les tests.
Copiez le contenu du script dans un fichier dataset-setup.sh puis lancez le
bash ./dataset-setup.sh
#!/bin/bash
# dataset-setup.sh
# Script to automate E2E dataset prerequisites for Vasco
# Usage: source .env && ./dataset-setup.sh
# Alternatively, set environment variables directly before running:
# E2E_ADMIN_LOGIN=admin E2E_ADMIN_PASSWORD='p4$$w0rd' E2E_USER_LOGIN=user_101 E2E_USER_PASSWORD=user ./dataset-setup.sh
set -euo pipefail
# Load credentials from environment
: "${E2E_ADMIN_LOGIN:?E2E_ADMIN_LOGIN not set}"
: "${E2E_ADMIN_PASSWORD:?E2E_ADMIN_PASSWORD not set}"
: "${E2E_USER_LOGIN:?E2E_USER_LOGIN not set}"
: "${E2E_USER_PASSWORD:?E2E_USER_PASSWORD not set}"
API_URL="http://localhost:8080"
# 1. Authenticate as admin and get access token
ACCESS_TOKEN=$(curl -s -X POST "$API_URL/auth/authenticate" \
-H 'content-type: application/json' \
-d '{"login": "'$E2E_ADMIN_LOGIN'", "password": "'$E2E_ADMIN_PASSWORD'"}' \
| jq -r .access_token)
echo "[INFO] Got admin access token $ACCESS_TOKEN."
# 2. Synchronize structures
curl -s -X POST "$API_URL/batches/synchronize-structures" \
-H "authorization: Bearer $ACCESS_TOKEN"
echo "[INFO] Synchronized structures."
# 3. Synchronize managers (optional, but recommended)
curl -s -X POST "$API_URL/batches/synchronize-managers" \
-H "authorization: Bearer $ACCESS_TOKEN"
echo "[INFO] Synchronized managers."
# 4. Set at least 2 structures as porteuses (IDs 2 and 3 assumed)
for STRUCT_ID in 2 3; do
curl -s -X POST "$API_URL/structures/$STRUCT_ID/set-portage" \
-H "authorization: Bearer $ACCESS_TOKEN" \
-H 'content-type: application/json' \
-d '{"canHostConvention": true}'
echo "[INFO] Structure $STRUCT_ID set as porteuse."
sleep 1
done
# 5. Assign "Créateur de convention structure" privilege to user_101 for 2 structures
for STRUCT_ID in 2 3; do
curl -s -X POST "$API_URL/privileges" \
-H "authorization: Bearer $ACCESS_TOKEN" \
-H 'content-type: application/json' \
-d '{"idPersonne":2,"email":"user_101@u-bordeaux.fr","lastName":"user_101","firstName":"user_101","idRole":7,"contextId":'$STRUCT_ID',"uid":"user_101","sendMailToUser":false,"mailContent":null}'
echo "[INFO] Privilege assigned to user_101 for structure $STRUCT_ID."
sleep 1
done
#TODO: fetch idPersonne of user_101 and use it in the privilege creation, it's required when the person exists
## 6. Encode and set password for user_101
# ENCODED_PASSWORD=$(curl -s -X POST "$API_URL/auth/encode" \
# -H "authorization: Bearer $ACCESS_TOKEN" \
# -H 'content-type: text/plain' \
# --data "$E2E_USER_PASSWORD")
# echo "[ACTION REQUIRED] Encoded password for user_101: $ENCODED_PASSWORD"
# echo "[ACTION REQUIRED] Please manually set this encoded password for user_101 in the database if needed."
# read -p $'Press Enter to continue after completing the manual password action...'
# 7. Create at least 2 "Domaine convention" nomenclatures
DOMAINE_IDS=()
for i in 1 2; do
ID=$(curl -s -X POST "$API_URL/nomenclatures/simple" \
-H 'Content-Type: application/json' \
-H "authorization: Bearer $ACCESS_TOKEN" \
-d '{"tableName":"domaines_convention","intitule":"Domaine convention E2E '$i'"}' | jq -r .id)
DOMAINE_IDS+=("$ID")
echo "[INFO] Created Domaine convention E2E $i with id $ID."
sleep 1
done
# 8. Create 1 "Tag" nomenclature
curl -s -X POST "$API_URL/nomenclatures/simple" \
-H 'Content-Type: application/json' \
-H "authorization: Bearer $ACCESS_TOKEN" \
-d '{"tableName":"tags","intitule":"Tag E2E 1"}'
echo "[INFO] Created Tag E2E 1."
# 9. Create 1 "Reference externe" nomenclature
curl -s -X POST "$API_URL/nomenclatures/simple" \
-H 'Content-Type: application/json' \
-H "authorization: Bearer $ACCESS_TOKEN" \
-d '{"tableName":"types_reference_externe","intitule":"Reference externe E2E 1"}'
echo "[INFO] Created Reference externe E2E 1."
# 10. Create typologie ouverte with the first domaine convention
TYPOLOGIE_ID=$(curl -s -X POST "$API_URL/typologies" \
-H "authorization: Bearer $ACCESS_TOKEN" \
-H 'content-type: application/json' \
-d '{"intitule":"Typologie ouverte E2E 1","description":"Typologie pour test E2E","domainesConvention":['${DOMAINE_IDS[0]}'],"impactFinancier":true,"personnePhysiqueAutorise":true,"historiqueAutorise":true,"validationJuridiqueRequired":false,"etablissementSignataire":true,"canAddVisa":true,"circuitVisaRequired":false,"canAddAdditionalStructuresPartenaires":"TOUT_TYPE"}' | jq -r .id)
echo "[INFO] Created Typologie ouverte E2E 1 with id $TYPOLOGIE_ID."
# 11. Open the typologie with today's date
TODAY=$(date +%F)
curl -s -X POST "$API_URL/typologies/$TYPOLOGIE_ID/ouvrir" \
-H "authorization: Bearer $ACCESS_TOKEN" \
-H 'content-type: application/json' \
-d '{"date":"'$TODAY'","informationComplementaire":null}'
echo "[INFO] Opened Typologie $TYPOLOGIE_ID with date $TODAY."
echo "[SUCCESS] Dataset setup complete."
Lancer les tests
Soit en mode cli
npm run e2e
Soir en mode graphique
npm run e2e:ui