From 3377127f206e5aa66271dd467c4f0c536bb75302 Mon Sep 17 00:00:00 2001 From: Erik Peterson Date: Tue, 15 Sep 2020 08:31:44 -0400 Subject: [PATCH] Adding leave and change-owner to organizations (#84) * Adding leave and change-owner to organizations * Tests for change-owner * Tests for leaveOrganization --- src/Endpoints/Organizations.php | 50 ++++++++++++++++--- tests/Endpoints/OrganizationsTest.php | 29 +++++++++++ .../Endpoints/Organizations/changeOwner.json | 3 ++ .../Organizations/leaveOrganization.json | 3 ++ 4 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 tests/Fixtures/Endpoints/Organizations/changeOwner.json create mode 100644 tests/Fixtures/Endpoints/Organizations/leaveOrganization.json diff --git a/src/Endpoints/Organizations.php b/src/Endpoints/Organizations.php index 9b785799..87c8596a 100644 --- a/src/Endpoints/Organizations.php +++ b/src/Endpoints/Organizations.php @@ -29,10 +29,9 @@ public function getAll() } /** - * Show all applications in an organisation. + * Show all applications in an organization. * * @param string $organizationUuid - * * @return ApplicationsResponse */ public function getApplications($organizationUuid) @@ -43,7 +42,7 @@ public function getApplications($organizationUuid) } /** - * Show all members of an organisation. + * Show all members of an organization. * * @param string $organizationUuid * @return MembersResponse @@ -70,7 +69,7 @@ public function getMember($organizationUuid, $memberUuid) } /** - * Show all admins of an organisation. + * Show all admins of an organization. * * @param string $organizationUuid * @return MembersResponse @@ -97,7 +96,7 @@ public function getAdmin($organizationUuid, $memberUuid) } /** - * Show all members invited to an organisation. + * Show all members invited to an organization. * * @param string $organizationUuid * @return InvitationsResponse @@ -110,7 +109,7 @@ public function getMemberInvitations($organizationUuid) } /** - * Delete a member from an organisation. + * Delete a member from an organization. * * @param string $organizationUuid * @param string $memberUuid @@ -126,6 +125,45 @@ public function deleteMember($organizationUuid, $memberUuid) ); } + /** + * Leave an organization. + * + * @param string $organizationUuid + * @return OperationResponse + */ + public function leaveOrganization($organizationUuid) + { + return new OperationResponse( + $this->client->request( + 'post', + "/organizations/${organizationUuid}/actions/leave" + ) + ); + } + + /** + * Change the owner of an organization. + * + * @param string $organizationUuid + * @param string $newOwnerUuid + * @return OperationResponse + */ + public function changeOwner($organizationUuid, $newOwnerUuid) + { + $options = [ + 'json' => [ + 'user_uuid' => $newOwnerUuid, + ], + ]; + return new OperationResponse( + $this->client->request( + 'post', + "/organizations/${organizationUuid}/actions/change-owner", + $options + ) + ); + } + /** * Show all teams in an organization. * diff --git a/tests/Endpoints/OrganizationsTest.php b/tests/Endpoints/OrganizationsTest.php index 08ef5aed..42e17d4e 100644 --- a/tests/Endpoints/OrganizationsTest.php +++ b/tests/Endpoints/OrganizationsTest.php @@ -155,4 +155,33 @@ public function testGetOrganizationInvitees() } } } + + public function testLeaveOrganization() + { + $response = $this->getPsr7GzipResponseForFixture('Endpoints/Organizations/leaveOrganization.json'); + $client = $this->getMockClient($response); + + /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */ + $organization = new Organizations($client); + $result = $organization->leaveOrganization('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851'); + + $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result); + $this->assertEquals('Left organization.', $result->message); + } + + public function testChangeOwner() + { + $response = $this->getPsr7GzipResponseForFixture('Endpoints/Organizations/changeOwner.json'); + $client = $this->getMockClient($response); + + /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */ + $organization = new Organizations($client); + $result = $organization->changeOwner( + '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', + '82cff7ec-2f09-11e9-b210-d663bd873d93' + ); + + $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result); + $this->assertEquals("Changed organization owner.", $result->message); + } } diff --git a/tests/Fixtures/Endpoints/Organizations/changeOwner.json b/tests/Fixtures/Endpoints/Organizations/changeOwner.json new file mode 100644 index 00000000..ade57199 --- /dev/null +++ b/tests/Fixtures/Endpoints/Organizations/changeOwner.json @@ -0,0 +1,3 @@ +{ + "message": "Changed organization owner." +} diff --git a/tests/Fixtures/Endpoints/Organizations/leaveOrganization.json b/tests/Fixtures/Endpoints/Organizations/leaveOrganization.json new file mode 100644 index 00000000..c5d5eae8 --- /dev/null +++ b/tests/Fixtures/Endpoints/Organizations/leaveOrganization.json @@ -0,0 +1,3 @@ +{ + "message": "Left organization." +}