Files
Classeo/backend/tests/Functional/Administration/Api/GradingModeEndpointsTest.php
Mathias STRASSER ff18850a43 feat: Configuration du mode de notation par établissement
Les établissements scolaires utilisent des systèmes d'évaluation variés
(notes /20, /10, lettres, compétences, sans notes). Jusqu'ici l'application
imposait implicitement le mode notes /20, ce qui ne correspondait pas
à la réalité pédagogique de nombreuses écoles.

Cette configuration permet à chaque établissement de choisir son mode
de notation par année scolaire, avec verrouillage automatique dès que
des notes ont été saisies pour éviter les incohérences. Le Score Sérénité
adapte ses pondérations selon le mode choisi (les compétences sont
converties via un mapping, le mode sans notes exclut la composante notes).
2026-02-07 02:32:20 +01:00

152 lines
4.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Functional\Administration\Api;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use PHPUnit\Framework\Attributes\Test;
/**
* Tests for grading mode API endpoints.
*
* @see Story 2.4 - Configuration Mode de Notation
*/
final class GradingModeEndpointsTest extends ApiTestCase
{
protected static ?bool $alwaysBootKernel = true;
// =========================================================================
// Security - Without tenant
// =========================================================================
#[Test]
public function getGradingModeReturns404WithoutTenant(): void
{
$client = static::createClient();
$client->request('GET', '/api/academic-years/current/grading-mode', [
'headers' => [
'Host' => 'localhost',
'Accept' => 'application/json',
],
]);
self::assertResponseStatusCodeSame(404);
}
#[Test]
public function configureGradingModeReturns404WithoutTenant(): void
{
$client = static::createClient();
$client->request('PUT', '/api/academic-years/current/grading-mode', [
'headers' => [
'Host' => 'localhost',
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
'json' => ['mode' => 'numeric_20'],
]);
self::assertResponseStatusCodeSame(404);
}
// =========================================================================
// Security - Without authentication (with tenant)
// =========================================================================
#[Test]
public function getGradingModeReturns401WithoutAuthentication(): void
{
$client = static::createClient();
$client->request('GET', 'http://ecole-alpha.classeo.local/api/academic-years/current/grading-mode', [
'headers' => [
'Accept' => 'application/json',
],
]);
self::assertResponseStatusCodeSame(401);
}
#[Test]
public function configureGradingModeReturns401WithoutAuthentication(): void
{
$client = static::createClient();
$client->request('PUT', 'http://ecole-alpha.classeo.local/api/academic-years/current/grading-mode', [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
'json' => ['mode' => 'numeric_20'],
]);
self::assertResponseStatusCodeSame(401);
}
// =========================================================================
// Validation - Invalid mode
// =========================================================================
#[Test]
public function configureGradingModeRejectsInvalidModeWithoutTenant(): void
{
$client = static::createClient();
$client->request('PUT', '/api/academic-years/current/grading-mode', [
'headers' => [
'Host' => 'localhost',
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
'json' => ['mode' => 'invalid_mode'],
]);
// Without tenant, returns 404 before validation kicks in
self::assertResponseStatusCodeSame(404);
}
// =========================================================================
// Special identifiers - 'current', 'next', 'previous'
// =========================================================================
#[Test]
public function getGradingModeAcceptsCurrentIdentifier(): void
{
$client = static::createClient();
$client->request('GET', 'http://ecole-alpha.classeo.local/api/academic-years/current/grading-mode', [
'headers' => ['Accept' => 'application/json'],
]);
// 401 (no auth) not 404 (invalid id) — proves 'current' is accepted
self::assertResponseStatusCodeSame(401);
}
#[Test]
public function getGradingModeAcceptsNextIdentifier(): void
{
$client = static::createClient();
$client->request('GET', 'http://ecole-alpha.classeo.local/api/academic-years/next/grading-mode', [
'headers' => ['Accept' => 'application/json'],
]);
self::assertResponseStatusCodeSame(401);
}
#[Test]
public function getGradingModeAcceptsPreviousIdentifier(): void
{
$client = static::createClient();
$client->request('GET', 'http://ecole-alpha.classeo.local/api/academic-years/previous/grading-mode', [
'headers' => ['Accept' => 'application/json'],
]);
self::assertResponseStatusCodeSame(401);
}
}