Skip to content

Commit

Permalink
add tests for basic column creations
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>
  • Loading branch information
Florian Steffens committed Oct 27, 2023
1 parent 0df6d43 commit e9b6f30
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/integration/features/APIv2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
97 changes: 97 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 --------------------------

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit e9b6f30

Please sign in to comment.