From 4e694786254e3fc937185cfa87b94db4796abd37 Mon Sep 17 00:00:00 2001 From: Roshan Lamichhane Date: Mon, 30 Jan 2023 17:18:08 +0545 Subject: [PATCH] Added test scenarios for relative quota amount of personal space --- .../features/apiSpaces/quota.feature | 21 ++++++++++++++ .../features/bootstrap/SpacesContext.php | 29 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/tests/acceptance/features/apiSpaces/quota.feature b/tests/acceptance/features/apiSpaces/quota.feature index 72f29d5bf5a..fddcadf2362 100644 --- a/tests/acceptance/features/apiSpaces/quota.feature +++ b/tests/acceptance/features/apiSpaces/quota.feature @@ -65,3 +65,24 @@ Feature: State of the quota And user "Alice" has uploaded a file inside space "Project Delta" with content "7 bytes" to "test.txt" When user "Alice" uploads a file inside space "Project Delta" with content "00011 bytes" to "test.txt" using the WebDAV API Then the HTTP status code should be "507" + + + Scenario Outline: Check the relative amount of quota of personal space + Given user "Admin" has changed the quota of the personal space of "Alice Hansen" space to "10000" + And user "Alice" has uploaded file "" to "/demo.txt" + When the user "Alice" requests these endpoints with "GET" with basic auth + | endpoint | + | | + Then the HTTP status code should be "200" + And the json responded should contain these key and value pairs: + | key | value | + | quota@@@free | | + | quota@@@used | | + | quota@@@total | | + | quota@@@relative | | + Examples: + | file_upload | end_point | quota_free | quota_used | quota_total | quota_relative | + | /filesForUpload/lorem.txt | /ocs/v1.php/cloud/users/Alice?format=json | 9301 | 699 | 10000 | 6.99 | + | /filesForUpload/lorem-big.txt | /ocs/v1.php/cloud/users/Alice?format=json | 883 | 9117 | 10000 | 91.17 | + | /filesForUpload/lorem.txt | /ocs/v2.php/cloud/users/Alice?format=json | 9301 | 699 | 10000 | 6.99 | + | /filesForUpload/lorem-big.txt | /ocs/v2.php/cloud/users/Alice?format=json | 883 | 9117 | 10000 | 91.17 | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 6bbfd3f2fc5..a15eebcd5ca 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3134,4 +3134,33 @@ class SpacesContext implements Context { ) ); } + + /** + * @Then /^the json responded should contain these key and value pairs:$/ + * + * Loops through data items in response to find given key and value pairs + * It does not support field value replacing + * + * @param TableNode $table + * + * @return void + * @throws Exception + */ + public function theJsonRespondedShouldContainTheseKeyAndValuePairs(TableNode $table):void { + $this->featureContext->verifyTableNodeColumns($table, ['key', 'value']); + $response = json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR); + $data = $response["ocs"]["data"]; + foreach ($table->getHash() as $row) { + $key = $row['key']; + $expectedValue = $row['value']; + $segments = explode('@@@', $key); + $actualValue = $data; + foreach ($segments as $segment) { + $arrayKeyExists = \array_key_exists($segment, $actualValue); + Assert::assertTrue($arrayKeyExists, "The key $segment does not exist on the response"); + $actualValue = $actualValue[$segment]; + } + Assert::assertEquals($expectedValue, $actualValue, "Expected $expectedValue but received $actualValue"); + } + } }