Skip to content

Commit

Permalink
Check app Entity has been set or not
Browse files Browse the repository at this point in the history
  • Loading branch information
amrita-shrestha committed Feb 28, 2023
1 parent ad93f31 commit 6f8b6af
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1727,20 +1727,7 @@ public function theAdministratorHasGivenTheRoleUsingTheGraphApi(string $role, st
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id') ?? $user;

if (empty($this->appEntity)) {
$applicationEntity = (
$this->featureContext->getJsonDecodedResponse(
GraphHelper::getApplications(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
)
)
)['value'][0];
$this->appEntity["id"] = $applicationEntity["id"];
foreach ($applicationEntity["appRoles"] as $value) {
$this->appEntity["appRoles"][$value['displayName']] = $value['id'];
}
$this->setApplicationEntity();
}

$response = GraphHelper::assignRole(
Expand Down Expand Up @@ -1782,16 +1769,43 @@ public function userRetrievesAssignedRoleUsingTheGraphApi(string $user): void {
);
}

/**
* set application Entity in global variable
*
* @return void
* @throws GuzzleException
*/
public function setApplicationEntity(): void {
$applicationEntity = (
$this->featureContext->getJsonDecodedResponse(
GraphHelper::getApplications(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
)
)
)['value'][0];
$this->appEntity["id"] = $applicationEntity["id"];
foreach ($applicationEntity["appRoles"] as $value) {
$this->appEntity["appRoles"][$value['displayName']] = $value['id'];
}
}

/**
* @Then /^the Graph API response should have the role "([^"]*)"$/
*
* @param string $role
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function theGraphApiResponseShouldHaveTheRole(string $role): void {
$response = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['value'][0];
if (empty($this->appEntity)) {
$this->setApplicationEntity();
}
Assert::assertEquals(
$this->appEntity["appRoles"][$role],
$response['appRoleId'],
Expand Down

0 comments on commit 6f8b6af

Please sign in to comment.