Add create user method

This commit is contained in:
René Preuß
2019-11-19 17:32:10 +01:00
parent b5ad7786f2
commit 2bd19efb3c
4 changed files with 36 additions and 3 deletions

View File

@@ -184,6 +184,7 @@ public function deleteSshKey(int $id)
```php ```php
public function getAuthedUser() public function getAuthedUser()
public function createUser(array $parameters)
``` ```
[**OAuth Scopes Enums**](https://github.com/ghostzero/bitinflow-accounts/blob/master/src/Enums/Scope.php) [**OAuth Scopes Enums**](https://github.com/ghostzero/bitinflow-accounts/blob/master/src/Enums/Scope.php)

View File

@@ -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 $publicKey
* @param string|null $name * @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 * @param int $id
* *

View File

@@ -18,6 +18,18 @@ trait UsersTrait
*/ */
public function getAuthedUser(): Result 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);
} }
} }

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Tests; namespace GhostZero\BitinflowAccounts\Tests;
use GhostZero\BitinflowAccounts\Tests\TestCases\ApiTestCase; use GhostZero\BitinflowAccounts\Tests\TestCases\ApiTestCase;
use Illuminate\Support\Str;
/** /**
* @author René Preuß <rene@preuss.io> * @author René Preuß <rene@preuss.io>
@@ -18,4 +19,23 @@ class ApiUsersTest extends ApiTestCase
$this->registerResult($result = $this->getClient()->getAuthedUser()); $this->registerResult($result = $this->getClient()->getAuthedUser());
$this->assertEquals('rene@preuss.io', $result->data()->email); $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());
}
} }