From 26c9f889e79611c05be078723ea253dbef486538 Mon Sep 17 00:00:00 2001 From: Sagar Gurung <46086950+SagarGi@users.noreply.github.com> Date: Tue, 11 Apr 2023 17:09:31 +0545 Subject: [PATCH] [tests-only][full-ci]Clean up old JSON assertion step (#6013) --- .../features/apiSpaces/changeSpaces.feature | 37 +++++- .../features/apiSpaces/uploadSpaces.feature | 4 - .../features/bootstrap/SpacesContext.php | 122 ------------------ 3 files changed, 33 insertions(+), 130 deletions(-) diff --git a/tests/acceptance/features/apiSpaces/changeSpaces.feature b/tests/acceptance/features/apiSpaces/changeSpaces.feature index 678014794..eb6c63ac5 100644 --- a/tests/acceptance/features/apiSpaces/changeSpaces.feature +++ b/tests/acceptance/features/apiSpaces/changeSpaces.feature @@ -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 - Then the user "Brian" should have a space called "Brian Murphy" with these key and value pairs: - | key | value | - | quota@@@total | | - | quota@@@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": [] + }, + "total" : { + "type": "number", + "enum": [] + } + } + } + } + } + """ Examples: | quotaValue | code | total | used | | 15 | "507" | 15 | 0 | diff --git a/tests/acceptance/features/apiSpaces/uploadSpaces.feature b/tests/acceptance/features/apiSpaces/uploadSpaces.feature index d220f529d..aec32d16a 100644 --- a/tests/acceptance/features/apiSpaces/uploadSpaces.feature +++ b/tests/acceptance/features/apiSpaces/uploadSpaces.feature @@ -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 | | Examples: | role | code | shouldOrNot | usedQuota | | manager | 201 | should | 4 | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index d44cbbc6c..cf3b03496 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -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$/ *