[test-only][full-ci] Api tests. get notification on different languages (#6254)

* get notification on different languages

* set default english if no configured

* fix

* fix after review

* fix after rebase

* after review
This commit is contained in:
Viktor Scharf
2023-05-17 10:00:47 +02:00
committed by GitHub
parent 4aad1db780
commit 36d7e77baa
4 changed files with 319 additions and 109 deletions

View File

@@ -13,7 +13,7 @@ default:
ldapGroupsOU: TestGroups
ldapInitialUserFilePath: /../../config/ldap-users.ldif
contexts:
- RoleAssignmentContext:
- SettingsContext:
- GraphContext:
- SpacesContext:
- FeatureContext: &common_feature_context_params
@@ -37,7 +37,7 @@ default:
- '%paths.base%/../features/apiSpaces'
context: *common_ldap_suite_context
contexts:
- RoleAssignmentContext:
- SettingsContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- CapabilitiesContext:
@@ -60,7 +60,7 @@ default:
- '%paths.base%/../features/apiSpacesShares'
context: *common_ldap_suite_context
contexts:
- RoleAssignmentContext:
- SettingsContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- CapabilitiesContext:
@@ -82,7 +82,7 @@ default:
- '%paths.base%/../features/apiContract'
context: *common_ldap_suite_context
contexts:
- RoleAssignmentContext:
- SettingsContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
- CapabilitiesContext:
@@ -103,7 +103,7 @@ default:
- '%paths.base%/../features/apiArchiver'
context: *common_ldap_suite_context
contexts:
- RoleAssignmentContext:
- SettingsContext:
- ArchiverContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
@@ -122,7 +122,7 @@ default:
- '%paths.base%/../features/apiGraph'
context: *common_ldap_suite_context
contexts:
- RoleAssignmentContext:
- SettingsContext:
- GraphContext:
- SpacesContext:
- FeatureContext: *common_feature_context_params
@@ -185,7 +185,7 @@ default:
- FavoritesContext:
- ChecksumContext:
- FilesVersionsContext:
- RoleAssignmentContext:
- SettingsContext:
extensions:
rdx\behatvars\BehatVariablesExtension: ~

View File

@@ -1,4 +1,4 @@
@api
@api
Feature: Notification
As a user
I want to be notified of actions related to me
@@ -21,108 +21,160 @@ Feature: Notification
When user "Brian" lists all notifications
Then the HTTP status code should be "200"
And the JSON response should contain a notification message with the subject "Space shared" and the message-details should match
"""
{
"type": "object",
"required": [
"app",
"datetime",
"message",
"messageRich",
"messageRichParameters",
"notification_id",
"object_id",
"object_type",
"subject",
"subjectRich",
"user"
],
"properties": {
"app": {
"type": "string",
"enum": ["userlog"]
},
"message": {
"type": "string",
"enum": ["Alice Hansen added you to Space notification checking"]
},
"messageRich": {
"type": "string",
"enum": ["{user} added you to Space {space}"]
},
"messageRichParameters": {
"type": "object",
"required": [
"space",
"user"
],
"properties": {
"space": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "string",
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\$[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}![a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"name": {
"type": "string",
"enum": ["notification checking"]
"""
{
"type": "object",
"required": [
"app",
"datetime",
"message",
"messageRich",
"messageRichParameters",
"notification_id",
"object_id",
"object_type",
"subject",
"subjectRich",
"user"
],
"properties": {
"app": {
"type": "string",
"enum": [
"userlog"
]
},
"message": {
"type": "string",
"enum": [
"Alice Hansen added you to Space notification checking"
]
},
"messageRich": {
"type": "string",
"enum": [
"{user} added you to Space {space}"
]
},
"messageRichParameters": {
"type": "object",
"required": [
"space",
"user"
],
"properties": {
"space": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "string",
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\$[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}![a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"name": {
"type": "string",
"enum": [
"notification checking"
]
}
}
}
},
"user": {
"type": "object",
"required": [
"displayname",
"id",
"name"
],
"properties": {
"displayname": {
"type": "string",
"enum": ["Alice Hansen"]
},
"id": {
"type": "string",
"enim": ["%user_id%"]
},
"name": {
"type": "string",
"enum": ["Alice"]
},
"user": {
"type": "object",
"required": [
"displayname",
"id",
"name"
],
"properties": {
"displayname": {
"type": "string",
"enum": [
"Alice Hansen"
]
},
"id": {
"type": "string",
"enim": [
"%user_id%"
]
},
"name": {
"type": "string",
"enum": [
"Alice"
]
}
}
}
}
},
"notification_id": {
"type": "string"
},
"object_id": {
"type": "string",
"pattern": "^%space_id_pattern%$"
},
"object_type": {
"type": "string",
"enum": [
"storagespace"
]
},
"subject": {
"type": "string",
"enum": [
"Space shared"
]
},
"subjectRich": {
"type": "string",
"enum": [
"Space shared"
]
},
"user": {
"type": "string",
"enum": [
"Alice"
]
}
},
"notification_id": {
"type": "string"
},
"object_id": {
"type": "string"
},
"object_type": {
"type": "string",
"enum": ["storagespace"]
},
"subject": {
"type": "string",
"enum": ["Space shared"]
},
"subjectRich": {
"type": "string",
"enum": ["Space shared"]
},
"user": {
"type": "string",
"enum": ["Alice"]
}
}
}
"""
"""
Scenario Outline: user gets a notification of space sharing in different languages
Given user "Alice" has created a space "notification checking" with the default quota using the GraphApi
And user "Brian" has switched the system language to "<language>"
And user "Alice" has shared a space "notification checking" with settings:
| shareWith | Brian |
| role | editor |
When user "Brian" lists all notifications
Then the HTTP status code should be "200"
And the JSON response should contain a notification message with the subject "<subject>" and the message-details should match
"""
{
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string",
"enum": [
"<message>"
]
}
}
}
"""
Examples:
| language | subject | message |
| de | Space freigegeben | Alice Hansen hat Sie zu Space notification checking hinzugefügt |
| en | Space shared | Alice Hansen added you to Space notification checking |
| es | Space compartido | Alice Hansen te añadió al Space notification checking |

