Skip to content

Commit

Permalink
add test coverage for activities api for a file
Browse files Browse the repository at this point in the history
  • Loading branch information
Salipa-Gurung committed Jul 25, 2024
1 parent 3787092 commit 065c4fa
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2293,4 +2293,31 @@ public static function getPermissionRoleDefinition(
self::getRequestHeaders()
);
}

/**
* @param string $baseUrl
* @param string $requestId
* @param string $user
* @param string $password
* @param string $resourceId
*
* @return ResponseInterface
*/
public static function getActivities(
string $baseUrl,
string $requestId,
string $user,
string $password,
string $resourceId
): ResponseInterface {
// 'kql=itemId' filter is required for the current implementation but it might change in future
// See: https://github.com/owncloud/ocis/issues/9194
$fullUrl = self::getBetaFullUrl($baseUrl, "extensions/org.libregraph/activities?kql=itemid%3A$resourceId");
return HttpRequestHelper::get(
$fullUrl,
$requestId,
$user,
$password
);
}
}
99 changes: 99 additions & 0 deletions tests/acceptance/features/apiGraph/activities.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Feature: check activities
As a user
I want to check who made which changes to files
So that I can track modifications


Scenario: check activities after uploading a file
Given user "Alice" has been created with default attributes and without skeleton files
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt"
When user "Alice" checks the activities for file "textfile0.txt" in space "Personal" using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
{
"type": "object",
"required": ["value"],
"properties": {
"value": {
"type": "array",
"minItems": 1,
"maxItems": 1,
"items": {
"type": "object",
"required": ["id","template","times"],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
},
"template": {
"type": "object",
"required": ["message","variables"],
"properties": {
"message": {
"const": "{user} added {resource} to {space}"
},
"variables": {
"type": "object",
"required": ["resource","space","user"],
"properties": {
"resource": {
"type": "object",
"required": ["id","name"],
"properties": {
"id": {
"type": "string",
"pattern": "%file_id_pattern%"
},
"name": {
"const": "textfile0.txt"
}
}
},
"space": {
"type": "object",
"required": ["id","name"],
"properties": {
"id": {
"type": "string",
"pattern": "^%user_id_pattern%!%user_id_pattern%$"
},
"name": {
"const": "Alice Hansen"
}
}
},
"user": {
"type": "object",
"required": ["id","displayName"],
"properties": {
"id": {
"type": "string",
"pattern": "%user_id_pattern%"
},
"displayName": {
"const": "Alice"
}
}
}
}
}
}
},
"times": {
"type": "object",
"required": ["recordedTime"],
"properties": {
"recordedTime": {
"type": "string",
"format": "date-time"
}
}
}
}
}
}
}
}
"""
23 changes: 23 additions & 0 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2775,4 +2775,27 @@ public function getPermissionRoleDefinitionUsingGraphAPI(string $user, string $p
)
);
}

/**
* @When /^user "([^"]*)" checks the activities for (?:folder|file) "([^"]*)" in space "([^"]*)" using the Graph API/
*
* @param string $user
* @param string $resource
* @param string $spaceName
*
* @return void
* @throws Exception
*
*/
public function userChecksTheActivitiesForResourceInSpaceUsingTheGraphAPI(string $user, string $resource, string $spaceName): void {
$resourceId = $this->featureContext->spacesContext->getResourceId($user, $spaceName, $resource);
$response = GraphHelper::getActivities(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$resourceId
);
$this->featureContext->setResponse($response);
}
}

0 comments on commit 065c4fa

Please sign in to comment.