From d6c08e1e51f6e5902933ffe3d2e532a21e590649 Mon Sep 17 00:00:00 2001 From: amrita Date: Thu, 2 Mar 2023 09:33:43 +0545 Subject: [PATCH] Add new step --- .../features/apiGraph/addUserToGroup.feature | 6 ++--- .../features/apiGraph/createGroup.feature | 6 ++--- .../features/bootstrap/GraphContext.php | 22 +++++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tests/acceptance/features/apiGraph/addUserToGroup.feature b/tests/acceptance/features/apiGraph/addUserToGroup.feature index dbca1b4fa66..f8e1ace5cec 100644 --- a/tests/acceptance/features/apiGraph/addUserToGroup.feature +++ b/tests/acceptance/features/apiGraph/addUserToGroup.feature @@ -157,7 +157,7 @@ Feature: add users to group | username | | Brian | | Carol | - And user "Alice" creates a group "grp1" using the Graph API + And user "Alice" has created a group "grp1" using the Graph API When the administrator "Alice" adds the following users to a group "grp1" at once using the Graph API | username | | Brian | @@ -184,7 +184,7 @@ Feature: add users to group Scenario: admin tries to add multiple non-existing users to a group at once Given the administrator has given "Alice" the role "Admin" using the settings api - And user "Alice" creates a group "grp1" using the Graph API + And user "Alice" has created a group "grp1" using the Graph API When the administrator "Alice" tries to add the following non-existing users to a group "grp1" at once using the Graph API | username | | Brian | @@ -197,7 +197,7 @@ Feature: add users to group And these users have been created with default attributes and without skeleton files: | username | | Brian | - And user "Alice" creates a group "grp1" using the Graph API + And user "Alice" has created a group "grp1" using the Graph API When the administrator "Alice" tries to add the following users to a group "grp1" at once using the Graph API | username | | Brian | diff --git a/tests/acceptance/features/apiGraph/createGroup.feature b/tests/acceptance/features/apiGraph/createGroup.feature index 78f0e6968fc..48af53fb0fa 100644 --- a/tests/acceptance/features/apiGraph/createGroup.feature +++ b/tests/acceptance/features/apiGraph/createGroup.feature @@ -26,17 +26,17 @@ Feature: create group Scenario: admin user tries to create a group that already exists Given group "mygroup" has been created When user "Alice" tries to create a group "mygroup" using the Graph API - And the HTTP status code should be "400" + Then the HTTP status code should be "400" And group "mygroup" should exist Scenario: normal user tries to create a group Given user "Brian" has been created with default attributes and without skeleton files When user "Brian" tries to create a group "mygroup" using the Graph API - And the HTTP status code should be "401" + Then the HTTP status code should be "401" And group "mygroup" should not exist Scenario: admin user tries to create a group that is the empty string When user "Alice" tries to create a group "" using the Graph API - Then the HTTP status code should be "400" \ No newline at end of file + Then the HTTP status code should be "400" diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 510e94a5811..6bd91d0bcba 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -890,6 +890,28 @@ class GraphContext implements Context { } } + /** + * @Given /^the administrator has created a group "([^"]*)" using the Graph API$/ + * @Given user :user has created a group :group using the Graph API + * + * @param string $group + * @param ?string $user + * + * @return void + * @throws Exception + * @throws GuzzleException + */ + public function userHasCreatedGroupUsingTheGraphApi(string $group, ?string $user = null): void { + $response = $this->createGroup($group, $user); + + if ($response->getStatusCode() === 200) { + $groupId = $this->featureContext->getJsonDecodedResponse($response)["id"]; + $this->featureContext->addGroupToCreatedGroupsList($group, true, true, $groupId); + } else { + $this->throwHttpException($response, "Could not create group '$group'."); + } + } + /** * create group with provided data *