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.

132 lines
3.7 KiB

<?php
namespace App\Tests;
use App\Factory\DojoFactory;
use App\Factory\UserFactory;
use App\Repository\UserRepository;
class DojoTest extends AbstractTest
{
/**
* Requirement: A user should be able to create a dojo!
*/
public function testCreateDojo(): void
{
$userName = "FooBarFigher";
$dojoName = "BigFightDojo";
$userRepository = $this->getContainer()->get(UserRepository::class);
$this->assertCount(0, $userRepository->findByAuthName($userName));
static::createClientWithToken($userName)->request('POST', '/api/dojos', [
'json' => [
'name' => $dojoName
]
]);
$this->assertResponseStatusCodeSame(201);
11 months ago
$this->assertCount(1, $userRepository->findByAuthName($userName));
}
/**
* Requirement: A user should be request his own dojo!
*/
public function testUserReadDojo(): void
{
$userName = "FooBarFigher";
$dojoName = "BigFightDojo";
$dojo = DojoFactory::createOne(
[
'name' => $dojoName,
'owner' => UserFactory::createOne([
'authName' => $userName
])
]);
static::createClientWithToken($userName)->request('GET', '/api/dojo');
$this->assertResponseStatusCodeSame(200);
$this->assertJsonContains(
[
'name' => 'BigFightDojo',
'members' => [],
'owner' => $this->getIri($dojo->getOwner()),
'id' => $dojo->getId()
->toBase32()
]);
}
/**
* Requirement: A user should be request his own dojo!
* Fails, if the dojo is not yet created.
*/
public function testUserReadDojoNotYetCreated(): void
{
$userName = "FooBarFigher";
$userRepository = $this->getContainer()->get(UserRepository::class);
$this->assertCount(0, $userRepository->findByAuthName($userName));
static::createClientWithToken($userName)->request('GET', '/api/dojo');
$this->assertResponseStatusCodeSame(404);
}
/**
* 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::createClientWithToken($userName)->request('POST', '/api/dojos', [
'json' => [
'name' => $dojoName
]
]);
$this->assertResponseStatusCodeSame(409); // 409 Conflict
}
/**
* Requirement: A user should be able to change the dojos name!
* FIXME: Add limitation so users will not do this frequently.
*/
public function testChangeDojoName(): void
{
$userName = "FooBarFigher";
$dojoName = "BigFightDojo";
$newDojoName = "BigFightDojo";
$dojo = DojoFactory::createOne(
[
'name' => $dojoName,
'owner' => UserFactory::createOne([
'authName' => $userName
])
]);
static::createClientWithToken($userName)->request('PATCH', '/api/dojos/' . $dojo->id,
[
'headers' => [
'content-type' => 'application/merge-patch+json'
],
'json' => [
'name' => $newDojoName
]
]);
$this->assertResponseStatusCodeSame(200);
}
}