From cbfd894243967c444f49f7ff7b9b7273dd42082e Mon Sep 17 00:00:00 2001 From: nirajacharya2 <122071597+nirajacharya2@users.noreply.github.com> Date: Tue, 31 Oct 2023 12:17:50 +0545 Subject: [PATCH] add query params to the log (#7493) (#7399) Co-authored-by: Sawjan Gurung --- tests/TestHelpers/GraphHelper.php | 4 ++- .../features/bootstrap/FeatureContext.php | 6 ++-- .../features/bootstrap/GraphContext.php | 29 ++++++++++--------- .../features/bootstrap/Provisioning.php | 4 +-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 2a27df195e1..c9ff5cce0e0 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -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 @@ -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, @@ -204,7 +206,7 @@ public static function editUser( return HttpRequestHelper::sendRequest( $url, $xRequestId, - "PATCH", + $method, $adminUser, $adminPassword, self::getRequestHeaders(), diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 74dd91f2c69..b3ee4633694 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -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) diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 4bb2062a80d..26ce1ff6afd 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -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); } /** @@ -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; @@ -233,6 +234,7 @@ public function editUserUsingTheGraphApi(string $byUser, string $user, string $u $byUser, $this->featureContext->getPasswordForUser($byUser), $userId, + $method, $userName, $password, $email, @@ -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); } /** @@ -523,21 +523,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); } /** @@ -551,7 +551,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); } /** @@ -1415,7 +1416,7 @@ public function userTriesToGetOwnDriveInformation(string $user) { * @param array $userIds * @param string $groupId * - * @return void + * @return ResponseInterface * @throws GuzzleException * @throws Exception */ diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 48fb0ec354e..cfd6f83626b 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -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; }