Skip to content

Commit

Permalink
tests: Add integration tests for archive and favorites
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Feb 23, 2024
1 parent d962301 commit 78738e3
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 13 deletions.
27 changes: 27 additions & 0 deletions tests/integration/features/APIv2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Feature: APIv2
Background:
Given user "participant1-v2" exists
Given user "participant2-v2" exists
Given user "participant3-v2" exists

@api2
Scenario: Test initial setup
Expand All @@ -15,11 +16,37 @@ Feature: APIv2
Given table "Table 1 via api v2" with emoji "👋" exists for user "participant1-v2" as "t1" via v2
Then user "participant1-v2" has the following tables via v2
| Table 1 via api v2 |
And user "participant1-v2" sees the following table attributes on table "t1"
| archived | 0 |
Then user "participant1-v2" updates table "t1" set title "updated title" and emoji "⛵︎" via v2
Then user "participant1-v2" has the following tables via v2
| updated title |
Then user "participant1-v2" updates table "t1" set archived 1 via v2
And user "participant1-v2" sees the following table attributes on table "t1"
| archived | 1 |
Then user "participant1-v2" updates table "t1" set archived 0 via v2
And user "participant1-v2" sees the following table attributes on table "t1"
| archived | 0 |
Then user "participant1-v2" deletes table "t1" via v2

@api2
Scenario: Favorite tables
Given table "Own table" with emoji "👋" exists for user "participant1-v2" as "t1" via v2
And user "participant1-v2" shares table with user "participant2-v2"
And user "participant1-v2" adds the table "t1" to favorites
And user "participant1-v2" sees the following table attributes on table "t1"
| favorite | 1 |
And user "participant2-v2" fetches table info for table "t1"
And user "participant2-v2" sees the following table attributes on table "t1"
| favorite | 0 |
When user "participant1-v2" removes the table "t1" from favorites
And user "participant1-v2" sees the following table attributes on table "t1"
| favorite | 0 |
When user "participant3-v2" adds the table "t1" to favorites
Then the last response should have a "403" status code



