-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add failure tests for createAccountOnFirstLogin feature
- Loading branch information
1 parent
98dbb12
commit 6ea7636
Showing
1 changed file
with
104 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,107 @@ | |
'provider_id' => $githubId, | ||
'email' => '[email protected]', | ||
]); | ||
}); | ||
}); | ||
|
||
|
||
test('new users can register from random page', function (): void { | ||
Config::set('socialstream.features', [ | ||
Features::createAccountOnFirstLogin(), | ||
]); | ||
|
||
$this->assertDatabaseEmpty('users'); | ||
$this->assertDatabaseEmpty('connected_accounts'); | ||
|
||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => $githubId = fake()->numerify('########'), | ||
'nickname' => 'joel', | ||
'name' => 'Joel', | ||
'email' => '[email protected]', | ||
'avatar' => null, | ||
'avatar_original' => null, | ||
]) | ||
->setToken('user-token') | ||
->setRefreshToken('refresh-token') | ||
->setExpiresIn(3600); | ||
|
||
$provider = Mockery::mock(GithubProvider::class); | ||
$provider->shouldReceive('user')->once()->andReturn($user); | ||
|
||
session()->put('socialstream.previous_url', '/random'); | ||
|
||
Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider); | ||
|
||
get('http://localhost/oauth/github/callback') | ||
->assertRedirect(RouteServiceProvider::HOME); | ||
|
||
$this->assertAuthenticated(); | ||
$this->assertDatabaseHas('users', ['email' => '[email protected]']); | ||
$this->assertDatabaseHas('connected_accounts', [ | ||
'provider' => 'github', | ||
'provider_id' => $githubId, | ||
'email' => '[email protected]', | ||
]); | ||
}); | ||
|
||
test('new users cannot register from login page without feature enabled', function (): void { | ||
$this->assertDatabaseEmpty('users'); | ||
$this->assertDatabaseEmpty('connected_accounts'); | ||
|
||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => $githubId = fake()->numerify('########'), | ||
'nickname' => 'joel', | ||
'name' => 'Joel', | ||
'email' => '[email protected]', | ||
'avatar' => null, | ||
'avatar_original' => null, | ||
]) | ||
->setToken('user-token') | ||
->setRefreshToken('refresh-token') | ||
->setExpiresIn(3600); | ||
|
||
$provider = Mockery::mock(GithubProvider::class); | ||
$provider->shouldReceive('user')->once()->andReturn($user); | ||
|
||
session()->put('socialstream.previous_url', route('login')); | ||
|
||
Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider); | ||
|
||
$response = get('http://localhost/oauth/github/callback'); | ||
|
||
$this->assertGuest(); | ||
$response->assertRedirect(route('login')); | ||
$response->assertSessionHasErrors(); | ||
}); | ||
|
||
test('new users cannot register from random page without feature enabled', function (): void { | ||
$this->assertDatabaseEmpty('users'); | ||
$this->assertDatabaseEmpty('connected_accounts'); | ||
|
||
$user = (new SocialiteUser()) | ||
->map([ | ||
'id' => $githubId = fake()->numerify('########'), | ||
'nickname' => 'joel', | ||
'name' => 'Joel', | ||
'email' => '[email protected]', | ||
'avatar' => null, | ||
'avatar_original' => null, | ||
]) | ||
->setToken('user-token') | ||
->setRefreshToken('refresh-token') | ||
->setExpiresIn(3600); | ||
|
||
$provider = Mockery::mock(GithubProvider::class); | ||
$provider->shouldReceive('user')->once()->andReturn($user); | ||
|
||
session()->put('socialstream.previous_url', '/random'); | ||
|
||
Socialite::shouldReceive('driver')->once()->with('github')->andReturn($provider); | ||
|
||
$response = get('http://localhost/oauth/github/callback'); | ||
|
||
$this->assertGuest(); | ||
$response->assertRedirect(route('login')); | ||
$response->assertSessionHasErrors(); | ||
}); |