feat(mail) : MailSyncTriggerController - POST /api/mail/sync (202 + Messenger async)
- dispatch MailSyncRequested au bus Messenger, retourne 202 immediat - folderPath optionnel via body JSON pour sync ciblee - en test : transport in-memory route le message en sync - securite via MailAccessChecker Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Functional\Controller\Mail;
|
||||
|
||||
use App\Entity\User;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class MailSyncTriggerControllerTest extends WebTestCase
|
||||
{
|
||||
public function testSyncTriggerReturns401WhenNotAuthenticated(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$client->request('POST', '/api/mail/sync');
|
||||
|
||||
self::assertResponseStatusCodeSame(401);
|
||||
}
|
||||
|
||||
public function testSyncTriggerReturns403ForRoleClient(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$container = static::getContainer();
|
||||
$em = $container->get('doctrine.orm.entity_manager');
|
||||
|
||||
$clientUser = $em->getRepository(User::class)->findOneBy(['username' => 'client-liot']);
|
||||
$client->loginUser($clientUser);
|
||||
$client->request('POST', '/api/mail/sync');
|
||||
|
||||
self::assertResponseStatusCodeSame(403);
|
||||
}
|
||||
|
||||
public function testSyncTriggerReturns202ForRoleUser(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$container = static::getContainer();
|
||||
$em = $container->get('doctrine.orm.entity_manager');
|
||||
|
||||
$user = $em->getRepository(User::class)->findOneBy(['username' => 'alice']);
|
||||
$client->loginUser($user);
|
||||
$client->request('POST', '/api/mail/sync');
|
||||
|
||||
self::assertResponseStatusCodeSame(202);
|
||||
$data = json_decode($client->getResponse()->getContent(), true);
|
||||
self::assertArrayHasKey('message', $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user