[test-only]ApiTest. Deprovisioning notification tests (#6994)

* add create/delete notification tests

* fix grammar

---------

Co-authored-by: Swikriti Tripathi <swikriti808@gmail.com>
This commit is contained in:
Viktor Scharf
2023-08-14 09:16:04 +02:00
committed by GitHub
parent 806e0d09db
commit 0258b2bfff
2 changed files with 254 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ class NotificationContext implements Context {
private SpacesContext $spacesContext;
private SettingsContext $settingsContext;
private string $notificationEndpointPath = '/apps/notifications/api/v1/notifications?format=json';
private string $globalNotificationEndpointPath = '/apps/notifications/api/v1/notifications/global';
private array $notificationIds;
@@ -44,6 +45,15 @@ class NotificationContext implements Context {
return \end($this->notificationIds);
}
/**
* @AfterScenario
*
* @return void
*/
public function deleteDeprovisioningNotification(): void {
$this->userDeletesDeprovisioningNotification();
}
/**
* @var string
*/
@@ -127,6 +137,20 @@ class NotificationContext implements Context {
$this->featureContext->setResponse($this->userDeletesNotification($user));
}
/**
* @Given user :user has deleted all notifications
*
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function userHasDeletedAllNotifications(string $user):void {
$this->userDeletesAllNotifications($user);
$this->featureContext->thenTheHTTPStatusCodeShouldBe(200);
}
/**
* @When user :user deletes a notification related to resource :resource with subject :subject
*
@@ -490,4 +514,63 @@ class NotificationContext implements Context {
$e->getMessage();
}
}
/**
* @When the administrator creates a deprovisioning notification
* @When user :user tries to create a deprovisioning notification
*
* @param string|null $user
*
* @return void
*/
public function userCreatesDeprovisioningNotification(?string $user = null):void {
$payload["type"] = "deprovision";
$payload["data"] = ["deprovision_date" => "2043-07-04T11:23:12Z"];
$response = OcsApiHelper::sendRequest(
$this->featureContext->getBaseUrl(),
$user ? $this->featureContext->getActualUsername($user) : $this->featureContext->getAdminUsername(),
$user ? $this->featureContext->getPasswordForUser($user) : $this->featureContext->getAdminPassword(),
'POST',
$this->globalNotificationEndpointPath,
'',
json_encode($payload),
2
);
$this->featureContext->setResponse($response);
}
/**
* @Given the administrator has created a deprovisioning notification
*
* @return void
*/
public function userHasCreatedDeprovisioningNotification():void {
$this->userCreatesDeprovisioningNotification();
$this->featureContext->thenTheHTTPStatusCodeShouldBe(200);
}
/**
* @When the administrator deletes the deprovisioning notification
* @When user :user tries to delete the deprovisioning notification
*
* @param string|null $user
*
* @return void
*/
public function userDeletesDeprovisioningNotification(?string $user = null):void {
$payload["ids"] = ["deprovision"];
$response = OcsApiHelper::sendRequest(
$this->featureContext->getBaseUrl(),
$user ? $this->featureContext->getActualUsername($user) : $this->featureContext->getAdminUsername(),
$user ? $this->featureContext->getPasswordForUser($user) : $this->featureContext->getAdminPassword(),
'DELETE',
$this->globalNotificationEndpointPath,
'',
json_encode($payload),
2
);
$this->featureContext->setResponse($response);
}
}