From e7c28bf9fe2a32524a93a03eac9c083925be0874 Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Thu, 5 Dec 2024 13:32:00 +0100 Subject: [PATCH] fixup! feat(polls): allow editing of draft polls --- .../features/bootstrap/FeatureContext.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 26db9d526fe..0dfb3834538 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -2510,6 +2510,45 @@ public function createPoll(string $user, string $identifier, string $statusCode, } } + /** + * @Then /^user "([^"]*)" updates a draft poll in room "([^"]*)" with (\d+)(?: \((v1)\))?$/ + * + * @param string $user + * @param string $identifier + * @param string $statusCode + * @param string $apiVersion + */ + public function updateDraftPoll(string $user, string $identifier, string $statusCode, string $apiVersion = 'v1', ?TableNode $formData = null): void { + $data = $formData->getRowsHash(); + $data['options'] = json_decode($data['options'], true); + if ($data['resultMode'] === 'public') { + $data['resultMode'] = 0; + } elseif ($data['resultMode'] === 'hidden') { + $data['resultMode'] = 1; + } else { + throw new \Exception('Invalid result mode'); + } + if ($data['maxVotes'] === 'unlimited') { + $data['maxVotes'] = 0; + } + + $this->setCurrentUser($user); + $this->sendRequest( + 'POST', '/apps/spreed/api/' . $apiVersion . '/poll/' . self::$identifierToToken[$identifier] . '/draft/'. self::$questionToPollId[$data['question']], + $data + ); + $this->assertStatusCode($this->response, $statusCode); + + if ($statusCode !== '200' && $statusCode !== '201') { + return; + } + + $response = $this->getDataFromResponse($this->response); + if (isset($response['id'])) { + self::$questionToPollId[$data['question']] = $response['id']; + } + } + /** * @Then /^user "([^"]*)" gets poll drafts for room "([^"]*)" with (\d+)(?: \((v1)\))?$/ *