diff --git a/src/Endpoints/UserInvites.php b/src/Endpoints/UserInvites.php new file mode 100644 index 00000000..750e18db --- /dev/null +++ b/src/Endpoints/UserInvites.php @@ -0,0 +1,33 @@ +adapter = $adapter; + } + + public function respondToInvite(string $inviteId, string $status) + { + $options = [ + 'status' => $status, + ]; + + $invite = $this->adapter->patch('user/invites/' . $inviteId, $options); + $this->body = json_decode($invite->getBody()); + + return $this->body->result; + } +} diff --git a/tests/Endpoints/UserInviteTest.php b/tests/Endpoints/UserInviteTest.php new file mode 100644 index 00000000..f19aabd5 --- /dev/null +++ b/tests/Endpoints/UserInviteTest.php @@ -0,0 +1,31 @@ +getPsr7JsonResponseForFixture('Endpoints/respondToUserInvite.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('patch')->willReturn($response); + + $mock->expects($this->once()) + ->method('patch') + ->with( + $this->equalTo('user/invites/4f5f0c14a2a41d5063dd301b2f829f04'), + $this->equalTo([ + 'status' => 'accepted', + ]) + ); + + $userInvites = new UserInvites($mock); + + $result = $userInvites->respondToInvite('4f5f0c14a2a41d5063dd301b2f829f04', 'accepted'); + + $this->assertObjectHasAttribute('id', $result); + $this->assertEquals('4f5f0c14a2a41d5063dd301b2f829f04', $userInvites->getBody()->result->id); + } +} diff --git a/tests/Fixtures/Endpoints/respondToUserInvite.json b/tests/Fixtures/Endpoints/respondToUserInvite.json new file mode 100644 index 00000000..6ffe9e98 --- /dev/null +++ b/tests/Fixtures/Endpoints/respondToUserInvite.json @@ -0,0 +1,26 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "4f5f0c14a2a41d5063dd301b2f829f04", + "invited_member_id": "5a7805061c76ada191ed06f989cc3dac", + "invited_member_email": "user@example.com", + "organization_id": "5a7805061c76ada191ed06f989cc3dac", + "organization_name": "Cloudflare, Inc.", + "roles": [ + { + "id": "3536bcfad5faccb999b47003c79917fb", + "name": "Organization Admin", + "description": "Administrative access to the entire Organization", + "permissions": [ + "#zones:read" + ] + } + ], + "invited_by": "user@example.com", + "invited_on": "2014-01-01T05:20:00Z", + "expires_on": "2014-01-01T05:20:00Z", + "status": "accepted" + } +} \ No newline at end of file