mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
Add tests for Pool, some are not fully working. Fix a crash on new_poll when request is incorrect.
This commit is contained in:
parent
bbad384474
commit
275a836464
@ -10,6 +10,7 @@ use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
use FOS\RestBundle\Controller\Annotations\Put;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\Exception\RuntimeException;
|
||||
use JMS\Serializer\SerializerBuilder;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
use Swift_Mailer;
|
||||
@ -142,7 +143,11 @@ class PollController extends FramadateController {
|
||||
$data = $request->getContent();
|
||||
|
||||
$serializer = SerializerBuilder::create()->build();
|
||||
try {
|
||||
$newpoll = $serializer->deserialize( $data, 'App\Entity\Poll', 'json' );
|
||||
} catch(RuntimeException $e) {
|
||||
return $this->json(["message" => "Incorrect JSON in request"], 400);
|
||||
}
|
||||
$newpoll
|
||||
->setAdminKey( $newpoll->generateAdminKey() )
|
||||
->setCreationDate( new DateTime() )
|
||||
|
@ -123,8 +123,43 @@ class PollControllerTest extends WebTestCase {
|
||||
|
||||
// Test Post new poll
|
||||
public function testPostOnePoll() {
|
||||
//TODO
|
||||
$client = static::createClient();
|
||||
|
||||
$this->loadFixtures(array(
|
||||
'App\DataFixtures\AppPollFixtures'
|
||||
));
|
||||
|
||||
$client->request('POST', '/api/v1/poll/', [
|
||||
'json' => [
|
||||
"title" => "Fromage ou dessert ? ",
|
||||
"description" => "Votre plat préféré",
|
||||
"creation_date" => "2048-04-25T16:19:48+02:00",
|
||||
"expiracy_date" => "2048-04-25T16:19:48+02:00",
|
||||
"kind" => "text",
|
||||
"allowed_answers" => [
|
||||
"yes"
|
||||
],
|
||||
"modification_policy" => "nobody",
|
||||
"mail_on_vote" => true,
|
||||
"choices" => [
|
||||
[
|
||||
"id" => 1,
|
||||
"name" => "fromage"
|
||||
],
|
||||
[
|
||||
"id" => 2,
|
||||
"name" => "dessert"
|
||||
]
|
||||
],
|
||||
"default_expiracy_days_from_now" => 365
|
||||
]
|
||||
]);
|
||||
|
||||
$response = $client->getResponse();
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
|
||||
$data = $response->getContent();
|
||||
$this->assertIsNumeric($data['poll']['id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user