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

migration_from_v1
Sébastien Touzé 2 years ago
parent 275a836464
commit 63ed7949a2
  1. 1
      .env.test
  2. 1
      config/services.yaml
  3. 2
      src/Controller/AdminController.php
  4. 35
      tests/Functional/AdminControllerTest.php

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

@ -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

@ -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.',
],

@ -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']);
}
}
Loading…
Cancel
Save