Skip to content

Commit

Permalink
move test away from accounts api, use graph to get userid
Browse files Browse the repository at this point in the history
  • Loading branch information
rhafer committed Apr 25, 2022
1 parent 15d3eca commit 8e72080
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ config = {
"earlyFail": True,
},
"localApiTests": {
"skip": False,
"skip": True,
"earlyFail": True,
},
"apiTests": {
Expand All @@ -76,7 +76,7 @@ config = {
},
"uiTests": {
"filterTags": "@ocisSmokeTest",
"skip": True,
"skip": False,
"skipExceptParts": [],
"earlyFail": True,
},
Expand Down
52 changes: 21 additions & 31 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use TestHelpers\SetupHelper;
use TestHelpers\GraphHelper;
use PHPUnit\Framework\Assert;

require_once 'bootstrap.php';
Expand Down Expand Up @@ -285,31 +286,23 @@ public function getETag(string $user, string $spaceName, string $fileName): stri
* @return string
*/
public function getUserIdByUserName(string $userName): string {
$fullUrl = $this->baseUrl . "/api/v0/accounts/accounts-list";
$this->featureContext->setResponse(
HttpRequestHelper::post(
$fullUrl,
"",
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
[],
"{}"
)
);
$this->featureContext->setResponse(GraphHelper::getUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$userName
));
if ($this->featureContext->getResponse()) {
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
$response = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
if (isset($response["accounts"])) {
$accounts = $response["accounts"];
if (isset($response["id"])) {
$user = $response;
} else {
throw new Exception(__METHOD__ . " accounts-list is empty");
}
}
foreach ($accounts as $account) {
if ($account["preferredName"] === $userName) {
return $account["id"];
}
}
return $user["id"];
throw new Exception(__METHOD__ . " user with name $userName not found");
}

Expand Down Expand Up @@ -607,7 +600,6 @@ public function theAdministratorGivesUserTheRole(string $user, string $role): vo
$password = $this->featureContext->getAdminPassword();
$headers = [];
$bundles = [];
$accounts = [];
$assignment = [];

// get the roles list first
Expand All @@ -628,22 +620,20 @@ public function theAdministratorGivesUserTheRole(string $user, string $role): vo
}
Assert::assertNotEmpty($roleToAssign, "The selected role $role could not be found");

// get the accounts list first
$fullUrl = $this->baseUrl . "/api/v0/accounts/accounts-list";
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}"));
$this->featureContext->setResponse(GraphHelper::getUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$user
));
if ($this->featureContext->getResponse()) {
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["accounts"])) {
$accounts = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["accounts"];
}
}
$accountToChange = "";
foreach ($accounts as $account) {
// find the selected user
if ($account["preferredName"] === $user) {
$accountToChange = $account;
if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["id"])) {
$accountToChange = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
}
}

Assert::assertNotEmpty($accountToChange, "The selected account $user does not exist");

// set the new role
Expand Down

0 comments on commit 8e72080

Please sign in to comment.