domain-watchdog/tests/Controller/ConnectorControllerTest.php

73 lines
2.5 KiB
PHP
Raw Normal View History

2025-10-14 17:40:48 +02:00
<?php
namespace App\Tests\Controller;
2025-10-14 18:48:40 +02:00
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
2025-10-14 17:40:48 +02:00
use App\Entity\Connector;
use App\Factory\UserFactory;
2025-10-14 18:48:40 +02:00
use App\Tests\AuthenticatedUserTrait;
2025-10-14 17:40:48 +02:00
use Zenstruck\Foundry\Test\Factories;
2025-10-14 18:48:40 +02:00
final class ConnectorControllerTest extends ApiTestCase
2025-10-14 17:40:48 +02:00
{
use Factories;
2025-10-14 18:48:40 +02:00
use AuthenticatedUserTrait;
2025-10-14 17:40:48 +02:00
public function testGetConnectorCollection(): void
{
2025-10-16 02:31:08 +02:00
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
2025-10-14 17:40:48 +02:00
$response = $client->request('GET', '/api/connectors');
$this->assertResponseIsSuccessful();
$this->assertMatchesResourceCollectionJsonSchema(Connector::class);
$this->assertCount(0, $response->toArray()['hydra:member']);
}
2025-10-16 02:31:08 +02:00
public function testCreateConnectorInvalidAuthData(): void
{
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
$client->request('POST', '/api/connectors', ['json' => [
'authData' => [
'waiveRetractationPeriod' => true,
'acceptConditions' => true,
'ownerLegalAge' => true,
'token' => '',
],
'provider' => 'gandi',
]]);
$this->assertResponseStatusCodeSame(400);
}
public function testCreateConnectorInvalidConsent(): void
{
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
$client->request('POST', '/api/connectors', ['json' => [
'authData' => [
'waiveRetractationPeriod' => true,
'acceptConditions' => true,
'ownerLegalAge' => false,
'token' => '',
],
'provider' => 'gandi',
]]);
$this->assertResponseStatusCodeSame(451);
}
public function testCreateConnectorInvalidAuthDataAdditionalKey(): void
{
$client = ConnectorControllerTest::createClientWithCredentials(ConnectorControllerTest::getToken(UserFactory::createOne()));
$client->request('POST', '/api/connectors', ['json' => [
'authData' => [
'waiveRetractationPeriod' => true,
'acceptConditions' => true,
'ownerLegalAge' => true,
'token' => '',
'unknownKey' => 'hello',
],
'provider' => 'gandi',
]]);
$this->assertResponseStatusCodeSame(400);
}
2025-10-14 17:40:48 +02:00
}