diff --git a/src/Api/Serializers/PollSerializer.php b/src/Api/Serializers/PollSerializer.php index 82d04354..52a7bcdd 100755 --- a/src/Api/Serializers/PollSerializer.php +++ b/src/Api/Serializers/PollSerializer.php @@ -12,7 +12,6 @@ namespace FoF\Polls\Api\Serializers; use Flarum\Api\Serializer\AbstractSerializer; -use Flarum\Api\Serializer\PostSerializer; use FoF\Polls\Poll; class PollSerializer extends AbstractSerializer diff --git a/tests/integration/api/CreatePollTest.php b/tests/integration/api/CreatePollTest.php index 21a76778..94853c2f 100644 --- a/tests/integration/api/CreatePollTest.php +++ b/tests/integration/api/CreatePollTest.php @@ -1,5 +1,14 @@ prepareDatabase([ 'users' => [ $this->normalUser(), - ['id' => 3, 'username' => 'polluser', 'email' => 'polluser@machine.local', 'password' => 'too-obscure', 'is_email_confirmed' => true] + ['id' => 3, 'username' => 'polluser', 'email' => 'polluser@machine.local', 'password' => 'too-obscure', 'is_email_confirmed' => true], ], 'discussions' => [ ['id' => 1, 'title' => 'Discussion 1', 'comment_count' => 1, 'participant_count' => 1, 'created_at' => '2021-01-01 00:00:00'], @@ -40,7 +49,7 @@ private function authorizedUserProvider(): array { return [ [1], - [3] + [3], ]; } @@ -53,6 +62,7 @@ private function unauthorizedUserProvider(): array /** * @dataProvider authorizedUserProvider + * * @test */ public function authorized_user_can_create_poll_in_post(int $userId) @@ -63,19 +73,19 @@ public function authorized_user_can_create_poll_in_post(int $userId) '/api/posts', [ 'authenticatedAs' => $userId, - 'json' => [ + 'json' => [ 'data' => [ 'attributes' => [ 'content' => 'Here is my poll', - 'poll' => [ - 'question' => 'What is your favourite colour?', - 'publicPoll' => false, - 'hideVotes' => false, - 'allowChangeVote' => true, + 'poll' => [ + 'question' => 'What is your favourite colour?', + 'publicPoll' => false, + 'hideVotes' => false, + 'allowChangeVote' => true, 'allowMultipleVotes' => false, - 'maxVotes' => 0, - 'endDate' => false, - 'options' => [ + 'maxVotes' => 0, + 'endDate' => false, + 'options' => [ [ 'answer' => 'Red', ], @@ -92,11 +102,11 @@ public function authorized_user_can_create_poll_in_post(int $userId) 'discussion' => [ 'data' => [ 'type' => 'discussions', - 'id' => 1, + 'id' => 1, ], ], - ] - ] + ], + ], ], ] ) @@ -121,7 +131,7 @@ public function authorized_user_can_create_poll_in_post(int $userId) $response = $this->send( $this->request( 'GET', - '/api/fof/polls/' . $pollId, + '/api/fof/polls/'.$pollId, [ 'authenticatedAs' => $userId, ] @@ -137,6 +147,7 @@ public function authorized_user_can_create_poll_in_post(int $userId) /** * @dataProvider unauthorizedUserProvider + * * @test */ public function unauthorized_user_cannot_create_poll_in_post(int $userId) @@ -147,19 +158,19 @@ public function unauthorized_user_cannot_create_poll_in_post(int $userId) '/api/posts', [ 'authenticatedAs' => $userId, - 'json' => [ + 'json' => [ 'data' => [ 'attributes' => [ 'content' => 'Here is my poll', - 'poll' => [ - 'question' => 'What is your favourite colour?', - 'publicPoll' => false, - 'hideVotes' => false, - 'allowChangeVote' => true, + 'poll' => [ + 'question' => 'What is your favourite colour?', + 'publicPoll' => false, + 'hideVotes' => false, + 'allowChangeVote' => true, 'allowMultipleVotes' => false, - 'maxVotes' => 0, - 'endDate' => false, - 'options' => [ + 'maxVotes' => 0, + 'endDate' => false, + 'options' => [ [ 'answer' => 'Red', ], @@ -176,11 +187,11 @@ public function unauthorized_user_cannot_create_poll_in_post(int $userId) 'discussion' => [ 'data' => [ 'type' => 'discussions', - 'id' => 1, + 'id' => 1, ], ], - ] - ] + ], + ], ], ] )