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.
57 lines
1.8 KiB
57 lines
1.8 KiB
11 months ago
|
<?php
|
||
|
namespace App\Tests;
|
||
|
|
||
|
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
||
|
use ApiPlatform\Symfony\Bundle\Test\Response;
|
||
|
use App\Factory\UserFactory;
|
||
|
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
|
||
|
{
|
||
|
UserFactory::createOne([
|
||
|
'authName' => "blablabla"
|
||
|
]);
|
||
|
|
||
|
$userRepository = $this->getContainer()->get(UserRepository::class);
|
||
|
$this->assertCount(1, $userRepository->findAll());
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @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);
|
||
|
}
|
||
|
}
|
||
|
|