-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
442 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DanielDeWit\LighthouseSanctum\Tests\Integration\GraphQL\Mutations; | ||
|
||
use DanielDeWit\LighthouseSanctum\Enums\RegisterStatus; | ||
use DanielDeWit\LighthouseSanctum\Tests\Integration\AbstractIntegrationTest; | ||
use DanielDeWit\LighthouseSanctum\Tests\stubs\Users\UserMustVerifyEmail; | ||
use Illuminate\Auth\Notifications\VerifyEmail; | ||
use Illuminate\Support\Facades\Notification; | ||
use Illuminate\Testing\TestResponse; | ||
|
||
class RegisterTest extends AbstractIntegrationTest | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_registers_a_user(): void | ||
{ | ||
$response = $this->makeRequest()->assertJsonStructure([ | ||
'data' => [ | ||
'register' => [ | ||
'token', | ||
'status', | ||
], | ||
], | ||
]); | ||
|
||
static::assertTrue(RegisterStatus::SUCCESS()->is($response->json('data.register.status'))); | ||
|
||
$this->assertDatabaseHas('users', [ | ||
'name' => 'Foo Bar', | ||
'email' => 'foo@bar.com', | ||
]); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_sends_an_email_verification_notification(): void | ||
{ | ||
Notification::fake(); | ||
|
||
$this->app['config']->set('auth.providers.users.model', UserMustVerifyEmail::class); | ||
|
||
$response = $this->makeRequest()->assertJsonStructure([ | ||
'data' => [ | ||
'register' => [ | ||
'token', | ||
'status', | ||
], | ||
], | ||
]); | ||
|
||
static::assertNull($response->json('data.register.token')); | ||
static::assertTrue(RegisterStatus::MUST_VERIFY_EMAIL()->is($response->json('data.register.status'))); | ||
|
||
$this->assertDatabaseHas('users', [ | ||
'name' => 'Foo Bar', | ||
'email' => 'foo@bar.com', | ||
]); | ||
|
||
$user = UserMustVerifyEmail::first(); | ||
|
||
Notification::assertSentTo($user, VerifyEmail::class); | ||
} | ||
|
||
protected function makeRequest(): TestResponse | ||
{ | ||
return $this->graphQL(/** @lang GraphQL */' | ||
mutation { | ||
register(input: { | ||
name: "Foo Bar", | ||
email: "foo@bar.com", | ||
password: "supersecret", | ||
password_confirmation: "supersecret", | ||
}) { | ||
token | ||
status | ||
} | ||
} | ||
'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DanielDeWit\LighthouseSanctum\Tests\Traits; | ||
|
||
use Illuminate\Auth\AuthManager; | ||
use Illuminate\Contracts\Auth\UserProvider; | ||
use Illuminate\Contracts\Config\Repository as Config; | ||
use Illuminate\Foundation\Auth\User; | ||
use Mockery; | ||
use Mockery\MockInterface; | ||
|
||
trait MocksUserProvider | ||
{ | ||
/** | ||
* @return AuthManager|MockInterface | ||
*/ | ||
protected function mockAuthManager(?UserProvider $userProvider) | ||
{ | ||
/** @var AuthManager|MockInterface $authManager */ | ||
$authManager = Mockery::mock(AuthManager::class) | ||
->shouldReceive('createUserProvider') | ||
->with('sanctum-provider') | ||
->andReturn($userProvider) | ||
->getMock(); | ||
|
||
return $authManager; | ||
} | ||
|
||
/** | ||
* @return Config|MockInterface | ||
*/ | ||
protected function mockConfig() | ||
{ | ||
/** @var Config|MockInterface $config */ | ||
$config = Mockery::mock(Config::class) | ||
->shouldReceive('get') | ||
->with('lighthouse-sanctum.provider') | ||
->andReturn('sanctum-provider') | ||
->getMock(); | ||
|
||
return $config; | ||
} | ||
|
||
/** | ||
* @return UserProvider|MockInterface | ||
*/ | ||
abstract protected function mockUserProvider(?User $user); | ||
} |
Oops, something went wrong.