2025-10-15 18:55:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Tests\State;
|
|
|
|
|
|
|
|
|
|
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
|
|
|
|
use ApiPlatform\Symfony\Bundle\Test\Client;
|
2025-10-25 17:26:56 +02:00
|
|
|
use App\Entity\Watchlist;
|
2025-10-15 18:55:39 +02:00
|
|
|
use App\Factory\UserFactory;
|
|
|
|
|
use App\Tests\AuthenticatedUserTrait;
|
|
|
|
|
use App\Tests\Service\RDAPServiceTest;
|
|
|
|
|
use PHPUnit\Framework\Attributes\DependsExternal;
|
2025-12-11 10:53:08 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2025-10-15 18:55:39 +02:00
|
|
|
use Zenstruck\Foundry\Test\Factories;
|
|
|
|
|
|
2025-10-25 17:26:56 +02:00
|
|
|
final class WatchlistUpdateProcessorTest extends ApiTestCase
|
2025-10-15 18:55:39 +02:00
|
|
|
{
|
|
|
|
|
use Factories;
|
|
|
|
|
use AuthenticatedUserTrait;
|
|
|
|
|
|
|
|
|
|
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
|
|
|
|
|
public function testCreateWatchlist(): void
|
|
|
|
|
{
|
|
|
|
|
self::createUserAndWatchlist();
|
|
|
|
|
$this->assertResponseIsSuccessful();
|
2025-12-11 10:53:08 +01:00
|
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_CREATED);
|
2025-10-25 17:26:56 +02:00
|
|
|
$this->assertMatchesResourceItemJsonSchema(Watchlist::class);
|
2025-10-15 18:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
|
|
|
|
|
public function testCreateTwoWatchlistWithSameDomains(): void
|
|
|
|
|
{
|
|
|
|
|
$client = self::createClientWithCredentials(self::getToken(UserFactory::createOne()));
|
|
|
|
|
self::createUserAndWatchlist($client);
|
|
|
|
|
self::createUserAndWatchlist($client);
|
2025-12-11 10:53:08 +01:00
|
|
|
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
2025-10-15 18:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
|
|
|
|
|
public function testUpdateWatchlist(): void
|
|
|
|
|
{
|
|
|
|
|
$client = self::createUserAndWatchlist();
|
|
|
|
|
$response = $client->request('GET', '/api/watchlists');
|
|
|
|
|
$token = $response->toArray()['hydra:member'][0]['token'];
|
|
|
|
|
|
|
|
|
|
$response = $client->request('PUT', '/api/watchlists/'.$token, ['json' => [
|
|
|
|
|
'domains' => ['/api/domains/iana.org', '/api/domains/example.com'],
|
|
|
|
|
'name' => 'My modified Watchlist',
|
2025-10-15 19:52:44 +02:00
|
|
|
'trackedEvents' => ['last changed'],
|
2025-10-19 21:37:52 +02:00
|
|
|
'trackedEppStatus' => [],
|
2025-10-25 19:27:41 +02:00
|
|
|
'enabled' => true,
|
2025-10-15 18:55:39 +02:00
|
|
|
]]);
|
|
|
|
|
$this->assertResponseIsSuccessful();
|
2025-10-25 17:26:56 +02:00
|
|
|
$this->assertMatchesResourceItemJsonSchema(Watchlist::class);
|
2025-10-15 18:55:39 +02:00
|
|
|
$data = $response->toArray();
|
|
|
|
|
$this->assertCount(2, $data['domains']);
|
2025-10-15 19:52:44 +02:00
|
|
|
$this->assertCount(1, $data['trackedEvents']);
|
2025-10-15 18:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-25 19:27:41 +02:00
|
|
|
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
|
|
|
|
|
public function testPartialUpdateWatchlist(): void
|
|
|
|
|
{
|
|
|
|
|
$client = self::createUserAndWatchlist();
|
|
|
|
|
$response = $client->request('GET', '/api/watchlists');
|
|
|
|
|
$token = $response->toArray()['hydra:member'][0]['token'];
|
|
|
|
|
|
|
|
|
|
$response = $client->request('PATCH', '/api/watchlists/'.$token, [
|
|
|
|
|
'headers' => ['Content-Type' => 'application/merge-patch+json'],
|
|
|
|
|
'json' => [
|
|
|
|
|
'enabled' => false,
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
|
$this->assertMatchesResourceItemJsonSchema(Watchlist::class);
|
|
|
|
|
$data = $response->toArray();
|
|
|
|
|
$this->assertFalse($data['enabled']);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-17 12:39:40 +02:00
|
|
|
public static function createUserAndWatchlist(?Client $client = null, array $domains = ['/api/domains/example.com'], ?string $connectorId = null): Client
|
2025-10-15 18:55:39 +02:00
|
|
|
{
|
|
|
|
|
$client = $client ?? self::createClientWithCredentials(self::getToken(UserFactory::createOne()));
|
2025-10-17 12:39:40 +02:00
|
|
|
|
2025-10-15 18:55:39 +02:00
|
|
|
$client->request('POST', '/api/watchlists', ['json' => [
|
2025-10-15 23:01:31 +02:00
|
|
|
'domains' => $domains,
|
2025-10-15 18:55:39 +02:00
|
|
|
'name' => 'My Watchlist',
|
2025-10-15 19:52:44 +02:00
|
|
|
'trackedEvents' => ['last changed', 'transfer', 'expiration', 'deletion'],
|
2025-10-19 21:37:52 +02:00
|
|
|
'trackedEppStatus' => ['redemption period', 'pending delete', 'client hold', 'server hold'],
|
2025-10-17 12:39:40 +02:00
|
|
|
'connector' => $connectorId,
|
2025-10-25 19:23:15 +02:00
|
|
|
'enabled' => true,
|
2025-10-15 18:55:39 +02:00
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
return $client;
|
|
|
|
|
}
|
|
|
|
|
}
|