[tests-only][full-ci]Clean up old JSON assertion step (#6013)

This commit is contained in:
Sagar Gurung
2023-04-11 17:09:31 +05:45
committed by GitHub
parent 0e2d20fe62
commit 26c9f889e7
3 changed files with 33 additions and 130 deletions

View File

@@ -625,10 +625,39 @@ Feature: Change data of space
Then the HTTP status code should be "200"
When user "Brian" uploads a file inside space "Brian Murphy" with content "file is more than 15 bytes" to "file.txt" using the WebDAV API
Then the HTTP status code should be <code>
Then the user "Brian" should have a space called "Brian Murphy" with these key and value pairs:
| key | value |
| quota@@@total | <total> |
| quota@@@used | <used> |
And for user "Brian" the JSON response should contain space called "Brian Murphy" and match
"""
{
"type": "object",
"required": [
"name",
"quota"
],
"properties": {
"name": {
"type": "string",
"enum": ["Brian Murphy"]
},
"quota": {
"type": "object",
"required": [
"used",
"total"
],
"properties": {
"used" : {
"type": "number",
"enum": [<used>]
},
"total" : {
"type": "number",
"enum": [<total>]
}
}
}
}
}
"""
Examples:
| quotaValue | code | total | used |
| 15 | "507" | 15 | 0 |

View File

@@ -68,10 +68,6 @@ Feature: Upload files into a space
}
}
"""
And the user "Brian" should have a space called "Project Ceres" with these key and value pairs:
| key | value |
| name | Project Ceres |
| quota@@@used | <usedQuota> |
Examples:
| role | code | shouldOrNot | usedQuota |
| manager | 201 | should | 4 |

View File

@@ -914,128 +914,6 @@ class SpacesContext implements Context {
Assert::assertEquals($fileContent, $actualFileContent, "$file does not contain $fileContent");
}
/**
* @Then /^the json responded should contain a space "([^"]*)" (?:|(?:owned by|granted to) "([^"]*)" )(?:|(?:with description file|with space image) "([^"]*)" )with these key and value pairs:$/
*
* @param string $spaceName
* @param string|null $userName
* @param string|null $fileName
* @param string|null $groupName
* @param TableNode|null $table
*
* @return void
* @throws Exception
*/
public function jsonRespondedShouldContain(
string $spaceName,
?string $userName = null,
?string $fileName = null,
?string $groupName = null,
?TableNode $table = null
): void {
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
Assert::assertIsArray($spaceAsArray = $this->getSpaceByNameFromResponse($spaceName), "No space with name $spaceName found");
foreach ($table->getHash() as $row) {
// remember the original Space Array
$original = $spaceAsArray;
$row['value'] = $this->featureContext->substituteInLineCodes(
$row['value'],
$this->featureContext->getCurrentUser(),
[],
[
[
"code" => "%space_id%",
"function" =>
[$this, "getSpaceIdByNameFromResponse"],
"parameter" => [$spaceName]
],
[
"code" => "%file_id%",
"function" =>
[$this, "getFileId"],
"parameter" => [$userName, $spaceName, $fileName]
],
[
"code" => "%eTag%",
"function" =>
[$this, "getETag"],
"parameter" => [$userName, $spaceName, $fileName]
]
],
$groupName,
$userName
);
$segments = explode("@@@", $row["key"]);
// traverse down in the array
foreach ($segments as $segment) {
$arrayKeyExists = \array_key_exists($segment, $spaceAsArray);
$key = $row["key"];
Assert::assertTrue($arrayKeyExists, "The key $key does not exist on the response");
if ($arrayKeyExists) {
$spaceAsArray = $spaceAsArray[$segment];
}
}
Assert::assertEquals($row["value"], $spaceAsArray);
// set the spaceArray to the point before traversing
$spaceAsArray = $original;
}
}
/**
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" with these key and value pairs:$/
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" (?:owned by|granted to) "([^"]*)" with these key and value pairs:$/
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" (?:with description file|with space image) "([^"]*)" with these key and value pairs:$/
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" (?:owned by|granted to) "([^"]*)" (?:with description file|with space image) "([^"]*)" with these key and value pairs:$/
*
* @param string $user
* @param string $spaceName
* @param string|null $grantedUser
* @param string|null $fileName
* @param TableNode|null $table
*
* @return void
* @throws GuzzleException
*/
public function userHasSpaceWith(
string $user,
string $spaceName,
?string $grantedUser = null,
?string $fileName = null,
?TableNode $table = null
): void {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user);
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"Expected response status code should be 200"
);
$this->jsonRespondedShouldContain($spaceName, $grantedUser, $fileName, null, $table);
}
/**
* @Then /^the user "([^"]*)" should have a space called "([^"]*)" granted to group "([^"]*)" with these key and value pairs:$/
*
* @param string $user
* @param string $spaceName
* @param string $grantedGroup
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function userHasSpaceGrantedToGroup(
string $user,
string $spaceName,
string $grantedGroup,
TableNode $table
): void {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user);
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"Expected response status code should be 200"
);
$this->jsonRespondedShouldContain($spaceName, null, null, $grantedGroup, $table);
}
/**
* @Then /^the JSON response should contain space called "([^"]*)" (?:|(?:owned by|granted to) "([^"]*)" )(?:|(?:with description file|with space image) "([^"]*)" )and match$/
*