From e9b6f30dc87d162b54202b5cb926966d7fd66866 Mon Sep 17 00:00:00 2001 From: Florian Steffens Date: Fri, 27 Oct 2023 15:12:06 +0200 Subject: [PATCH] add tests for basic column creations Signed-off-by: Florian Steffens --- tests/integration/features/APIv2.feature | 30 ++++++ .../features/bootstrap/FeatureContext.php | 97 +++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/tests/integration/features/APIv2.feature b/tests/integration/features/APIv2.feature index c51b3921c..17908b7ff 100644 --- a/tests/integration/features/APIv2.feature +++ b/tests/integration/features/APIv2.feature @@ -18,3 +18,33 @@ Feature: APIv2 Then user "participant1-v2" has the following tables via v2 | updated title | Then user "participant1-v2" deletes table "t1" via v2 + + @api2 + Scenario: Basic column actions + Given table "Table 2" with emoji "👋" exists for user "participant1-v2" as "t2" via v2 + Then column from main type "text" for node type "table" and node name "t2" exists with name "c1" and following properties via v2 + | subtype | line | + | title | Beautiful text column | + | mandatory | 0 | + | description | This is a description! | + Then column from main type "text" for node type "table" and node name "t2" exists with name "c2" and following properties via v2 + | subtype | rich | + | title | Rich is cool | + | mandatory | 1 | + | description | Another description | + Then column from main type "number" for node type "table" and node name "t2" exists with name "c3" and following properties via v2 + | title | Counter | + | mandatory | 0 | + Then column from main type "number" for node type "table" and node name "t2" exists with name "c4" and following properties via v2 + | subtype | progress | + | title | Progress | + Then column from main type "number" for node type "table" and node name "t2" exists with name "c5" and following properties via v2 + | subtype | check | + | title | Checking | + Then column from main type "datetime" for node type "table" and node name "t2" exists with name "c6" and following properties via v2 + | subtype | date | + | title | A single date | + | datetimeDefault | today | + Then node with node type "table" and node name "t2" has the following columns via v2 + | Beautiful text column | Rich is cool | Counter | Progress | Checking | A single date | + Then print register diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 3cd623cf5..de9ea4f76 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -68,6 +68,7 @@ class FeatureContext implements Context { // example for a table: 'test-table' -> 5 private array $tableIds = []; private array $viewIds = []; + private array $columnIds = []; // use CommandLineTrait; @@ -290,6 +291,100 @@ public function deleteTableV2(string $user, string $tableName): void { unset($this->tableIds[$tableName]); } + /** + * @Then column from main type :columnType for node type :nodeType and node name :nodeName exists with name :columnName and following properties via v2 + * + * @param string $nodeType + * @param string $nodeName + * @param string $columnType + * @param string $columnName + * @param TableNode|null $properties + */ + public function createColumnV2(string $nodeType, string $nodeName, string $columnType, string $columnName, TableNode $properties = null): void { + $props = [ + 'baseNodeType' => $nodeType, + ]; + if($nodeType === 'table') { + $props['baseNodeId'] = $this->tableIds[$nodeName]; + } + if($nodeType === 'view') { + $props['baseNodeId'] = $this->viewIds[$nodeName]; + } + $title = null; + foreach ($properties->getRows() as $row) { + if($row[0] === 'title') { + $title = $row[1]; + } + $props[$row[0]] = $row[1]; + } + + $this->sendOcsRequest( + 'POST', + '/apps/tables/api/2/columns/'.$columnType, + $props + ); + + $newColumn = $this->getDataFromResponse($this->response)['ocs']['data']; + $this->columnIds[$columnName] = $newColumn['id']; + + Assert::assertEquals(200, $this->response->getStatusCode()); + + $this->sendOcsRequest( + 'GET', + '/apps/tables/api/2/columns/'.$newColumn['id'], + ); + + $columnToVerify = $this->getDataFromResponse($this->response)['ocs']['data']; + Assert::assertEquals(200, $this->response->getStatusCode()); + Assert::assertEquals($columnToVerify['title'], $title); + } + + /** + * @Then node with node type :nodeType and node name :nodeName has the following columns via v2 + * + * @param string $nodeType + * @param string $nodeName + * @param TableNode|null $body + */ + public function columnsForNodeV2(string $nodeType, string $nodeName, TableNode $body = null): void { + $nodeId = null; + if($nodeType === 'table') { + $nodeId = $this->tableIds[$nodeName]; + } + if($nodeType === 'view') { + $nodeId = $this->viewIds[$nodeName]; + } + + $this->sendOcsRequest( + 'GET', + '/apps/tables/api/2/columns/'.$nodeType.'/'.$nodeId + ); + + $data = $this->getDataFromResponse($this->response)['ocs']['data']; + Assert::assertEquals(200, $this->response->getStatusCode()); + + // check if tables are empty + if ($body === null) { + Assert::assertCount(0, $data); + return; + } + + // check if given tables exists + $titles = []; + foreach ($data as $d) { + $titles[] = $d['title']; + } + foreach ($body->getRows()[0] as $tableTitle) { + Assert::assertTrue(in_array($tableTitle, $titles, true)); + } + } + + // (((((((((((((((((((((((((((( END API v2 ))))))))))))))))))))))))))))))))))) + + + + + // IMPORT -------------------------- /** @@ -364,6 +459,8 @@ public function printRegister(): void { print_r($this->tableIds); echo "Views --------------------\n"; print_r($this->viewIds); + echo "Columns --------------------\n"; + print_r($this->columnIds); } /**