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 24, 2024
1 parent ad0e8a6 commit d685279
Show file tree
Hide file tree
Showing 3 changed files with 151 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 {
// resourceId 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"
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"
}
}
}
}
}
}
}
}
"""
25 changes: 25 additions & 0 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
class GraphContext implements Context {
private FeatureContext $featureContext;
private SpacesContext $spacesContext;

/**
* application Entity
Expand All @@ -47,6 +48,7 @@ public function before(BeforeScenarioScope $scope): void {
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context from here
$this->featureContext = $environment->getContext('FeatureContext');
$this->spacesContext = $environment->getContext('SpacesContext');
}

/**
Expand Down Expand Up @@ -2775,4 +2777,27 @@ public function getPermissionRoleDefinitionUsingGraphAPI(string $user, string $p
)
);
}

/**
* @When /^user "([^"]*)" checks the activities for (?:folder|file) "([^"]*)" in space "([^"]*)"/
*
* @param string $user
* @param string $resource
* @param string $spaceName
*
* @return void
* @throws Exception
*
*/
public function userChecksTheActivitiesForResource(string $user, string $resource, string $spaceName): void {
$resourceId = $this->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 d685279

Please sign in to comment.