Skip to content

Commit 1f1f04a

Browse files
committed
WIP
1 parent 0a5e9f8 commit 1f1f04a

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

tests/BartenderManagerTest.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,34 @@
33
use DirectoryTree\Bartender\BartenderManager;
44
use DirectoryTree\Bartender\Facades\Bartender;
55
use DirectoryTree\Bartender\Tests\User;
6+
use Illuminate\Support\Facades\Route;
67

7-
test('it can register handlers', function () {
8+
it('is bound to facade', function () {
9+
expect(Bartender::getFacadeRoot())->toBeInstanceOf(BartenderManager::class);
10+
});
11+
12+
it('can register handlers', function () {
813
$manager = new BartenderManager();
914

1015
$manager->serve('foo', stdClass::class);
1116

1217
expect($manager->handlers())->toBe(['foo' => stdClass::class]);
1318
});
1419

15-
test('it returns new user model', function () {
20+
it('returns new user model', function () {
1621
$manager = new BartenderManager();
1722

1823
$manager->setUserModel(User::class);
1924

2025
expect($manager->getUserModel())->toBe(User::class);
2126
});
2227

23-
test('it is bound to facade', function () {
24-
expect(Bartender::getFacadeRoot())->toBeInstanceOf(BartenderManager::class);
28+
it('registers routes', function () {
29+
$manager = new BartenderManager();
30+
31+
$manager->routes();
32+
33+
expect(Route::getRoutes())->toHaveCount(2);
34+
expect(Route::has('auth.driver.callback'))->toBeTrue();
35+
expect(Route::has('auth.driver.redirect'))->toBeTrue();
2536
});

tests/UserProviderQueryTest.php tests/UserProviderRepositoryTest.php

+26-26
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
beforeEach(fn () => Bartender::setUserModel(User::class));
1010

1111
it('determines if user already exists with a different provider', function () {
12-
$socialite = tap(new SocialiteUser(), function ($user) {
13-
$user->id = '1';
14-
$user->email = '[email protected]';
15-
});
16-
1712
User::create([
1813
'provider_id' => '1',
1914
'provider_name' => 'foo',
@@ -22,15 +17,15 @@
2217
'password' => bcrypt('password'),
2318
]);
2419

25-
expect((new UserProviderRepository)->exists('bar', $socialite))->toBeTrue();
26-
});
27-
28-
it('determines if user already exists with no provider', function () {
2920
$socialite = tap(new SocialiteUser(), function ($user) {
3021
$user->id = '1';
3122
$user->email = '[email protected]';
3223
});
3324

25+
expect((new UserProviderRepository)->exists('bar', $socialite))->toBeTrue();
26+
});
27+
28+
it('determines if user already exists with no provider', function () {
3429
User::create([
3530
'provider_id' => null,
3631
'provider_name' => null,
@@ -39,6 +34,11 @@
3934
'password' => bcrypt('password'),
4035
]);
4136

37+
$socialite = tap(new SocialiteUser(), function ($user) {
38+
$user->id = '1';
39+
$user->email = '[email protected]';
40+
});
41+
4242
expect((new UserProviderRepository)->exists('bar', $socialite))->toBeTrue();
4343
});
4444

@@ -58,12 +58,6 @@
5858
});
5959

6060
it('updates user not associated to provider', function () {
61-
$socialite = tap(new SocialiteUser(), function (SocialiteUser $user) {
62-
$user->id = '1';
63-
$user->name = 'foo';
64-
$user->email = '[email protected]';
65-
});
66-
6761
User::create([
6862
'provider_id' => '1',
6963
'provider_name' => 'foo',
@@ -72,6 +66,12 @@
7266
'password' => 'password',
7367
]);
7468

69+
$socialite = tap(new SocialiteUser(), function (SocialiteUser $user) {
70+
$user->id = '1';
71+
$user->name = 'foo';
72+
$user->email = '[email protected]';
73+
});
74+
7575
$user = (new UserProviderRepository)->updateOrCreate('foo', $socialite);
7676

7777
expect($user->wasRecentlyCreated)->toBeFalse();
@@ -82,12 +82,6 @@
8282
});
8383

8484
it('throws exception when attempting to create existing user with null provider', function () {
85-
$socialite = tap(new SocialiteUser(), function (SocialiteUser $user) {
86-
$user->id = '1';
87-
$user->name = 'foo';
88-
$user->email = '[email protected]';
89-
});
90-
9185
User::create([
9286
'name' => 'bar',
9387
'email' => '[email protected]',
@@ -96,16 +90,16 @@
9690

9791
$this->expectException(QueryException::class);
9892

99-
(new UserProviderRepository)->updateOrCreate('foo', $socialite);
100-
});
101-
102-
it('throws exception when attempting to create existing user with another provider', function () {
10393
$socialite = tap(new SocialiteUser(), function (SocialiteUser $user) {
104-
$user->id = '123';
94+
$user->id = '1';
10595
$user->name = 'foo';
10696
$user->email = '[email protected]';
10797
});
10898

99+
(new UserProviderRepository)->updateOrCreate('foo', $socialite);
100+
});
101+
102+
it('throws exception when attempting to create existing user with another provider', function () {
109103
User::create([
110104
'name' => 'bar',
111105
'provider_id' => '456',
@@ -114,6 +108,12 @@
114108
'password' => 'password',
115109
]);
116110

111+
$socialite = tap(new SocialiteUser(), function (SocialiteUser $user) {
112+
$user->id = '123';
113+
$user->name = 'bar';
114+
$user->email = '[email protected]';
115+
});
116+
117117
$this->expectException(QueryException::class);
118118

119119
(new UserProviderRepository)->updateOrCreate('bar', $socialite);

0 commit comments

Comments
 (0)