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] removing the setResponse() in given/then step in GraphContext #7399

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public static function createUser(
* @param string $adminUser
* @param string $adminPassword
* @param string $userId
* @param string $method
* @param string|null $userName
* @param string|null $password
* @param string|null $email
Expand All @@ -187,6 +188,7 @@ public static function editUser(
string $adminUser,
string $adminPassword,
string $userId,
?string $method = "PATCH",
?string $userName = null,
?string $password = null,
?string $email = null,
Expand All @@ -204,7 +206,7 @@ public static function editUser(
return HttpRequestHelper::sendRequest(
$url,
$xRequestId,
"PATCH",
$method,
$adminUser,
$adminPassword,
self::getRequestHeaders(),
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1444,13 +1444,13 @@ public function theOcsDataOfTheResponseShouldMatch(
* @Then the JSON data of the response should match
*
* @param PyStringNode $schemaString
* @param ResponseInterface|null $response
*
* @return void
*
* @throws Exception
*/
public function theDataOfTheResponseShouldMatch(PyStringNode $schemaString): void {
$responseBody = $this->getJsonDecodedResponseBodyContent();
public function theDataOfTheResponseShouldMatch(PyStringNode $schemaString, ResponseInterface $response=null): void {
$responseBody = $this->getJsonDecodedResponseBodyContent($response);
$this->assertJsonDocumentMatchesSchema(
$responseBody,
$this->getJSONSchema($schemaString)
Expand Down
29 changes: 15 additions & 14 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ public function theUserEnablesUserToUsingTheGraphApi(string $byUser, string $use
* @throws JsonException
*/
public function theUserInformationShouldMatchTheJSON(string $user, PyStringNode $schemaString): void {
$this->adminHasRetrievedUserUsingTheGraphApi($user);
$this->featureContext->theDataOfTheResponseShouldMatch($schemaString);
$response = $this->adminHasRetrievedUserUsingTheGraphApi($user);
$this->featureContext->theDataOfTheResponseShouldMatch($schemaString, $response);
}

/**
Expand All @@ -219,11 +219,12 @@ public function theUserInformationShouldMatchTheJSON(string $user, PyStringNode
* @param string|null $email
* @param string|null $displayName
* @param bool|true $accountEnabled
* @param string $method
*
* @return void
* @throws GuzzleException
*/
public function editUserUsingTheGraphApi(string $byUser, string $user, string $userName = null, string $password = null, string $email = null, string $displayName = null, bool $accountEnabled = true): ResponseInterface {
public function editUserUsingTheGraphApi(string $byUser, string $user, string $userName = null, string $password = null, string $email = null, string $displayName = null, bool $accountEnabled = true, string $method="PATCH"): ResponseInterface {
$user = $this->featureContext->getActualUsername($user);
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
$userId = $userId ?? $user;
Expand All @@ -233,6 +234,7 @@ public function editUserUsingTheGraphApi(string $byUser, string $user, string $u
$byUser,
$this->featureContext->getPasswordForUser($byUser),
$userId,
$method,
$userName,
$password,
$email,
Expand All @@ -244,23 +246,21 @@ public function editUserUsingTheGraphApi(string $byUser, string $user, string $u
/**
* @param string $user
*
* @return void
* @return ResponseInterface
* @throws JsonException
* @throws GuzzleException
*/
public function adminHasRetrievedUserUsingTheGraphApi(string $user): void {
public function adminHasRetrievedUserUsingTheGraphApi(string $user): ResponseInterface {
$user = $this->featureContext->getActualUsername($user);
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
$userId = $userId ?: $user;
$result = GraphHelper::getUser(
return GraphHelper::getUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$userId
);
$this->featureContext->setResponse($result);
$this->featureContext->thenTheHTTPStatusCodeShouldBe(200);
}

/**
Expand Down Expand Up @@ -526,21 +526,21 @@ public function adminChangesPasswordOfUserToUsingTheGraphApi(
string $user,
string $password,
?string $byUser = null
): void {
): ResponseInterface {
$credentials = $this->getAdminOrUserCredentials($byUser);
$user = $this->featureContext->getActualUsername($user);
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
$userId = $userId ?? $user;
$response = GraphHelper::editUser(
return GraphHelper::editUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials["username"],
$credentials["password"],
$userId,
null,
"PATCH",
$user,
$password
);
$this->featureContext->setResponse($response);
}

/**
Expand All @@ -554,7 +554,8 @@ public function adminChangesPasswordOfUserToUsingTheGraphApi(
* @throws Exception
*/
public function theUserResetsThePasswordOfUserToUsingTheGraphApi(string $byUser, string $user, string $password) {
$this->adminChangesPasswordOfUserToUsingTheGraphApi($user, $password, $byUser);
$response = $this->adminChangesPasswordOfUserToUsingTheGraphApi($user, $password, $byUser);
$this->featureContext->setResponse($response);
}

/**
Expand Down Expand Up @@ -1418,7 +1419,7 @@ public function userTriesToGetOwnDriveInformation(string $user) {
* @param array $userIds
* @param string $groupId
*
* @return void
* @return ResponseInterface
* @throws GuzzleException
* @throws Exception
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,8 @@ public function usersHaveBeenCreated(
if (!$this->isTestingWithLdap()) {
// for graph api, we need to save the user id to be able to add it in some group
// can be fetched with the "onPremisesSamAccountName" i.e. userid
$this->graphContext->adminHasRetrievedUserUsingTheGraphApi($userAttributes['userid']);
$userAttributes['id'] = $this->getJsonDecodedResponse()['id'];
$response = $this->graphContext->adminHasRetrievedUserUsingTheGraphApi($userAttributes['userid']);
$userAttributes['id'] = $this->getJsonDecodedResponse($response)['id'];
} else {
$userAttributes['id'] = null;
}
Expand Down