From 0a4dcf456b5841ea4219243a7a95879e44e7c16e Mon Sep 17 00:00:00 2001 From: IanM Date: Wed, 31 Jan 2024 16:49:15 +0000 Subject: [PATCH] add unauthorized api test --- tests/integration/api/CreatePollTest.php | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/integration/api/CreatePollTest.php b/tests/integration/api/CreatePollTest.php index a0f7aa27..edcd1e6a 100644 --- a/tests/integration/api/CreatePollTest.php +++ b/tests/integration/api/CreatePollTest.php @@ -435,4 +435,45 @@ public function authorized_user_can_create_global_poll_on_api(int $userId) $this->assertTrue($json['data']['attributes']['isGlobal']); } + + /** + * @dataProvider unauthorizedUserProvider + * + * @test + */ + public function unauthorized_user_cannot_create_global_poll_on_api(int $userId) + { + $response = $this->send( + $this->request( + 'POST', + '/api/fof/polls', + [ + 'authenticatedAs' => $userId, + 'json' => [ + 'data' => [ + 'attributes' => [ + 'question' => 'Add a global poll', + 'publicPoll' => false, + 'hideVotes' => false, + 'allowChangeVote' => true, + 'allowMultipleVotes' => false, + 'maxVotes' => 0, + 'endDate' => false, + 'options' => [ + [ + 'answer' => 'Yes', + ], + [ + 'answer' => 'No', + ], + ], + ], + ], + ], + ] + ) + ); + + $this->assertEquals(403, $response->getStatusCode()); + } }