mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-17 17:55:42 +00:00
75 lines
2.7 KiB
PHP
75 lines
2.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Tests\State;
|
||
|
|
|
||
|
|
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
||
|
|
use ApiPlatform\Symfony\Bundle\Test\Client;
|
||
|
|
use App\Entity\WatchList;
|
||
|
|
use App\Factory\UserFactory;
|
||
|
|
use App\Tests\AuthenticatedUserTrait;
|
||
|
|
use App\Tests\Service\RDAPServiceTest;
|
||
|
|
use PHPUnit\Framework\Attributes\DependsExternal;
|
||
|
|
use Zenstruck\Foundry\Test\Factories;
|
||
|
|
|
||
|
|
final class WatchListUpdateProcessorTest extends ApiTestCase
|
||
|
|
{
|
||
|
|
use Factories;
|
||
|
|
use AuthenticatedUserTrait;
|
||
|
|
|
||
|
|
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
|
||
|
|
public function testCreateWatchlist(): void
|
||
|
|
{
|
||
|
|
self::createUserAndWatchlist();
|
||
|
|
$this->assertResponseIsSuccessful();
|
||
|
|
$this->assertResponseStatusCodeSame(201);
|
||
|
|
$this->assertMatchesResourceItemJsonSchema(WatchList::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[DependsExternal(RDAPServiceTest::class, 'testUpdateRdapServers')]
|
||
|
|
public function testCreateTwoWatchlistWithSameDomains(): void
|
||
|
|
{
|
||
|
|
$client = self::createClientWithCredentials(self::getToken(UserFactory::createOne()));
|
||
|
|
self::createUserAndWatchlist($client);
|
||
|
|
self::createUserAndWatchlist($client);
|
||
|
|
$this->assertResponseStatusCodeSame(403);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[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',
|
||
|
|
'triggers' => [
|
||
|
|
['action' => 'email', 'event' => 'last changed'],
|
||
|
|
],
|
||
|
|
]]);
|
||
|
|
$this->assertResponseIsSuccessful();
|
||
|
|
$this->assertMatchesResourceItemJsonSchema(WatchList::class);
|
||
|
|
$data = $response->toArray();
|
||
|
|
$this->assertCount(2, $data['domains']);
|
||
|
|
$this->assertCount(1, $data['triggers']);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function createUserAndWatchlist(?Client $client = null): Client
|
||
|
|
{
|
||
|
|
$client = $client ?? self::createClientWithCredentials(self::getToken(UserFactory::createOne()));
|
||
|
|
$client->request('POST', '/api/watchlists', ['json' => [
|
||
|
|
'domains' => ['/api/domains/example.com'],
|
||
|
|
'name' => 'My Watchlist',
|
||
|
|
'triggers' => [
|
||
|
|
['action' => 'email', 'event' => 'last changed'],
|
||
|
|
['action' => 'email', 'event' => 'transfer'],
|
||
|
|
['action' => 'email', 'event' => 'expiration'],
|
||
|
|
['action' => 'email', 'event' => 'deletion'],
|
||
|
|
],
|
||
|
|
]]);
|
||
|
|
|
||
|
|
return $client;
|
||
|
|
}
|
||
|
|
}
|