[tests-only] Added test for sharingNg for endpoint sharedByMe from personal space (#8285)

* Added tests to list shared by me resources

Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com>

* Review address

---------

Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com>
This commit is contained in:
Sagar Gurung
2024-02-01 13:54:44 +05:45
committed by GitHub
parent 024e02be95
commit 1281a730e8
3 changed files with 697 additions and 0 deletions
@@ -2525,4 +2525,62 @@ class GraphContext implements Context {
)
);
}
/**
* @When user :user lists the resources shared by him/her using the Graph API
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userListsTheResourcesSharedByAUserUsingGraphApi(string $user): void {
$credentials = $this->getAdminOrUserCredentials($user);
$this->featureContext->setResponse(
GraphHelper::getSharesSharedByMe(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials['username'],
$credentials['password']
)
);
}
/**
* @Then /^the JSON data of the response should (not )?contain file name "([^"]*)" with the following data:?$/
*
* @param string $shouldOrNot (not| )
* @param string $fileName
* @param PyStringNode $schemaString
*
* @return void
* @throws Exception
*/
public function theJsonDataResponseShouldOrNotContainSharedByMeDetails(
string $shouldOrNot,
string $fileName,
PyStringNode $schemaString
): void {
$responseBody = $this->featureContext->getJsonDecodedResponseBodyContent()->value;
$fileOrFolderFound = false;
foreach ($responseBody as $value) {
if (isset($value->name) && $value->name === $fileName) {
$responseBody = $value;
$fileOrFolderFound = true;
break;
}
}
$shouldContain = \trim($shouldOrNot) !== 'not';
if (!$shouldContain && !$fileOrFolderFound) {
return;
}
Assert::assertFalse(
!$shouldContain && $fileOrFolderFound,
'Response contains file "' . $fileName . '" but should.'
);
$this->featureContext->assertJsonDocumentMatchesSchema(
$responseBody,
$this->featureContext->getJSONSchema($schemaString)
);
}
}