Skip to content

Commit

Permalink
Added necessary helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
Roshan Lamichhane committed Feb 7, 2023
1 parent 4e69478 commit 15c152b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
18 changes: 7 additions & 11 deletions tests/acceptance/features/apiSpaces/quota.feature
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,11 @@ Feature: State of the quota
| endpoint |
| <end_point> |
Then the HTTP status code should be "200"
And the json responded should contain these key and value pairs:
| key | value |
| quota@@@free | <quota_free> |
| quota@@@used | <quota_used> |
| quota@@@total | <quota_total> |
| quota@@@relative | <quota_relative> |
And the OCS status code should be "<ocs_code>"
And the relative quota amount should be "<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 |
| file_upload | end_point | ocs_code | quota_relative |
| /filesForUpload/lorem.txt | /ocs/v1.php/cloud/users/%username% | 100 | 6.99 |
| /filesForUpload/lorem-big.txt | /ocs/v1.php/cloud/users/%username% | 100 | 91.17 |
| /filesForUpload/lorem.txt | /ocs/v2.php/cloud/users/%username% | 200 | 6.99 |
| /filesForUpload/lorem-big.txt | /ocs/v2.php/cloud/users/%username% | 200 | 91.17 |
18 changes: 18 additions & 0 deletions tests/acceptance/features/bootstrap/OCSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,24 @@ public function getOCSResponseStatusCode(ResponseInterface $response):string {
);
}

/**
* Parses the xml answer to return data items from ocs response
*
* @param ResponseInterface $response
*
* @return SimpleXMLElement
* @throws Exception
*/
public function getOCSResponseData(ResponseInterface $response): SimpleXMLElement {
$responseXml = $this->featureContext->getResponseXml($response, __METHOD__);
if (isset($responseXml->data)) {
return $responseXml->data;
}
throw new Exception(
"No OCS data items found in responseXml"
);
}

/**
* Parses the xml answer to get ocs response message which doesn't match with
* http one in v1 of the api.
Expand Down
34 changes: 14 additions & 20 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3136,31 +3136,25 @@ public function publicDownloadsTheFolderFromTheLastCreatedPublicLink(string $res
}

/**
* @Then /^the json responded should contain these key and value pairs:$/
* @Then the relative quota amount should be :quota_amount
*
* Loops through data items in response to find given key and value pairs
* It does not support field value replacing
*
* @param TableNode $table
* @param string $quotaAmount
*
* @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");
public function theRelativeQuotaAmountShouldBe(string $quotaAmount): void {
$data = $this->ocsContext->getOCSResponseData($this->featureContext->getResponse());
if (isset($data->quota, $data->quota->relative)) {
Assert::assertEquals(
$data->quota->relative,
$quotaAmount,
"Expected relative quota amount to be $quotaAmount but found to be $data->quota->relative"
);
} else {
throw new Exception(
"No relative quota amount found in responseXml"
);
}
}
}

0 comments on commit 15c152b

Please sign in to comment.