Skip to content

Commit

Permalink
test(integration): add scenarios for content manipulation via contexts
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Jun 28, 2024
1 parent ca76dcf commit 098f870
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 14 deletions.
49 changes: 49 additions & 0 deletions tests/integration/features/APIv2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,55 @@ Feature: APIv2
When user "participant3-v2" attempts to fetch Context "c1"
Then the reported status is "404"

@api2 @contexts @current
Scenario: Add a row to both a table and a view through a context
Given table "Table 1 via api v2" with emoji "👋" exists for user "participant1-v2" as "t1" via v2
And column "one" exists with following properties
| type | text |
| subtype | line |
| mandatory | 0 |
| description | This is a description! |
And column "two" exists with following properties
| type | number |
| mandatory | 1 |
| numberDefault | 10 |
| description | This is a description! |
And column "three" exists with following properties
| type | selection |
| subtype | check |
| mandatory | 1 |
| description | This is a description! |
And column "four" exists with following properties
| type | datetime |
| subtype | date |
| mandatory | 0 |
| description | This is a description! |
And user "participant1-v2" create view "v1" with emoji "⚡️" for "t1" as "v1"
And user "participant1-v2" creates the Context "c1" with name "Enchanting Guitar" with icon "tennis" and description "Lorem ipsum dolor etc pp" and nodes:
| alias | type | permissions |
| t1 | table | read,create,update |
| v1 | view | read,create |
And user "participant1-v2" shares the Context "c1" to "user" "participant2-v2"
When user "participant2-v2" tries to create a row using v2 on "table" "t1" with following values
| one | AHA |
| two | 161 |
| three | true |
| four | 2023-12-24 |
Then the reported status is 200
When user "participant2-v2" tries to create a row using v2 on "view" "v1" with following values
| one | PHP |
| two | 666 |
| three | false |
| four | 2024-04-24 |
Then the reported status is 200
When user "participant1-v1" fetches the rows from "table" "t1"
Then there should be a row with following values:
| one | AHA |
| two | 161 |
| three | true |
| four | 2023-12-24 |


@api2 @rows
Scenario: Create rows via v2 and check them
Given table "Rows check" with emoji "👨🏻‍💻" exists for user "participant1-v2" as "base1" via v2
Expand Down
84 changes: 70 additions & 14 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function __construct() {
public function setUp() {
$this->createdUsers = [];
$this->createdGroups = [];
$this->tableId = null;
}

/**
Expand Down Expand Up @@ -163,6 +164,57 @@ public function userFetchesTableInfo($user, $tableName) {
return $tableToVerify;
}

/**
* @When user :user fetches the rows from :nodeType :nodeAlias
*/
public function userFetchesRowsFromNode(string $user, string $nodeType, string $nodeAlias) {
$this->setCurrentUser($user);
$node = $this->collectionManager->getByAlias($nodeType, $nodeAlias);

$collection = $nodeType . 's';

$this->sendRequest(
'GET',
sprintf('/apps/tables/api/2/%s/%d/rows', $collection, $node['id'])
);

$data = $this->getDataFromResponse($this->response);
$this->collectionManager->register($data, $nodeType . '-rows', $node['id']);
$this->collectionManager->register(['type' => $nodeType, 'item' => $node], 'currentNode', 0);
}

/**
* @Then there should be a row with following values:
*/
public function thereShouldBeARowWithFollowingValues(TableNode $rowValues) {
$nodeMeta = $this->collectionManager->getById('currentNode', 0);
$columns = $this->getColumnsForNode($nodeMeta['type'], $nodeMeta['item']['id']);

$expectedColumns = array_combine($rowValues->getColumn(0), $rowValues->getColumn(1));
$resultColumns = [];
foreach ($columns as $column) {
if (isset($expectedColumns[$column['title']])) {
$resultColumns[] = ['columnId' => $column['id'], 'value' => $expectedColumns[$column['title']]];
unset($expectedColumns[$column['title']]);
}
}
Assert::assertCount(0, $expectedColumns, 'not all expected columns are valid');

$actualRowData = $this->collectionManager->getById($nodeMeta['type'] . '-rows', $nodeMeta['item']['id']);
foreach ($actualRowData as $row) {
$found = true;
foreach ($resultColumns as $column) {
$found = $found && in_array($column, $row['data'], true);
}
if ($found) {
Assert::assertTrue(true);
return;
}
}

Assert::assertTrue(false, 'Expected row was not found');
}

/**
* @Then user :user has the following tables via v2
*
Expand Down Expand Up @@ -426,28 +478,31 @@ public function createColumnV2(string $nodeType, string $nodeName, string $colum
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 {
protected function getColumnsForNode(string $nodeType, string $nodeAlias): array {
$nodeId = null;
if($nodeType === 'table') {
$nodeId = $this->tableIds[$nodeName];
}
if($nodeType === 'view') {
$nodeId = $this->viewIds[$nodeName];
$nodeId = $this->tableIds[$nodeAlias];
} else if($nodeType === 'view') {
$nodeId = $this->viewIds[$nodeAlias];
}

$this->sendOcsRequest(
'GET',
'/apps/tables/api/2/columns/'.$nodeType.'/'.$nodeId
sprintf('/apps/tables/api/2/columns/%s/%s', $nodeType, $nodeId),
);

$data = $this->getDataFromResponse($this->response)['ocs']['data'];
return $this->getDataFromResponse($this->response)['ocs']['data'];
}

/**
* @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 {
$data = $this->getColumnsForNode($nodeType, $nodeName);
Assert::assertEquals(200, $this->response->getStatusCode());

// check if tables are empty
Expand Down Expand Up @@ -1264,6 +1319,7 @@ public function createRow(?TableNode $properties = null): void {
*/
public function userTriesToCreateRowUsingV2OnNodeXWithFollowingValues(string $user, string $nodeType, string $nodeAlias, TableNode $properties): void {
$this->setCurrentUser($user);
// FIXME: tables are not in collectionManager yet
$node = $this->collectionManager->getByAlias($nodeType, $nodeAlias);

$props = [];
Expand Down

0 comments on commit 098f870

Please sign in to comment.