Skip to content

Bug - Fixed falsy E2E test case #2847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions tests/E2E/Controller/v1/Profile/GroupsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ static function (stdClass $userGroup): string {
* @throws JsonException
*/
#[DataProvider('dataProviderTestThatGroupsActionReturnExpectedWithValidApiKey')]
#[TestDox('Test that `GET /v1/profile/groups` request returns `401` with valid `$token` API key token')]
public function testThatGroupsActionReturnExpectedWithValidApiKey(string $token): void
#[TestDox(
'Test that `GET /v1/profile/groups` request returns `401` with valid `$token` API key token ($role - role)'
)]
public function testThatGroupsActionReturnExpectedWithValidApiKey(string $token, string $role): void
{
$client = $this->getApiKeyClient($token);
$client = $this->getApiKeyClient($role);
$client->request('GET', $this->baseUrl);

$response = $client->getResponse();
Expand All @@ -163,7 +165,7 @@ public function testThatGroupsActionReturnExpectedWithValidApiKey(string $token)
self::assertSame(401, $responseContent->code, 'Response code was not expected' . $info);
self::assertTrue(property_exists($responseContent, 'message'), 'Response does not contain "message"' . $info);
self::assertSame(
'JWT Token not found',
'Invalid API key',
$responseContent->message,
'Response message was not expected' . $info,
);
Expand Down Expand Up @@ -192,20 +194,20 @@ public static function dataProviderTestThatGroupsActionReturnExpected(): Generat
}

/**
* @return Generator<array-key, array{0: string}>
*
* @throws Throwable
*
* @return Generator<array-key, array{0: string, 1: string}>
*/
public static function dataProviderTestThatGroupsActionReturnExpectedWithValidApiKey(): Generator
{
$rolesService = self::getRolesService();

if (getenv('USE_ALL_USER_COMBINATIONS') === 'yes') {
foreach ($rolesService->getRoles() as $role) {
yield [str_pad($rolesService->getShort($role), 40, '_')];
yield [str_pad($rolesService->getShort($role), 40, '_'), $role];
}
} else {
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_')];
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_'), Role::LOGGED->value];
}
}

Expand Down
17 changes: 9 additions & 8 deletions tests/E2E/Controller/v1/Profile/IndexControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ public function testThatProfileActionReturns401WithInvalidApiKey(): void
* @throws JsonException
*/
#[DataProvider('dataProviderTestThatProfileActionReturnsExpectedWithValidApiKeyToken')]
#[TestDox('Test that `GET /v1/profile` request returns `401` with valid `$token` API key token')]
public function testThatProfileActionReturnsExpectedWithValidApiKeyToken(string $token): void
#[TestDox('Test that `GET /v1/profile` request returns `401` with valid `$token` API key token ($role - role)')]
public function testThatProfileActionReturnsExpectedWithValidApiKeyToken(string $token, string $role): void
{
$client = $this->getApiKeyClient($token);

$client = $this->getApiKeyClient($role);
$client->request('GET', $this->baseUrl);

$response = $client->getResponse();
Expand All @@ -134,7 +135,7 @@ public function testThatProfileActionReturnsExpectedWithValidApiKeyToken(string
self::assertSame(401, $responseContent->code, 'Response code was not expected' . $info);
self::assertTrue(property_exists($responseContent, 'message'), 'Response does not contain "message"' . $info);
self::assertSame(
'JWT Token not found',
'Invalid API key',
$responseContent->message,
'Response message was not expected' . $info,
);
Expand Down Expand Up @@ -167,20 +168,20 @@ public static function dataProviderTestThatProfileActionReturnExpectedWithValidU
}

/**
* @return Generator<array-key, array{0: string}>
*
* @throws Throwable
*
* @return Generator<array-key, array{0: string, 1: string}>
*/
public static function dataProviderTestThatProfileActionReturnsExpectedWithValidApiKeyToken(): Generator
{
$rolesService = self::getRolesService();

if (getenv('USE_ALL_USER_COMBINATIONS') === 'yes') {
foreach ($rolesService->getRoles() as $role) {
yield [str_pad($rolesService->getShort($role), 40, '_')];
yield [str_pad($rolesService->getShort($role), 40, '_'), $role];
}
} else {
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_')];
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_'), Role::LOGGED->value];
}
}

Expand Down
16 changes: 9 additions & 7 deletions tests/E2E/Controller/v1/Profile/RolesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ public function testThatRolesActionReturnsExpected(string $u, string $p, Stringa
* @throws JsonException
*/
#[DataProvider('dataProviderTestThatRolesActionReturnsExpectedWithValidApiKey')]
#[TestDox('Test that `GET /v1/profile/roles` request returns `401` with valid API key `$token` token')]
public function testThatRolesActionReturnsExpectedWithValidApiKey(string $token): void
#[TestDox(
'Test that `GET /v1/profile/roles` request returns `401` with valid API key `$token` token ($role - role)'
)]
public function testThatRolesActionReturnsExpectedWithValidApiKey(string $token, string $role): void
{
$client = $this->getApiKeyClient($token);
$client = $this->getApiKeyClient($role);
$client->request('GET', $this->baseUrl);

$response = $client->getResponse();
Expand All @@ -135,7 +137,7 @@ public function testThatRolesActionReturnsExpectedWithValidApiKey(string $token)
self::assertSame(401, $responseContent->code, 'Response code was not expected' . $info);
self::assertTrue(property_exists($responseContent, 'message'), 'Response does not contain "message"' . $info);
self::assertSame(
'JWT Token not found',
'Invalid API key',
$responseContent->message,
'Response message was not expected' . $info,
);
Expand Down Expand Up @@ -212,7 +214,7 @@ public static function dataProviderTestThatRolesActionReturnsExpected(): Generat
}

/**
* @return Generator<array-key, array{0: string}>
* @return Generator<array-key, array{0: string, 1: string}>
*
* @throws Throwable
*/
Expand All @@ -222,10 +224,10 @@ public static function dataProviderTestThatRolesActionReturnsExpectedWithValidAp

if (getenv('USE_ALL_USER_COMBINATIONS') === 'yes') {
foreach ($rolesService->getRoles() as $role) {
yield [str_pad($rolesService->getShort($role), 40, '_')];
yield [str_pad($rolesService->getShort($role), 40, '_'), $role];
}
} else {
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_')];
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_'), Role::LOGGED->value];
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/E2E/TestCase/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace App\Tests\E2E\TestCase;

use App\Enum\Role;
use App\Utils\JSON;
use JsonException;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
Expand Down
Loading