|
9 | 9 | beforeEach(fn () => Bartender::setUserModel(User::class));
|
10 | 10 |
|
11 | 11 | 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 |
| - |
17 | 12 | User::create([
|
18 | 13 | 'provider_id' => '1',
|
19 | 14 | 'provider_name' => 'foo',
|
|
22 | 17 | 'password' => bcrypt('password'),
|
23 | 18 | ]);
|
24 | 19 |
|
25 |
| - expect((new UserProviderRepository)->exists('bar', $socialite))->toBeTrue(); |
26 |
| -}); |
27 |
| - |
28 |
| -it('determines if user already exists with no provider', function () { |
29 | 20 | $socialite = tap(new SocialiteUser(), function ($user) {
|
30 | 21 | $user->id = '1';
|
31 | 22 | $user-> email = '[email protected]';
|
32 | 23 | });
|
33 | 24 |
|
| 25 | + expect((new UserProviderRepository)->exists('bar', $socialite))->toBeTrue(); |
| 26 | +}); |
| 27 | + |
| 28 | +it('determines if user already exists with no provider', function () { |
34 | 29 | User::create([
|
35 | 30 | 'provider_id' => null,
|
36 | 31 | 'provider_name' => null,
|
|
39 | 34 | 'password' => bcrypt('password'),
|
40 | 35 | ]);
|
41 | 36 |
|
| 37 | + $socialite = tap(new SocialiteUser(), function ($user) { |
| 38 | + $user->id = '1'; |
| 39 | + $user-> email = '[email protected]'; |
| 40 | + }); |
| 41 | + |
42 | 42 | expect((new UserProviderRepository)->exists('bar', $socialite))->toBeTrue();
|
43 | 43 | });
|
44 | 44 |
|
|
58 | 58 | });
|
59 | 59 |
|
60 | 60 | 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 |
| - |
67 | 61 | User::create([
|
68 | 62 | 'provider_id' => '1',
|
69 | 63 | 'provider_name' => 'foo',
|
|
72 | 66 | 'password' => 'password',
|
73 | 67 | ]);
|
74 | 68 |
|
| 69 | + $socialite = tap(new SocialiteUser(), function (SocialiteUser $user) { |
| 70 | + $user->id = '1'; |
| 71 | + $user->name = 'foo'; |
| 72 | + $user-> email = '[email protected]'; |
| 73 | + }); |
| 74 | + |
75 | 75 | $user = (new UserProviderRepository)->updateOrCreate('foo', $socialite);
|
76 | 76 |
|
77 | 77 | expect($user->wasRecentlyCreated)->toBeFalse();
|
|
82 | 82 | });
|
83 | 83 |
|
84 | 84 | 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 |
| - |
91 | 85 | User::create([
|
92 | 86 | 'name' => 'bar',
|
93 | 87 |
|
|
96 | 90 |
|
97 | 91 | $this->expectException(QueryException::class);
|
98 | 92 |
|
99 |
| - (new UserProviderRepository)->updateOrCreate('foo', $socialite); |
100 |
| -}); |
101 |
| - |
102 |
| -it('throws exception when attempting to create existing user with another provider', function () { |
103 | 93 | $socialite = tap(new SocialiteUser(), function (SocialiteUser $user) {
|
104 |
| - $user->id = '123'; |
| 94 | + $user->id = '1'; |
105 | 95 | $user->name = 'foo';
|
106 | 96 | $user-> email = '[email protected]';
|
107 | 97 | });
|
108 | 98 |
|
| 99 | + (new UserProviderRepository)->updateOrCreate('foo', $socialite); |
| 100 | +}); |
| 101 | + |
| 102 | +it('throws exception when attempting to create existing user with another provider', function () { |
109 | 103 | User::create([
|
110 | 104 | 'name' => 'bar',
|
111 | 105 | 'provider_id' => '456',
|
|
114 | 108 | 'password' => 'password',
|
115 | 109 | ]);
|
116 | 110 |
|
| 111 | + $socialite = tap(new SocialiteUser(), function (SocialiteUser $user) { |
| 112 | + $user->id = '123'; |
| 113 | + $user->name = 'bar'; |
| 114 | + $user-> email = '[email protected]'; |
| 115 | + }); |
| 116 | + |
117 | 117 | $this->expectException(QueryException::class);
|
118 | 118 |
|
119 | 119 | (new UserProviderRepository)->updateOrCreate('bar', $socialite);
|
|
0 commit comments