Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Update tests with ROLE_GAME permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeKESTEMAN committed Aug 25, 2022
1 parent aefed84 commit b70743c
Show file tree
Hide file tree
Showing 25 changed files with 1,519 additions and 172 deletions.
8 changes: 7 additions & 1 deletion api/fixtures/test/test-game.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
App\Entity\Game:
game_{1..59}:
game_{1..58}:
tweet: '@tweet_<current()>'
player: '@player_<current()>'
reward: '@reward_<current()>'
playDate: '<dateTimeBetween("-30 days", "now")>'
game_59:
tweet: '@tweet_59'
player: '@player_59'
reward: '@reward_59'
playDate: <identity(new \DateTime('2022-01-01 12:00:00.000000'))>

game_60:
tweet: '@tweet_60'
player: '@player_60'
Expand Down
14 changes: 12 additions & 2 deletions api/fixtures/test/test-lot.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
App\Entity\Lot:
lot_{1..59}:
lot_{1..58}:
name (unique): <word()>
quantity: <numberBetween(1, 100)>
message: <sentence()>

lot_60:
lot_59:
name (unique): 'Lot de test'
quantity: <numberBetween(1, 100)>
message: <sentence()>

lot_60:
name (unique): 'Lot de test pour game'
quantity: <numberBetween(1, 100)>
message: <sentence()>

lot_61:
name (unique): 'Supprime moi !'
quantity: <numberBetween(1, 100)>
message: <sentence()>

lot_62:
name (unique): 'Supprime moi game !'
quantity: <numberBetween(1, 100)>
message: <sentence()>
6 changes: 5 additions & 1 deletion api/fixtures/test/test-media_object.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
App\Entity\MediaObject:
media_object:
media_object_admin:
name: <name()>
filePath: 'image.png'

media_object_game:
name: <name()>
filePath: 'game_image.png'
4 changes: 4 additions & 0 deletions api/fixtures/test/test-tweet_reply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ App\Entity\TweetReply:
tweet_reply:
name (unique): on_new_game
message: <sentence()>

tweet_reply_game:
name (unique): no_more_available_lots
message: <sentence()>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Tests\Api;
namespace App\Tests\Api\ROLE_ADMIN;

