Add test for admin, fix issue on admin token parameter.

This commit is contained in:
Sébastien Touzé 2020-05-23 16:31:59 +02:00
parent 275a836464
commit 63ed7949a2
4 changed files with 38 additions and 1 deletions

View File

@ -3,3 +3,4 @@ KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
ADMIN_TOKEN=testAdminToken

View File

@ -4,6 +4,7 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
admin_token: '%env(resolve:ADMIN_TOKEN)%'
services:
# default configuration for services in *this* file

View File

@ -34,7 +34,7 @@ class AdminController extends FramadateController {
function cleanExpiredPolls(
string $token
) {
if ( $this->getParameter( 'ADMIN_TOKEN' ) !== $token ) {
if ( $this->getParameter( 'admin_token' ) !== $token ) {
return $this->json( [
'message' => 'clean routine can NOT be done, your admin token is bad, and you should feel bad.',
],

View File

@ -0,0 +1,35 @@
<?php
namespace App\Tests\Functional;
use Liip\TestFixturesBundle\Test\FixturesTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AdminControllerTest extends WebTestCase {
use FixturesTrait;
// Test getting all polls
public function testGetAllPolls() {
$client = static::createClient();
$this->loadFixtures(array(
'App\DataFixtures\AppPollFixtures'
));
$client->request('GET', '/admin/polls/clean/testAdminToken');
$response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$body = $response->getContent();
$json = json_decode($body, true);
$this->assertEquals(4, $json['data']['count']);
//This call is supposed to be nilpotent
$client->request('GET', '/admin/polls/clean/testAdminToken');
$response = $client->getResponse();
$json = json_decode($response->getContent(), true);
$this->assertEquals(0, $json['data']['count']);
}
}