You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.6 KiB
52 lines
1.6 KiB
<?php
|
|
namespace App\Tests;
|
|
|
|
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
|
use ApiPlatform\Symfony\Bundle\Test\Response;
|
|
use App\Repository\UserRepository;
|
|
use Zenstruck\Foundry\Test\Factories;
|
|
use Zenstruck\Foundry\Test\ResetDatabase;
|
|
use DateTimeImmutable;
|
|
use DateTimeZone;
|
|
|
|
class DojoTest extends ApiTestCase
|
|
{
|
|
// This trait provided by Foundry will take care of refreshing the database content to a known state before each test
|
|
use ResetDatabase, Factories;
|
|
|
|
private function generateAuthToken(string $authName)
|
|
{
|
|
$sign_seed = sodium_base642bin($_ENV['AUTH_SEED'], SODIUM_BASE64_VARIANT_ORIGINAL);
|
|
$sign_pair = sodium_crypto_sign_seed_keypair($sign_seed);
|
|
$sign_secret = sodium_crypto_sign_secretkey($sign_pair);
|
|
$now = new DateTimeImmutable("now", new DateTimeZone("UTC"));
|
|
$message = $authName . "|" . $now->format("c");
|
|
|
|
return sodium_bin2base64(sodium_crypto_sign($message, $sign_secret), SODIUM_BASE64_VARIANT_URLSAFE);
|
|
}
|
|
|
|
public function testCreateDojo(): void
|
|
{
|
|
/**
|
|
*
|
|
* @var Response $response
|
|
*/
|
|
$response = static::createClient()->request('POST', '/api/dojos',
|
|
[
|
|
'headers' => [
|
|
'accept' => 'application/json',
|
|
'X-AUTH-TOKEN' => $this->generateAuthToken('blablabla')
|
|
],
|
|
'json' => [
|
|
'name' => 'FooBar'
|
|
]
|
|
]);
|
|
|
|
$this->assertResponseStatusCodeSame(201);
|
|
|
|
$userRepository = $this->getContainer()->get(UserRepository::class);
|
|
$this->assertCount(1, $userRepository->findAll());
|
|
}
|
|
}
|
|
|