Skip to content

Commit

Permalink
Adding leave and change-owner to organizations (#84)
Browse files Browse the repository at this point in the history
* Adding leave and change-owner to organizations
* Tests for change-owner
* Tests for leaveOrganization
  • Loading branch information
eporama authored Sep 15, 2020
1 parent 4451a51 commit 3377127
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
50 changes: 44 additions & 6 deletions src/Endpoints/Organizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
*
Expand Down
29 changes: 29 additions & 0 deletions tests/Endpoints/OrganizationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 3 additions & 0 deletions tests/Fixtures/Endpoints/Organizations/changeOwner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"message": "Changed organization owner."
}
3 changes: 3 additions & 0 deletions tests/Fixtures/Endpoints/Organizations/leaveOrganization.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"message": "Left organization."
}

0 comments on commit 3377127

Please sign in to comment.