From 219aa2d20b1b625b15c5e1dac38b8a2f8200bf32 Mon Sep 17 00:00:00 2001 From: Niraj Acharya Date: Fri, 18 Aug 2023 09:25:41 +0545 Subject: [PATCH] adding test for deprovisioning notification using date format --- .../deprovisioningNotification.feature | 68 +++++++++++++++++++ .../bootstrap/NotificationContext.php | 30 +++++++- 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/features/apiNotification/deprovisioningNotification.feature b/tests/acceptance/features/apiNotification/deprovisioningNotification.feature index 41149c95f9c..d211579eecf 100644 --- a/tests/acceptance/features/apiNotification/deprovisioningNotification.feature +++ b/tests/acceptance/features/apiNotification/deprovisioningNotification.feature @@ -169,3 +169,71 @@ Feature: Deprovisioning notification | Space Admin | | User | | User Light | + + + Scenario Outline: administrator creates a deprovisioning notification with different date formats + When the administrator creates a deprovisioning notification on "" using date format "" + Then the HTTP status code should be "200" + When user "Alice" lists all notifications + Then the HTTP status code should be "200" + And the JSON response should contain a notification message with the subject "Instance will be shut down and deprovisioned" and the message-details should match + """ + { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string", + "enum": [ + "Attention! The instance will be shut down and deprovisioned on . Download all your data before that date as no access past that date is possible." + ] + } + } + } + """ + Examples: + | deprovision_date | deprovision_date_format | + | 2006-01-02T15:04:05.999999999+07:00 | 2006-01-02T15:04:05.999999999Z07:00 | + | 3:04PM | 3:04PM | + | Jan 2 15:04:05 | Jan _2 15:04:05 | + | Jan 2 15:04:05.000000000 | Jan _2 15:04:05.000000000 | + # when we make an api request using date format like Jan `_2 15:04:05` the server removes the `_` with a space so added a space to make assertions. + | 2023-01-02 15:04:05 | 2006-01-02 15:04:05 | + | 2023-01-02 | 2006-01-02 | + | 15:04:05 | 15:04:05 | + + + Scenario Outline: administrator change a deprovisioning notification with different date formats + Given the administrator has created a deprovisioning notification + When the administrator creates a deprovisioning notification on "" using date format "" + Then the HTTP status code should be "200" + When user "Alice" lists all notifications + Then the HTTP status code should be "200" + And the JSON response should contain a notification message with the subject "Instance will be shut down and deprovisioned" and the message-details should match + """ + { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string", + "enum": [ + "Attention! The instance will be shut down and deprovisioned on . Download all your data before that date as no access past that date is possible." + ] + } + } + } + """ + Examples: + | deprovision_date | deprovision_date_format | + | 01/02 03:04:05PM '23 -0700 | 01/02 03:04:05PM '06 -0700 | + | Mon Jan 2 15:04:05 UTC 2023 | Mon Jan _2 15:04:05 UTC 2006 | + | Mon Jan 02 15:04:05 -0700 2023 | Mon Jan 02 15:04:05 -0700 2006 | + | 02 Jan 23 15:04 -0700 | 02 Jan 06 15:04 -0700 | + | Monday, 02-Jan-23 15:04:05 UTC | Monday, 02-Jan-06 15:04:05 UTC | + | Mon, 02 Jan 2023 15:04:05 -0700 | Mon, 02 Jan 2006 15:04:05 -0700 | + | 2006-01-02T15:04:05+07:00 | 2006-01-02T15:04:05Z07:00 | diff --git a/tests/acceptance/features/bootstrap/NotificationContext.php b/tests/acceptance/features/bootstrap/NotificationContext.php index 8fc634fecaf..87ff5893735 100644 --- a/tests/acceptance/features/bootstrap/NotificationContext.php +++ b/tests/acceptance/features/bootstrap/NotificationContext.php @@ -520,13 +520,22 @@ public function clearInbucketMessages():void { * @When user :user tries to create a deprovisioning notification * * @param string|null $user + * @param string|null $deprovision_date + * @param string|null $deprovision_date_format * * @return void + * + * @throws GuzzleException + * + * @throws JsonException */ - public function userCreatesDeprovisioningNotification(?string $user = null):void { + public function userCreatesDeprovisioningNotification( + ?string $user = null, + ?string $deprovision_date = "2043-07-04T11:23:12Z", + ?string $deprovision_date_format= "2006-01-02T15:04:05Z07:00" + ):void { $payload["type"] = "deprovision"; - $payload["data"] = ["deprovision_date" => "2043-07-04T11:23:12Z"]; - + $payload["data"] = ["deprovision_date" => $deprovision_date, "deprovision_date_format" => $deprovision_date_format]; $response = OcsApiHelper::sendRequest( $this->featureContext->getBaseUrl(), $user ? $this->featureContext->getActualUsername($user) : $this->featureContext->getAdminUsername(), @@ -540,6 +549,21 @@ public function userCreatesDeprovisioningNotification(?string $user = null):void $this->featureContext->setResponse($response); } + /** + * @When the administrator creates a deprovisioning notification on :arg1 using date format :arg2 + * + * @param $deprovision_date + * @param $deprovision_date_format + * + * @return void + * + * @throws GuzzleException + * @throws JsonException + */ + public function theAdministratorCreatesADeprovisioningNotificationUsingDateFormat($deprovision_date, $deprovision_date_format) { + $this->userCreatesDeprovisioningNotification(null, $deprovision_date, $deprovision_date_format); + } + /** * @Given the administrator has created a deprovisioning notification *