From c182baab1771f8742629072b8cec00cfa71ae077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Preu=C3=9F?= Date: Sat, 28 Dec 2019 18:42:59 +0100 Subject: [PATCH] Add method to check if a email exists --- .../BitinflowAccounts/Traits/UsersTrait.php | 16 +++++++++++++++- .../GhostZero/BitinflowAccounts/ApiUsersTest.php | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php b/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php index 4556a8f..84e4148 100644 --- a/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php +++ b/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php @@ -32,4 +32,18 @@ trait UsersTrait { return $this->post('v2/users', $parameters); } -} \ No newline at end of file + + /** + * Checks if the given email exists. + * + * @param string $email + * + * @return Result + */ + public function isEmailExisting(string $email): Result + { + return $this->post('v2/users/check-email', [ + 'email' => $email, + ]); + } +} diff --git a/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php b/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php index 7d42284..db19fbd 100644 --- a/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php +++ b/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php @@ -22,6 +22,20 @@ class ApiUsersTest extends ApiTestCase $this->assertEquals('rene@preuss.io', $result->data()->email); } + public function testEmailAvailabilityNonExisting(): void + { + $this->getClient()->withToken($this->getToken()); + $this->registerResult($result = $this->getClient()->isEmailExisting('rene+non-existing@preuss.io')); + $this->assertTrue(!$result->success()); + } + + public function testEmailAvailabilityExisting(): void + { + $this->getClient()->withToken($this->getToken()); + $this->registerResult($result = $this->getClient()->isEmailExisting('rene@preuss.io')); + $this->assertTrue($result->success()); + } + public function testCreateUser(): void { $testEmailAddress = $this->createRandomEmail(); @@ -47,4 +61,4 @@ class ApiUsersTest extends ApiTestCase { return sprintf('rene+unittest.%s@bitinflow.com', Str::random()); } -} \ No newline at end of file +}