@api2
Scenario: Basic column actions
Given table "Table 2" with emoji "👋" exists for user "participant1-v2" as "t2" via v2
Expand Down
117 changes: 104 additions & 13 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class FeatureContext implements Context {
private array $viewIds = [];
private array $columnIds = [];

// Store data from last request to perform assertions, id is used as a key
private array $tableData = [];
private array $viewData = [];

// use CommandLineTrait;

/**
Expand Down Expand Up @@ -127,16 +131,30 @@ public function createTableV2(string $user, string $title, string $tableName, st
Assert::assertEquals($newTable['emoji'], $emoji);
Assert::assertEquals($newTable['ownership'], $user);

$tableToVerify = $this->userFetchesTableInfo($user, $tableName);
Assert::assertEquals(200, $this->response->getStatusCode());
Assert::assertEquals($tableToVerify['title'], $title);
Assert::assertEquals($tableToVerify['emoji'], $emoji);
Assert::assertEquals($tableToVerify['ownership'], $user);
}

/**
* @Given user :user fetches table info for table :tableName
*/
public function userFetchesTableInfo($user, $tableName) {
$this->setCurrentUser($user);
$tableId = $this->tableIds[$tableName];

$this->sendOcsRequest(
'GET',
'/apps/tables/api/2/tables/'.$newTable['id'],
'/apps/tables/api/2/tables/'.$tableId,
);

$tableToVerify = $this->getDataFromResponse($this->response)['ocs']['data'];
Assert::assertEquals(200, $this->response->getStatusCode());
Assert::assertEquals($tableToVerify['title'], $title);
Assert::assertEquals($tableToVerify['emoji'], $emoji);
Assert::assertEquals($tableToVerify['ownership'], $user);
$this->tableData[$tableName] = $tableToVerify;
$this->tableId = $tableToVerify['id'];

return $tableToVerify;
}

/**
Expand Down Expand Up @@ -223,20 +241,34 @@ public function initialResourcesV2(string $user, TableNode $body = null): void {

/**
* @Then user :user updates table :tableName set title :title and emoji :emoji via v2
* @Then user :user updates table :tableName set archived :archived via v2
*
* @param string $user
* @param string $title
* @param string|null $emoji
* @param string $tableName
* @throws Exception
*/
public function updateTableV2(string $user, string $title, ?string $emoji, string $tableName): void {
public function updateTableV2(string $user, string $tableName, string $title = null, ?string $emoji = null, ?bool $archived = null): void {
$this->setCurrentUser($user);

$data = ['title' => $title];
$this->sendOcsRequest(
'GET',
'/apps/tables/api/2/tables/'.$this->tableIds[$tableName],
);

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

$data = [];
if ($title !== null) {
$data['title'] = $title;
}
if ($emoji !== null) {
$data['emoji'] = $emoji;
}
if ($archived !== null) {
$data['archived'] = $archived;
}

$this->sendOcsRequest(
'PUT',
Expand All @@ -247,9 +279,10 @@ public function updateTableV2(string $user, string $title, ?string $emoji, strin
$updatedTable = $this->getDataFromResponse($this->response)['ocs']['data'];

Assert::assertEquals(200, $this->response->getStatusCode());
Assert::assertEquals($updatedTable['title'], $title);
Assert::assertEquals($updatedTable['emoji'], $emoji);
Assert::assertEquals($updatedTable['ownership'], $user);
Assert::assertEquals($updatedTable['title'], $title ?? $previousData['title']);
Assert::assertEquals($updatedTable['emoji'], $emoji ?? $previousData['emoji']);
Assert::assertEquals($updatedTable['ownership'], $user ?? $previousData['ownership']);
Assert::assertEquals($updatedTable['archived'], $archived ?? $previousData['archived']);

$this->sendOcsRequest(
'GET',
Expand All @@ -258,9 +291,12 @@ public function updateTableV2(string $user, string $title, ?string $emoji, strin

$tableToVerify = $this->getDataFromResponse($this->response)['ocs']['data'];
Assert::assertEquals(200, $this->response->getStatusCode());
Assert::assertEquals($tableToVerify['title'], $title);
Assert::assertEquals($tableToVerify['emoji'], $emoji);
Assert::assertEquals($tableToVerify['ownership'], $user);
Assert::assertEquals($tableToVerify['title'], $title ?? $previousData['title']);
Assert::assertEquals($tableToVerify['emoji'], $emoji ?? $previousData['emoji']);
Assert::assertEquals($tableToVerify['ownership'], $user ?? $previousData['ownership']);
Assert::assertEquals($tableToVerify['archived'], $archived ?? $previousData['archived']);

$this->tableData[$tableName] = $tableToVerify;
}

/**
Expand Down Expand Up @@ -1634,4 +1670,59 @@ protected function assertStatusCode(ResponseInterface $response, int $statusCode
Assert::assertEquals($statusCode, $response->getStatusCode(), $message);
}
}

/**
* @Given user :user sees the following table attributes on table :tableName
*/
public function userSeesTheFollowingTableAttributesOnTable($user, $tableName, TableNode $table) {
foreach ($table->getRows() as $row) {
$attribute = $row[0];
$value = $row[1];
if (in_array($attribute, ['archived', 'favorite'])) {
$value = (bool)$value;
}
Assert::assertEquals($value, $this->tableData[$tableName][$attribute]);
}
}

/**
* @Given user :user adds the table :tableName to favorites
*/
public function userAddsTheTableToFavorites($user, $tableName) {
$this->setCurrentUser($user);
$nodeType = 0;
$tableId = $this->tableIds[$tableName];

$this->sendOcsRequest(
'POST',
'/apps/tables/api/2/favorites/' . $nodeType. '/' . $tableId,
);
if ($this->response->getStatusCode() === 200) {
$this->userFetchesTableInfo($user, $tableName);
}
}

/**
* @Given user :user removes the table :tableName from favorites
*/
public function userRemovesTheTableFromFavorites($user, $tableName) {
$this->setCurrentUser($user);
$nodeType = 0;
$tableId = $this->tableIds[$tableName];

$this->sendOcsRequest(
'DELETE',
'/apps/tables/api/2/favorites/' . $nodeType. '/' . $tableId,
);
if ($this->response->getStatusCode() === 200) {
$this->userFetchesTableInfo($user, $tableName);
}
}

/**
* @Then /^the last response should have a "([^"]*)" status code$/
*/
public function theLastResponseShouldHaveAStatusCode(int $statusCode) {
Assert::assertEquals($statusCode, $this->response->getStatusCode());
}
}

0 comments on commit 78738e3

Please sign in to comment.