From 2bd19efb3ccb491b9e41998cd302bb2fc42183f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Preu=C3=9F?= Date: Tue, 19 Nov 2019 17:32:10 +0100 Subject: [PATCH] Add create user method --- README.md | 1 + .../BitinflowAccounts/Traits/SshKeysTrait.php | 4 ++-- .../BitinflowAccounts/Traits/UsersTrait.php | 14 ++++++++++++- .../BitinflowAccounts/ApiUsersTest.php | 20 +++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b43c097..10b6c44 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,7 @@ public function deleteSshKey(int $id) ```php public function getAuthedUser() +public function createUser(array $parameters) ``` [**OAuth Scopes Enums**](https://github.com/ghostzero/bitinflow-accounts/blob/master/src/Enums/Scope.php) diff --git a/src/GhostZero/BitinflowAccounts/Traits/SshKeysTrait.php b/src/GhostZero/BitinflowAccounts/Traits/SshKeysTrait.php index eda731a..5d6dd0a 100644 --- a/src/GhostZero/BitinflowAccounts/Traits/SshKeysTrait.php +++ b/src/GhostZero/BitinflowAccounts/Traits/SshKeysTrait.php @@ -27,7 +27,7 @@ trait SshKeysTrait } /** - * Get currently authed user with Bearer Token + * Creates ssh key for the currently authed user * * @param string $publicKey * @param string|null $name @@ -43,7 +43,7 @@ trait SshKeysTrait } /** - * Get currently authed user with Bearer Token + * Deletes a given ssh key for the currently authed user * * @param int $id * diff --git a/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php b/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php index 369a691..56ddcb4 100644 --- a/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php +++ b/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php @@ -18,6 +18,18 @@ trait UsersTrait */ public function getAuthedUser(): Result { - return $this->get('users/me', [], null); + return $this->get('users/me'); + } + + /** + * Creates a new user on behalf of the current user. + * + * @param array $parameters + * + * @return Result + */ + public function createUser(array $parameters): Result + { + return $this->post('users', $parameters); } } \ No newline at end of file diff --git a/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php b/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php index 735671a..ff8a9ea 100644 --- a/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php +++ b/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace GhostZero\BitinflowAccounts\Tests; use GhostZero\BitinflowAccounts\Tests\TestCases\ApiTestCase; +use Illuminate\Support\Str; /** * @author René Preuß @@ -18,4 +19,23 @@ class ApiUsersTest extends ApiTestCase $this->registerResult($result = $this->getClient()->getAuthedUser()); $this->assertEquals('rene@preuss.io', $result->data()->email); } + + public function testCreateUser(): void + { + $testEmailAddress = $this->createRandomEmail(); + + $this->getClient()->withToken($this->getToken()); + $this->registerResult($result = $this->getClient()->createUser([ + 'first_name' => 'René', + 'last_name' => 'Preuß', + 'email' => $testEmailAddress, + 'terms_accepted_at' => now()->toDateTimeString(), + ])); + $this->assertEquals($testEmailAddress, $result->data()->email); + } + + private function createRandomEmail(): string + { + return sprintf('rene+unittest.%s@bitinflow.com', Str::random()); + } } \ No newline at end of file