use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use App\Entity\Game;
Expand All @@ -25,9 +25,9 @@ final class GameTest extends ApiTestCase
*/
public function testGetCollection(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$response = static::createClient()->request('GET', '/games', ['auth_bearer' => $token]);
$response = self::createClient()->request('GET', '/games', ['auth_bearer' => $token]);

self::assertResponseIsSuccessful();
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
Expand Down Expand Up @@ -60,11 +60,11 @@ public function testGetCollection(): void
*/
public function testGetGame(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$iri = $this->findIriBy(Game::class, ['playDate' => new DateTime('2022-01-01 12:30:00.000000')]);

static::createClient()->request('GET', $iri, ['auth_bearer' => $token]);
self::createClient()->request('GET', $iri, ['auth_bearer' => $token]);

self::assertResponseIsSuccessful();
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
Expand All @@ -78,15 +78,22 @@ public function testGetGame(): void

/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testCreateGame(): void
{
static::createClient()->request('POST', '/games', ['json' => [
'playDate' => new DateTime('2022-01-01 12:35:00.000000'),
]]);
$token = LoginTest::getAdminLoginToken();

self::createClient()->request('POST', '/games', [
'auth_bearer' => $token,
'json' => [
'playDate' => new DateTime('2022-01-01 12:35:00.000000'),
]
]
);

self::assertResponseStatusCodeSame(405);
}
Expand All @@ -100,15 +107,15 @@ public function testCreateGame(): void
*/
public function testUpdateGame(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$iri = $this->findIriBy(Game::class, ['playDate' => new DateTime('2022-01-01 12:30:00.000000')]);
$iri = $this->findIriBy(Game::class, ['playDate' => new DateTime('2022-01-01 12:00:00.000000')]);

static::createClient()->request('PUT', $iri, [
self::createClient()->request('PUT', $iri, [
'auth_bearer' => $token,
'json' => [
'score' => 10,
], ]);
],]);

self::assertResponseIsSuccessful();
self::assertJsonContains([
Expand All @@ -126,27 +133,36 @@ public function testUpdateGame(): void
*/
public function testFailedToReupdateGame(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$iri = $this->findIriBy(Game::class, ['playDate' => new DateTime('2022-01-01 12:30:00.000000')]);
$iri = $this->findIriBy(Game::class, ['playDate' => new DateTime('2022-01-01 12:00:00.000000')]);

static::createClient()->request('PUT', $iri, [
self::createClient()->request('PUT', $iri, [
'auth_bearer' => $token,
'json' => [
'score' => 11,
], ]);
],]);

self::assertResponseStatusCodeSame(403);
}

/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
* @throws DecodingExceptionInterface
*/
public function testDeleteGame(): void
{
$iri = $this->findIriBy(Game::class, ['playDate' => new DateTime('2022-01-01 12:30:00.000000')]);
$token = LoginTest::getAdminLoginToken();

$iri = $this->findIriBy(Game::class, ['playDate' => new DateTime('2022-01-01 12:00:00.000000')]);

static::createClient()->request('DELETE', $iri);
self::createClient()->request('DELETE', $iri, [
'auth_bearer' => $token,
]
);

self::assertResponseStatusCodeSame(405);
}
Expand Down
34 changes: 17 additions & 17 deletions api/tests/Api/LotTest.php → api/tests/Api/ROLE_ADMIN/LotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Tests\Api;
namespace App\Tests\Api\ROLE_ADMIN;

use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use App\Entity\Lot;
Expand All @@ -25,9 +25,9 @@ final class LotTest extends ApiTestCase
*/
public function testGetCollection(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$response = static::createClient()->request('GET', '/lots', ['auth_bearer' => $token]);
$response = self::createClient()->request('GET', '/lots', ['auth_bearer' => $token]);

self::assertResponseIsSuccessful();
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
Expand All @@ -36,7 +36,7 @@ public function testGetCollection(): void
'@context' => '/contexts/Lot',
'@id' => '/lots',
'@type' => 'hydra:Collection',
'hydra:totalItems' => 61,
'hydra:totalItems' => 62,
'hydra:view' => [
'@id' => '/lots?page=1',
'@type' => 'hydra:PartialCollectionView',
Expand All @@ -60,9 +60,9 @@ public function testGetCollection(): void
*/
public function testGetLot(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$client = static::createClient();
$client = self::createClient();
$iri = $this->findIriBy(Lot::class, ['name' => 'Lot de test']);

$client->request('GET', $iri, ['auth_bearer' => $token]);
Expand All @@ -86,9 +86,9 @@ public function testGetLot(): void
*/
public function testCreateLotWithInvalidQuantity(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$response = static::createClient()->request('POST', '/lots', [
self::createClient()->request('POST', '/lots', [
'auth_bearer' => $token,
'json' => [
'name' => 'Nouveau lot de test',
Expand Down Expand Up @@ -117,9 +117,9 @@ public function testCreateLotWithInvalidQuantity(): void
*/
public function testCreateLot(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$response = static::createClient()->request('POST', '/lots', [
$response = self::createClient()->request('POST', '/lots', [
'auth_bearer' => $token,
'json' => [
'name' => 'Nouveau lot de test',
Expand Down Expand Up @@ -152,9 +152,9 @@ public function testCreateLot(): void
*/
public function testUpdateLot(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$client = static::createClient();
$client = self::createClient();
$iri = $this->findIriBy(Lot::class, ['name' => 'Lot de test']);

$client->request('PUT', $iri, [
Expand Down Expand Up @@ -182,9 +182,9 @@ public function testUpdateLot(): void
*/
public function testFailedDeleteLot(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$client = static::createClient();
$client = self::createClient();
$iri = $this->findIriBy(Lot::class, ['name' => 'Lot de test 2.0']);

$client->request('DELETE', $iri, ['auth_bearer' => $token]);
Expand All @@ -200,17 +200,17 @@ public function testFailedDeleteLot(): void
*/
public function testDeleteLot(): void
{
$token = LoginTest::getLoginToken();
$token = LoginTest::getAdminLoginToken();

$client = static::createClient();
$client = self::createClient();
$iri = $this->findIriBy(Lot::class, ['name' => 'Supprime moi !']);

$client->request('DELETE', $iri, ['auth_bearer' => $token]);

self::assertResponseStatusCodeSame(204);

$this->assertNull(
static::getContainer()->get('doctrine')->getRepository(Lot::class)->findOneBy(['name' => 'Supprime moi !'])
self::getContainer()->get('doctrine')->getRepository(Lot::class)->findOneBy(['name' => 'Supprime moi !'])
);
}
}
Loading

0 comments on commit b70743c

Please sign in to comment.