From e9f440b9dc6fe6767ca957f882a2ee77c89a8767 Mon Sep 17 00:00:00 2001 From: JanWennrich <42703348+JanWennrich@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:02:03 +0200 Subject: [PATCH] feat(Projects): add method to rotate project access tokens --- src/Api/Projects.php | 11 +++++++++++ tests/Api/ProjectsTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/Api/Projects.php b/src/Api/Projects.php index 3f5d1962..669be9de 100644 --- a/src/Api/Projects.php +++ b/src/Api/Projects.php @@ -1715,6 +1715,17 @@ public function deleteProjectAccessToken($project_id, $token_id) return $this->delete($this->getProjectPath($project_id, 'access_tokens/'.$token_id)); } + /** + * @param int|string $project_id + * @param int|string $token_id + * + * @return mixed + */ + public function rotateProjectAccessToken($project_id, $token_id) + { + return $this->post($this->getProjectPath($project_id, 'access_tokens/'.$token_id.'/rotate')); + } + /** * @param int|string $project_id * diff --git a/tests/Api/ProjectsTest.php b/tests/Api/ProjectsTest.php index c3296d62..3f49f787 100644 --- a/tests/Api/ProjectsTest.php +++ b/tests/Api/ProjectsTest.php @@ -2952,6 +2952,33 @@ public function shouldDeleteProjectAccessToken(): void $this->assertEquals($expectedBool, $api->deleteProjectAccessToken(1, 2)); } + /** + * @test + */ + public function shouldRotateProjectAccessToken(): void + { + $expectedArray = [ + 'user_id' => 141, + 'scopes' => [ + 'api', + ], + 'name' => 'token', + 'expires_at' => '2021-01-31', + 'id' => 3, + 'active' => true, + 'created_at' => '2021-01-20T22:11:48.151Z', + 'revoked' => false, + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/access_tokens/2/rotate') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedBool, $api->rotateProjectAccessToken(1, 2)); + } + /** * @test */