From ff68659b4e16c3eeb1456518ba227023d6812c4a Mon Sep 17 00:00:00 2001 From: Niraj Acharya Date: Tue, 11 Feb 2025 14:42:28 +0545 Subject: [PATCH] adding test for trying to create auth app-token without expiry using cli --- tests/acceptance/bootstrap/CliContext.php | 18 ++++++++++++++---- .../features/cliCommands/authAppToken.feature | 6 ++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/acceptance/bootstrap/CliContext.php b/tests/acceptance/bootstrap/CliContext.php index d75861841cd..43bf76bc526 100644 --- a/tests/acceptance/bootstrap/CliContext.php +++ b/tests/acceptance/bootstrap/CliContext.php @@ -129,6 +129,7 @@ class CliContext implements Context { /** * @When the administrator creates auth-app token for user :user with expiration time :expirationTime using the auth-app CLI + * @When the administrator tries to create auth-app token for user :user with expiration time :expirationTime using the auth-app CLI * * @param string $user * @param string $expirationTime @@ -287,19 +288,28 @@ class CliContext implements Context { } /** - * @Then the command should be successful + * @Then /^the command should be (successful|unsuccessful)$/ + * + * @param string $successfulOrNot * * @return void */ - public function theCommandShouldBeSuccessful(): void { + public function theCommandShouldBeSuccessful(string $successfulOrNot): void { $response = $this->featureContext->getResponse(); $this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); $jsonResponse = $this->featureContext->getJsonDecodedResponse($response); - Assert::assertSame("OK", $jsonResponse["status"]); + $expectedStatus = 'OK'; + $expectedExitCode = 0; + if ($successfulOrNot === "unsuccessful") { + $expectedStatus = "ERROR"; + $expectedExitCode = 1; + } + + Assert::assertSame($expectedStatus, $jsonResponse["status"]); Assert::assertSame( - 0, + $expectedExitCode, $jsonResponse["exitCode"], "Expected exit code to be 0, but got " . $jsonResponse["exitCode"] ); diff --git a/tests/acceptance/features/cliCommands/authAppToken.feature b/tests/acceptance/features/cliCommands/authAppToken.feature index bae3b00962f..686d713ffa6 100644 --- a/tests/acceptance/features/cliCommands/authAppToken.feature +++ b/tests/acceptance/features/cliCommands/authAppToken.feature @@ -34,3 +34,9 @@ Feature: create auth-app token "maxItems": 0 } """ + + + Scenario: try to create auth-app token without expiry + When the administrator tries to create auth-app token for user "Alice" with expiration time "" using the auth-app CLI + Then the command should be unsuccessful + And the command output should contain "time: invalid duration"