View File

@@ -22,9 +22,8 @@ require_once 'bootstrap.php';
*/
class NotificationContext implements Context {
private FeatureContext $featureContext;
private SpacesContext $spacesContext;
private SettingsContext $settingsContext;
private string $notificationEndpointPath = '/apps/notifications/api/v1/notifications?format=json';
private array $notificationIds;
@@ -78,6 +77,7 @@ class NotificationContext implements Context {
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->spacesContext = $environment->getContext('SpacesContext');
$this->settingsContext = $environment->getContext('SettingsContext');
}
/**
@@ -89,13 +89,17 @@ class NotificationContext implements Context {
*/
public function userListAllNotifications(string $user):void {
$this->setUserRecipient($user);
$headers = ["accept-language" => $this->settingsContext->getSettingLanguageValue($user)];
$response = OcsApiHelper::sendRequest(
$this->featureContext->getBaseUrl(),
$this->featureContext->getActualUsername($user),
$this->featureContext->getPasswordForUser($user),
'GET',
$this->notificationEndpointPath,
$this->featureContext->getStepLineRef()
$this->featureContext->getStepLineRef(),
[],
2,
$headers
);
$this->featureContext->setResponse($response);
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
@@ -18,7 +19,7 @@ require_once 'bootstrap.php';
/**
* Context for the TUS-specific steps using the Graph API
*/
class RoleAssignmentContext implements Context {
class SettingsContext implements Context {
private FeatureContext $featureContext;
private SpacesContext $spacesContext;
private string $baseUrl;
@@ -256,4 +257,157 @@ class RoleAssignmentContext implements Context {
$assignmentRoleId = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())["assignments"][0]["roleId"];
Assert::assertEquals($this->userGetRoleIdByRoleName($this->featureContext->getAdminUserName(), $role), $assignmentRoleId, "user has no role $role");
}
/**
* @param string $user
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function sendRequestGetBundlesList(string $user): void {
$fullUrl = $this->baseUrl . $this->settingsUrl . "bundles-list";
$this->featureContext->setResponse(
$this->spacesContext->sendPostRequestToUrl($fullUrl, $user, $this->featureContext->getPasswordForUser($user), '{}')
);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201"
);
}
/**
* @param string $user
* @param string $bundleName
*
* @return array
*
* @throws GuzzleException
* @throws Exception
*/
public function getBundlesList(string $user, string $bundleName): array {
$this->sendRequestGetBundlesList($user);
$body = json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR);
foreach ($body["bundles"] as $value) {
if ($value["displayName"] === $bundleName) {
return $value;
}
}
return [];
}
/**
* @param string $user
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function sendRequestGetSettingsValuesList(string $user): void {
$fullUrl = $this->baseUrl . $this->settingsUrl . "values-list";
$body = json_encode(["account_uuid" => "me"], JSON_THROW_ON_ERROR);
$this->featureContext->setResponse(
$this->spacesContext->sendPostRequestToUrl($fullUrl, $user, $this->featureContext->getPasswordForUser($user), $body)
);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201"
);
}
/**
* @param string $user
*
* @return string
*
* @throws GuzzleException
* @throws Exception
*/
public function getSettingLanguageValue(string $user): string {
$this->sendRequestGetSettingsValuesList($user);
$body = json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR);
// if no language is set, the request body is empty return English as the default language
if (empty($body)) {
return "en";
}
foreach ($body["values"] as $value) {
if ($value["identifier"]["setting"] === "language") {
return $value["value"]["listValue"]["values"][0]["stringValue"];
}
}
}
/**
* @param string $user
* @param string $language
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function sendRequestToSwitchSystemLanguage(string $user, string $language): void {
$profileBundlesList = $this->getBundlesList($user, "Profile");
Assert::assertNotEmpty($profileBundlesList, "bundles list is empty");
$settingId = '';
foreach ($profileBundlesList["settings"] as $value) {
if ($value["name"] === "language") {
$settingId = $value["id"];
break;
}
}
Assert::assertNotEmpty($settingId, "settingId is empty");
$fullUrl = $this->baseUrl . $this->settingsUrl . "values-save";
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$body = json_encode(
[
"value" => [
"account_uuid" => "me",
"bundleId" => $profileBundlesList["id"],
"id" => $userId,
"listValue" => [
"values" => [
[
"stringValue" => $language
]
]
],
"resource" => [
"type" => "TYPE_USER"
],
"settingId" => $settingId
]
],
JSON_THROW_ON_ERROR
);
$this->featureContext->setResponse(
$this->spacesContext->sendPostRequestToUrl($fullUrl, $user, $this->featureContext->getPasswordForUser($user), $body)
);
}
/**
* @Given /^user "([^"]*)" has switched the system language to "([^"]*)"$/
*
* @param string $user
* @param string $language
*
* @return void
*
* @throws Exception
*/
public function theUserHasSwitchedSysemLanguage(string $user, string $language): void {
$this->sendRequestToSwitchSystemLanguage($user, $language);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201"
);
}
}