mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
Add test on Comment, test on DELETE does not work as how route works is unclear, fix requirement constraint name on CommentController.
This commit is contained in:
parent
63ed7949a2
commit
da0078e547
@ -27,7 +27,7 @@ class CommentController extends FramadateController {
|
||||
* @Get(
|
||||
* path = "/poll/{id}/comments",
|
||||
* name = "get_poll_comment",
|
||||
* requirements = {"poll_id"="\d+"}
|
||||
* requirements = {"id"="\d+"}
|
||||
* )
|
||||
*/
|
||||
public
|
||||
@ -52,7 +52,7 @@ class CommentController extends FramadateController {
|
||||
* @Post(
|
||||
* path = "/poll/{id}/comment",
|
||||
* name = "new_comment",
|
||||
* requirements = {"content"="\w+", "poll_id"="\d+"}
|
||||
* requirements = {"content"="\w+", "id"="\d+"}
|
||||
* )
|
||||
*/
|
||||
public
|
||||
@ -71,13 +71,16 @@ class CommentController extends FramadateController {
|
||||
$em = $this->getDoctrine()->getRepository( Owner::class );
|
||||
|
||||
$data = json_decode( $data, true );
|
||||
if(!isset($data['email'])) {
|
||||
return $this->json(["message" => "Incorrect JSON in request"], 400);
|
||||
}
|
||||
|
||||
$foundOwner = $em->findOneByEmail( $data[ 'email' ] );
|
||||
// manage existing or new Owner
|
||||
if ( ! $foundOwner ) {
|
||||
$foundOwner = new Owner();
|
||||
$foundOwner->setPseudo( $data[ 'owner' ][ 'email' ] )
|
||||
->setEmail( $data[ 'owner' ][ 'email' ] )
|
||||
$foundOwner->setPseudo( $data[ 'email' ] )
|
||||
->setEmail( $data[ 'email' ] )
|
||||
->setModifierToken( uniqid( '', true ) );
|
||||
}
|
||||
// anti flood
|
||||
@ -142,7 +145,7 @@ class CommentController extends FramadateController {
|
||||
* @Delete(
|
||||
* path = "/poll/{id}/comments",
|
||||
* name = "poll_comments_delete",
|
||||
* requirements = {"accessToken"="\w+", "poll_id"="\d+"}
|
||||
* requirements = {"accessToken"="\w+", "id"="\d+"}
|
||||
* )
|
||||
*
|
||||
* @param Poll $poll
|
||||
|
76
tests/Functional/CommentControllerTest.php
Normal file
76
tests/Functional/CommentControllerTest.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?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 comments from one Poll
|
||||
public function testGetAllComments() {
|
||||
$client = static::createClient();
|
||||
|
||||
$this->loadFixtures(array(
|
||||
'App\DataFixtures\AppPollFixtures',
|
||||
'App\DataFixtures\CommentFixtures',
|
||||
));
|
||||
|
||||
$client->request('GET', '/api/v1/poll/1/comments');
|
||||
|
||||
$response = $client->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$body = $response->getContent();
|
||||
$json = json_decode($body, true);
|
||||
$this->assertEquals(5, count($json['data']));
|
||||
|
||||
}
|
||||
|
||||
public function testNewComment() {
|
||||
$client = static::createClient();
|
||||
|
||||
$this->loadFixtures(array(
|
||||
'App\DataFixtures\AppPollFixtures',
|
||||
'App\DataFixtures\CommentFixtures',
|
||||
));
|
||||
|
||||
$data = [
|
||||
'text' => "Mon nouveau commentaire de test !",
|
||||
'email' => "email@host.plop"
|
||||
];
|
||||
|
||||
$client->request('POST', '/api/v1/poll/1/comment', [
|
||||
'body' => json_encode($data)
|
||||
],
|
||||
[],
|
||||
[
|
||||
'CONTENT_TYPE' => 'application/json',
|
||||
'HTTP_ACCEPT' => 'application/json',
|
||||
],
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
$body = $response->getContent();
|
||||
$json = json_decode($body, true);
|
||||
$this->assertEquals("email@host.plop", $json['data']['your_comment']['pseudo']);
|
||||
}
|
||||
|
||||
public function testDeleteComments() {
|
||||
$client = static::createClient();
|
||||
|
||||
$this->loadFixtures(array(
|
||||
'App\DataFixtures\AppPollFixtures',
|
||||
'App\DataFixtures\CommentFixtures',
|
||||
));
|
||||
|
||||
|
||||
$client->request('DELETE', '/api/v1/poll/1/comments');
|
||||
$response = $client->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user