Skip to content

Commit

Permalink
addSteps: clean project space after test
Browse files Browse the repository at this point in the history
  • Loading branch information
ScharfViktor authored and rhafer committed Apr 26, 2022
1 parent 84dcbb5 commit b34a957
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Hook\Call\AfterScenario;
use Behat\Gherkin\Node\TableNode;
use Behat\Testwork\Environment\Environment;
use GuzzleHttp\Exception\GuzzleException;
Expand Down Expand Up @@ -333,6 +334,55 @@ public function setUpScenario(BeforeScenarioScope $scope): void {
);
}

/**
* @AfterScenario
*
* @return void
*
* @throws Exception
*/
public function cleanDataAfterTests(): void
{
$this->deleteAllSpacesOfTheType('project');
}

/**
* The method first disables and then deletes spaces
* @param string $driveType
*
* @return void
*
* @throws Exception
*/
public function deleteAllSpacesOfTheType(string $driveType): void
{
$query = "\$filter=driveType eq $driveType";
$userAdmin = $this->featureContext->getAdminUsername();

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

$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
$drives = json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
if (isset($drives["value"])) {
$drives = $drives["value"];
}

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"]);
}
}
}
}
}

/**
* Send Graph List My Spaces Request
*
Expand Down

0 comments on commit b34a957

Please sign in to comment.