mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-24 22:49:06 -06:00
Replace asserting userID with regex match
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
@api
|
||||
Feature: get user information
|
||||
Feature: get user own information
|
||||
As user
|
||||
I want to be able to retrieve my own information
|
||||
So that I can see my information
|
||||
@@ -11,9 +11,9 @@ Feature: get user information
|
||||
Scenario: user gets his/her own information with no group involvement
|
||||
When the user "Alice" retrives her information using the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the api response for user "Alice" should contains the following information:
|
||||
And the api response should contains the following information:
|
||||
| displayName | Alice Hansen |
|
||||
| id | %user_id% |
|
||||
| id | %UUIDv4% |
|
||||
| mail | alice@example.org |
|
||||
| onPremisesSamAccountName | Alice |
|
||||
| memberOf | |
|
||||
@@ -25,9 +25,9 @@ Feature: get user information
|
||||
And user "Alice" has been added to group "tea-lover"
|
||||
And user "Alice" has been added to group "coffee-lover"
|
||||
When the user "Alice" retrives her information using the Graph API
|
||||
And the api response for user "Alice" should contains the following information:
|
||||
And the api response should contains the following information:
|
||||
| displayName | Alice Hansen |
|
||||
| id | %user_id% |
|
||||
| id | %UUIDv4% |
|
||||
| onPremisesSamAccountName | Alice |
|
||||
| mail | alice@example.org |
|
||||
| memberOf | tea-lover, coffee-lover |
|
||||
@@ -201,6 +201,20 @@ class GraphContext implements Context {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method check if the userUUIDv4 is in correct pattern or not
|
||||
*
|
||||
* @param string $userUUIDv4
|
||||
*
|
||||
* @return int
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function checkUUIDv4PatternForUserId(string $userUUIDv4): int {
|
||||
$UUIDv4Regex = '/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i';
|
||||
return preg_match($UUIDv4Regex, $userUUIDv4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group
|
||||
*
|
||||
@@ -1034,14 +1048,13 @@ class GraphContext implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the api response for user "([^"]*)" should contains the following information:$/
|
||||
* @Then /^the api response should contains the following information:$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theApiResponseForUserShouldContainsTheFollowingInformation(string $user, TableNode $table): void {
|
||||
public function theApiResponseForUserShouldContainsTheFollowingInformation(TableNode $table): void {
|
||||
$rows = $table->getRowsHash();
|
||||
$apiResponse = \json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR);
|
||||
// assertion of the user is member of groups
|
||||
@@ -1054,25 +1067,36 @@ class GraphContext implements Context {
|
||||
}
|
||||
Assert::assertEqualsCanonicalizing($memberOf, $memberOfFromApiReponse);
|
||||
}
|
||||
// get user_id for the given user
|
||||
$rows['id'] = $this->featureContext->substituteInLineCodes(
|
||||
// check if the user_if from response is in format UUIDv4
|
||||
$isUUIDv4 = $this->featureContext->substituteInLineCodes(
|
||||
$rows['id'],
|
||||
$this->featureContext->getCurrentUser(),
|
||||
[],
|
||||
[
|
||||
[
|
||||
"code" => "%user_id%",
|
||||
"code" => "%UUIDv4%",
|
||||
"function" =>
|
||||
[$this->spacesContext, "getUserIdByUserName"],
|
||||
"parameter" => [$user]
|
||||
[$this, "checkUUIDv4PatternForUserId"],
|
||||
"parameter" => [$apiResponse['id']]
|
||||
],
|
||||
]
|
||||
);
|
||||
Assert::assertEquals(
|
||||
1,
|
||||
$isUUIDv4,
|
||||
__METHOD__ .
|
||||
$apiResponse['id'] . ' ID is not in the format of UUIDv4'
|
||||
);
|
||||
|
||||
// assertion for remaining key other than 'memberOf'
|
||||
// assertion for remaining key other than 'memberOf' and
|
||||
foreach (array_keys($rows) as $keyName) {
|
||||
if ($keyName !== 'memberOf') {
|
||||
Assert::assertEquals($rows[$keyName], $apiResponse[$keyName]);
|
||||
if ($keyName !== 'memberOf' && $keyName !== 'id') {
|
||||
Assert::assertEquals(
|
||||
$rows[$keyName],
|
||||
$apiResponse[$keyName],
|
||||
__METHOD__ .
|
||||
' Expected ' . $rows[$keyName] . ' but got ' . $apiResponse[$keyName]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user