|
|
|
@ -2,7 +2,8 @@
|
|
|
|
|
namespace App\Tests;
|
|
|
|
|
|
|
|
|
|
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
|
|
|
|
use ApiPlatform\Symfony\Bundle\Test\Response;
|
|
|
|
|
use App\Factory\DojoFactory;
|
|
|
|
|
use App\Factory\UserFactory;
|
|
|
|
|
use App\Repository\UserRepository;
|
|
|
|
|
use Zenstruck\Foundry\Test\Factories;
|
|
|
|
|
use Zenstruck\Foundry\Test\ResetDatabase;
|
|
|
|
@ -25,27 +26,59 @@ class DojoTest extends ApiTestCase
|
|
|
|
|
return sodium_bin2base64(sodium_crypto_sign($message, $sign_secret), SODIUM_BASE64_VARIANT_URLSAFE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCreateDojo(): void
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @var Response $response
|
|
|
|
|
* Requirement: A user should be able to create a dojo!
|
|
|
|
|
*/
|
|
|
|
|
$response = static::createClient()->request('POST', '/api/dojos',
|
|
|
|
|
public function testCreateDojo(): void
|
|
|
|
|
{
|
|
|
|
|
$userName = "FooBarFigher";
|
|
|
|
|
$dojoName = "BigFightDojo";
|
|
|
|
|
$userRepository = $this->getContainer()->get(UserRepository::class);
|
|
|
|
|
|
|
|
|
|
$this->assertCount(0, $userRepository->findByAuthName($userName));
|
|
|
|
|
|
|
|
|
|
static::createClient()->request('POST', '/api/dojos',
|
|
|
|
|
[
|
|
|
|
|
'headers' => [
|
|
|
|
|
'accept' => 'application/json',
|
|
|
|
|
'X-AUTH-TOKEN' => $this->generateAuthToken('blablabla')
|
|
|
|
|
'X-AUTH-TOKEN' => $this->generateAuthToken($userName)
|
|
|
|
|
],
|
|
|
|
|
'json' => [
|
|
|
|
|
'name' => 'FooBar'
|
|
|
|
|
'name' => $dojoName
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertResponseStatusCodeSame(201);
|
|
|
|
|
|
|
|
|
|
$userRepository = $this->getContainer()->get(UserRepository::class);
|
|
|
|
|
$this->assertCount(1, $userRepository->findAll());
|
|
|
|
|
$this->assertCount(1, $userRepository->findByAuthName($userName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Requirement: A user should NOT be able to create more than one dojos!
|
|
|
|
|
*/
|
|
|
|
|
public function testUserCannotCreateMultipleDojos(): void
|
|
|
|
|
{
|
|
|
|
|
$userName = "FooBarFigher";
|
|
|
|
|
$dojoName = "BigFightDojo";
|
|
|
|
|
DojoFactory::createOne([
|
|
|
|
|
'name' => $dojoName,
|
|
|
|
|
'owner' => UserFactory::createOne([
|
|
|
|
|
'authName' => $userName
|
|
|
|
|
])
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
static::createClient()->request('POST', '/api/dojos',
|
|
|
|
|
[
|
|
|
|
|
'headers' => [
|
|
|
|
|
'accept' => 'application/json',
|
|
|
|
|
'X-AUTH-TOKEN' => $this->generateAuthToken($userName)
|
|
|
|
|
],
|
|
|
|
|
'json' => [
|
|
|
|
|
'name' => $dojoName
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertResponseStatusCodeSame(409); // 409 Conflict
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|