Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only] [full-ci] ApiTest. after each test users-manager delete their project space #4441

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,38 +420,44 @@ public function setUpScenario(BeforeScenarioScope $scope): void {
* @throws Exception|GuzzleException
*/
public function cleanDataAfterTests(): void {
// TODO enable when admin can disable and delete spaces
// $this->deleteAllSpacesOfTheType('project');
$this->deleteAllProjectSpaces();
$this->deleteAllPersonalSpaces();
}

/**
* Admin first disables and then deletes spaces
*
* @param string $driveType
* manager of the project space first disables and then deletes spaces
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function deleteAllSpacesOfTheType(string $driveType): void {
$query = "\$filter=driveType eq $driveType";
public function deleteAllProjectSpaces(): void {
$query = "\$filter=driveType eq project";
$userAdmin = $this->featureContext->getAdminUsername();

for ($i = 0; $i < 2; ++$i) {
$this->theUserListsAllAvailableSpacesUsingTheGraphApi(
$userAdmin,
$query
);
$drives = $this->getAvailableSpaces();

if (!empty($drives)) {
foreach ($drives as $value) {
if (!\array_key_exists("deleted", $value["root"])) {
$this->sendDisableSpaceRequest($userAdmin, $value["name"]);
} else {
$this->sendDeleteSpaceRequest($userAdmin, $value["name"]);
}
$this->theUserListsAllAvailableSpacesUsingTheGraphApi(
$userAdmin,
$query
);
$drives = $this->getAvailableSpaces();
$createdUsers = $this->featureContext->getCreatedUsers();

foreach ($drives as $value) {
foreach ($value["root"]["permissions"] as $permissions) {
// find an user who is a manager
if ($permissions["roles"][0] === "manager") {
$userId = $permissions["grantedTo"][0]["user"]["id"];

foreach ($createdUsers as $user) {
if ($user["id"] === $userId) {
$userName = $user["actualUsername"];

if (!\array_key_exists("deleted", $value["root"])) {
$this->sendDisableSpaceRequest($userName, $value["name"]);
}
$this->sendDeleteSpaceRequest($userName, $value["name"]);
}
}
}
}
}
Expand All @@ -466,9 +472,9 @@ public function deleteAllSpacesOfTheType(string $driveType): void {
*/
public function deleteAllPersonalSpaces(): void {
$query = "\$filter=driveType eq personal";
$createdUsers= $this->featureContext->getCreatedUsers();
$createdUsers = $this->featureContext->getCreatedUsers();

foreach($createdUsers as $user) {
foreach ($createdUsers as $user) {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi(
$user["actualUsername"],
$query
Expand Down Expand Up @@ -901,13 +907,11 @@ public function rememberTheAvailableSpaces(): void {
$drives = $drives["value"];
}

Assert::assertArrayHasKey(0, $drives, "No drives were found on that endpoint");
$spaces = [];
foreach ($drives as $drive) {
$spaces[$drive["name"]] = $drive;
}
$this->setAvailableSpaces($spaces);
Assert::assertNotEmpty($spaces, "No spaces have been found");
}

/**
Expand Down Expand Up @@ -3027,7 +3031,7 @@ public function forUserSpaceShouldContainLinks(
string $fileName = ''
): void {
$body = '';
if (!empty ($fileName)) {
if (!empty($fileName)) {
$body = $this->getFileId($user, $spaceName, $fileName);
} else {
$space = $this->getSpaceByName($user, $spaceName);
Expand Down