diff --git a/app/Console/Commands/NamiInitializeCommand.php b/app/Console/Commands/NamiInitializeCommand.php index fe22b94c..55c80e2f 100644 --- a/app/Console/Commands/NamiInitializeCommand.php +++ b/app/Console/Commands/NamiInitializeCommand.php @@ -5,7 +5,6 @@ namespace App\Console\Commands; use App\Initialize\Initializer; use Illuminate\Console\Command; use Zoomyboy\LaravelNami\Nami; -use Zoomyboy\LaravelNami\NamiUser; class NamiInitializeCommand extends Command { @@ -40,15 +39,7 @@ class NamiInitializeCommand extends Command */ public function handle() { - app(Initializer::class)->run(NamiUser::fromPayload([ - 'credentials' => [ - 'mglnr' => $this->option('mglnr'), - 'password' => $this->option('password'), - ], - 'firstname' => 'Console', - 'lastname' => 'Console', - 'group_id' => $this->option('group_id'), - ])); + app(Initializer::class)->run(); return 0; } diff --git a/app/Course/Controllers/CourseController.php b/app/Course/Controllers/CourseController.php index 25dbd0ed..8c5276be 100644 --- a/app/Course/Controllers/CourseController.php +++ b/app/Course/Controllers/CourseController.php @@ -21,16 +21,16 @@ class CourseController extends Controller return redirect()->back()->success('Ausbildung erstellt'); } - public function update(Member $member, CourseMember $course, UpdateRequest $request): RedirectResponse + public function update(Member $member, CourseMember $course, UpdateRequest $request, NamiSettings $settings): RedirectResponse { - $request->persist($member, $course); + $request->persist($member, $course, $settings); return redirect()->back()->success('Ausbildung aktualisiert'); } - public function destroy(Member $member, CourseMember $course, DestroyRequest $request): RedirectResponse + public function destroy(Member $member, CourseMember $course, DestroyRequest $request, NamiSettings $settings): RedirectResponse { - $request->persist($member, $course); + $request->persist($member, $course, $settings); return redirect()->back()->success('Ausbildung gelöscht'); } diff --git a/app/Course/Requests/DestroyRequest.php b/app/Course/Requests/DestroyRequest.php index 74613780..744d600b 100644 --- a/app/Course/Requests/DestroyRequest.php +++ b/app/Course/Requests/DestroyRequest.php @@ -5,6 +5,7 @@ namespace App\Course\Requests; use App\Course\Models\Course; use App\Course\Models\CourseMember; use App\Member\Member; +use App\Setting\NamiSettings; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Arr; use Illuminate\Validation\ValidationException; @@ -32,13 +33,9 @@ class DestroyRequest extends FormRequest return []; } - public function persist(Member $member, CourseMember $course): void + public function persist(Member $member, CourseMember $course, NamiSettings $settings): void { - try { - auth()->user()->api()->deleteCourse($member->nami_id, $course->nami_id); - } catch(NamiException $e) { - throw ValidationException::withMessages(['id' => 'Unbekannter Fehler']); - } + $settings->login()->deleteCourse($member->nami_id, $course->nami_id); $course->delete(); } diff --git a/app/Course/Requests/StoreRequest.php b/app/Course/Requests/StoreRequest.php index 09b94ee9..5434fd8b 100644 --- a/app/Course/Requests/StoreRequest.php +++ b/app/Course/Requests/StoreRequest.php @@ -47,11 +47,7 @@ class StoreRequest extends FormRequest 'course_id' => $course->nami_id, ])->toArray(); - try { - $namiId = Nami::login($settings->mglnr, $settings->password)->createCourse($member->nami_id, $payload); - } catch(NamiException $e) { - throw ValidationException::withMessages(['id' => 'Unbekannter Fehler']); - } + $namiId = $settings->login()->createCourse($member->nami_id, $payload); $member->courses()->create($this->safe()->collect()->put('nami_id', $namiId)->toArray()); } diff --git a/app/Course/Requests/UpdateRequest.php b/app/Course/Requests/UpdateRequest.php index 05b0c268..e179e334 100644 --- a/app/Course/Requests/UpdateRequest.php +++ b/app/Course/Requests/UpdateRequest.php @@ -5,6 +5,7 @@ namespace App\Course\Requests; use App\Course\Models\Course; use App\Course\Models\CourseMember; use App\Member\Member; +use App\Setting\NamiSettings; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Arr; use Illuminate\Validation\ValidationException; @@ -37,13 +38,13 @@ class UpdateRequest extends FormRequest ]; } - public function persist(Member $member, CourseMember $course): void + public function persist(Member $member, CourseMember $course, NamiSettings $settings): void { - try { - auth()->user()->api()->updateCourse($member->nami_id, $course->nami_id, $this->safe()->merge(['course_id' => Course::find($this->input('course_id'))->nami_id])->toArray()); - } catch(NamiException $e) { - throw ValidationException::withMessages(['id' => 'Unbekannter Fehler']); - } + $settings->login()->updateCourse( + $member->nami_id, + $course->nami_id, + $this->safe()->merge(['course_id' => Course::find($this->input('course_id'))->nami_id])->toArray() + ); $course->update($this->safe()->toArray()); } diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index c9fc9315..1300def6 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -39,13 +39,6 @@ class Handler extends ExceptionHandler */ public function report(Throwable $exception) { - if (is_a($exception, NamiException::class)) { - \Log::error($exception->getMessage(), [ - 'request' => $exception->request, - 'response' => $exception->response - ]); - } - parent::report($exception); } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index cf70fced..c320716a 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -4,8 +4,8 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use App\Providers\RouteServiceProvider; +use Illuminate\Foundation\Auth\AuthenticatesUsers; use Inertia\Response; -use Zoomyboy\LaravelNami\AuthenticatesNamiUsers; class LoginController extends Controller { @@ -20,7 +20,7 @@ class LoginController extends Controller | */ - use AuthenticatesNamiUsers; + use AuthenticatesUsers; /** * Where to redirect users after login. @@ -42,4 +42,5 @@ class LoginController extends Controller public function showLoginForm(): Response { return \Inertia::render('VLogin'); } + } diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index d3689e5e..f2b9b65d 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -6,7 +6,7 @@ use Illuminate\Http\Resources\Json\JsonResource; use Storage; /** - * @mixin \Zoomyboy\LaravelNami\NamiUser + * @mixin \App\User */ class UserResource extends JsonResource { @@ -19,8 +19,8 @@ class UserResource extends JsonResource public function toArray($request) { return [ - 'name' => $this->getFirstname(), - 'email' => null, + 'name' => $this->name, + 'email' => $this->email, 'avatar' => [ 'src' => Storage::url('avatar.png') ] diff --git a/app/Initialize/InitializeActivities.php b/app/Initialize/InitializeActivities.php index 4678fe8d..0717d246 100644 --- a/app/Initialize/InitializeActivities.php +++ b/app/Initialize/InitializeActivities.php @@ -3,7 +3,6 @@ namespace App\Initialize; use Zoomyboy\LaravelNami\Api; -use Zoomyboy\LaravelNami\NamiUser; class InitializeActivities { @@ -13,8 +12,9 @@ class InitializeActivities { $this->api = $api; } - public function handle(NamiUser $user): void + public function handle(): void { - app(ActivityCreator::class)->createFor($this->api, $user->getNamiGroupId()); + $groupId = $this->api->groups()->first()->id; + app(ActivityCreator::class)->createFor($this->api, $groupId); } } diff --git a/app/Initialize/InitializeCourses.php b/app/Initialize/InitializeCourses.php index bea52ff0..cd1ef667 100644 --- a/app/Initialize/InitializeCourses.php +++ b/app/Initialize/InitializeCourses.php @@ -5,7 +5,6 @@ namespace App\Initialize; use App\Course\Models\Course; use Aweos\Agnoster\Progress\Progress; use Zoomyboy\LaravelNami\Api; -use Zoomyboy\LaravelNami\NamiUser; class InitializeCourses { @@ -15,7 +14,7 @@ class InitializeCourses { $this->api = $api; } - public function handle(NamiUser $user): void + public function handle(): void { $this->api->courses()->each(function($course) { Course::create(['nami_id' => $course->id, 'name' => $course->name]); diff --git a/app/Initialize/InitializeFees.php b/app/Initialize/InitializeFees.php index de432274..2ac55833 100644 --- a/app/Initialize/InitializeFees.php +++ b/app/Initialize/InitializeFees.php @@ -2,8 +2,8 @@ namespace App\Initialize; +use App\Fee; use Zoomyboy\LaravelNami\Api; -use Zoomyboy\LaravelNami\NamiUser; class InitializeFees { @@ -13,10 +13,11 @@ class InitializeFees { $this->api = $api; } - public function handle(NamiUser $user): void + public function handle(): void { - $this->api->feesOf($user->getNamiGroupId())->each(function($fee) { - \App\Fee::create(['nami_id' => $fee->id, 'name' => $fee->name]) + $group = $this->api->groups()->first()->id; + $this->api->feesOf($group)->each(function($fee) { + Fee::create(['nami_id' => $fee->id, 'name' => $fee->name]) ->subscriptions()->create([ 'name' => $fee->name, 'amount' => 1000, diff --git a/app/Initialize/InitializeGenders.php b/app/Initialize/InitializeGenders.php index b5447042..d81b376e 100644 --- a/app/Initialize/InitializeGenders.php +++ b/app/Initialize/InitializeGenders.php @@ -3,7 +3,6 @@ namespace App\Initialize; use Zoomyboy\LaravelNami\Api; -use Zoomyboy\LaravelNami\NamiUser; class InitializeGenders { @@ -13,7 +12,7 @@ class InitializeGenders { $this->api = $api; } - public function handle(NamiUser $user): void + public function handle(): void { $this->api->genders()->each(function($gender) { \App\Gender::create(['nami_id' => $gender->id, 'name' => $gender->name]); diff --git a/app/Initialize/InitializeGroups.php b/app/Initialize/InitializeGroups.php index 67e46aec..7a791c3a 100644 --- a/app/Initialize/InitializeGroups.php +++ b/app/Initialize/InitializeGroups.php @@ -4,7 +4,6 @@ namespace App\Initialize; use App\Group; use Zoomyboy\LaravelNami\Api; -use Zoomyboy\LaravelNami\NamiUser; class InitializeGroups { diff --git a/app/Initialize/InitializeJob.php b/app/Initialize/InitializeJob.php index 010f1262..5a05192c 100644 --- a/app/Initialize/InitializeJob.php +++ b/app/Initialize/InitializeJob.php @@ -9,19 +9,11 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Zoomyboy\LaravelNami\NamiUser; class InitializeJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasProgress; - public NamiUser $user; - - public function __construct(NamiUser $user) - { - $this->user = $user; - } - /** * Execute the job. * @@ -29,6 +21,6 @@ class InitializeJob implements ShouldQueue */ public function handle() { - app(Initializer::class)->run($this->user); + app(Initializer::class)->run(); } } diff --git a/app/Initialize/InitializeNationalities.php b/app/Initialize/InitializeNationalities.php index e0e066cc..07077205 100644 --- a/app/Initialize/InitializeNationalities.php +++ b/app/Initialize/InitializeNationalities.php @@ -2,6 +2,7 @@ namespace App\Initialize; +use App\Nationality; use Zoomyboy\LaravelNami\Api; class InitializeNationalities { @@ -12,10 +13,10 @@ class InitializeNationalities { $this->api = $api; } - public function handle(): void + public function handle(Api $api): void { $this->api->nationalities()->each(function($nationality) { - \App\Nationality::create(['nami_id' => $nationality->id, 'name' => $nationality->name]); + Nationality::create(['nami_id' => $nationality->id, 'name' => $nationality->name]); }); } } diff --git a/app/Initialize/Initializer.php b/app/Initialize/Initializer.php index 90baac3d..8effcb38 100644 --- a/app/Initialize/Initializer.php +++ b/app/Initialize/Initializer.php @@ -2,12 +2,13 @@ namespace App\Initialize; +use App\Setting\NamiSettings; use Zoomyboy\LaravelNami\Api; -use Zoomyboy\LaravelNami\NamiUser; class Initializer { - public static array $initializers = [ + public NamiSettings $settings; + public array $initializers = [ InitializeNationalities::class, InitializeFees::class, InitializeConfessions::class, @@ -19,9 +20,14 @@ class Initializer { InitializeMembers::class, ]; - public function run(NamiUser $namiUser): void { - foreach (static::$initializers as $initializer) { - (new $initializer($namiUser->api()))->handle($namiUser); + public function __construct(NamiSettings $settings) + { + $this->settings = $settings; + } + + public function run(): void { + foreach ($this->initializers as $initializer) { + app($initializer)->handle($this->settings->login()); } } diff --git a/app/Member/CreateJob.php b/app/Member/CreateJob.php index 784afd01..b03ca2f3 100644 --- a/app/Member/CreateJob.php +++ b/app/Member/CreateJob.php @@ -12,7 +12,6 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Zoomyboy\LaravelNami\Nami; -use Zoomyboy\LaravelNami\NamiUser; class CreateJob implements ShouldQueue { @@ -20,9 +19,8 @@ class CreateJob implements ShouldQueue public int $memberId; public Member $member; - public NamiUser $user; - public function __construct(Member $member, NamiUser $user) + public function __construct(Member $member) { $this->memberId = $member->id; $this->user = $user; diff --git a/app/Member/DeleteJob.php b/app/Member/DeleteJob.php index 02b8f84a..3870c084 100644 --- a/app/Member/DeleteJob.php +++ b/app/Member/DeleteJob.php @@ -9,7 +9,6 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Zoomyboy\LaravelNami\Nami; -use Zoomyboy\LaravelNami\NamiUser; class DeleteJob implements ShouldQueue { @@ -17,9 +16,8 @@ class DeleteJob implements ShouldQueue public int $memberId; public Member $member; - public NamiUser $user; - public function __construct(Member $member, NamiUser $user) + public function __construct(Member $member) { $this->memberId = $member->id; $this->user = $user; @@ -38,7 +36,7 @@ class DeleteJob implements ShouldQueue return; } - Nami::login($this->user->mglnr)->deleteMember($this->member->nami_id); + $setting->login()->deleteMember($this->member->nami_id); Member::withoutEvents(function() { $this->member->update(['nami_id' => null]); diff --git a/app/Member/UpdateJob.php b/app/Member/UpdateJob.php index f56d2b43..1cce0f79 100644 --- a/app/Member/UpdateJob.php +++ b/app/Member/UpdateJob.php @@ -10,7 +10,6 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Zoomyboy\LaravelNami\Nami; -use Zoomyboy\LaravelNami\NamiUser; class UpdateJob implements ShouldQueue { @@ -18,12 +17,10 @@ class UpdateJob implements ShouldQueue public int $memberId; public Member $member; - public NamiUser $user; - public function __construct(Member $member, NamiUser $user) + public function __construct(Member $member) { $this->memberId = $member->id; - $this->user = $user; } /** @@ -39,7 +36,7 @@ class UpdateJob implements ShouldQueue return; } - $response = Nami::login($this->user->mglnr)->putMember([ + $response = $this->service->login()->putMember([ 'firstname' => $this->member->firstname, 'lastname' => $this->member->lastname, 'joined_at' => $this->member->joined_at, diff --git a/app/Setting/NamiSettings.php b/app/Setting/NamiSettings.php index 7c1fdb78..394271bd 100644 --- a/app/Setting/NamiSettings.php +++ b/app/Setting/NamiSettings.php @@ -3,6 +3,8 @@ namespace App\Setting; use Spatie\LaravelSettings\Settings; +use Zoomyboy\LaravelNami\Api; +use Zoomyboy\LaravelNami\Nami; class NamiSettings extends Settings { @@ -16,4 +18,9 @@ class NamiSettings extends Settings return 'nami'; } + public function login(): Api + { + return Nami::login($this->mglnr, $this->password); + } + } diff --git a/packages/laravel-nami b/packages/laravel-nami index b8d2a04d..63cef423 160000 --- a/packages/laravel-nami +++ b/packages/laravel-nami @@ -1 +1 @@ -Subproject commit b8d2a04d43dd7634ac6e653b26b07b317c5566db +Subproject commit 63cef423857c4d87c0e813e761102f518502cd5f diff --git a/tests/Feature/Course/DeleteTest.php b/tests/Feature/Course/DeleteTest.php index 7d019b9f..b771ec63 100644 --- a/tests/Feature/Course/DeleteTest.php +++ b/tests/Feature/Course/DeleteTest.php @@ -18,8 +18,7 @@ class DeleteTest extends TestCase public function testItDeletesACourse(): void { - $this->withoutExceptionHandling(); - $this->login()->init(); + $this->login()->loginNami(); app(CourseFake::class)->deleteSuccessful(123, 999); $member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne(); @@ -31,14 +30,13 @@ class DeleteTest extends TestCase public function testItReceivesUnknownErrors(): void { - $this->login()->init(); + $this->login()->loginNami(); app(CourseFake::class)->deleteFailed(123, 999); $member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne(); $response = $this->delete("/member/{$member->id}/course/{$member->courses->first()->id}"); $this->assertDatabaseCount('course_members', 1); - $response->assertSessionHasErrors(['id' => 'Unbekannter Fehler']); } diff --git a/tests/Feature/Course/UpdateTest.php b/tests/Feature/Course/UpdateTest.php index 71ab5ccf..03d4605b 100644 --- a/tests/Feature/Course/UpdateTest.php +++ b/tests/Feature/Course/UpdateTest.php @@ -56,7 +56,7 @@ class UpdateTest extends TestCase */ public function testItValidatesInput(array $payload, array $errors): void { - $this->login(); + $this->login()->loginNami(); $member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->for(Course::factory()), 'courses')->createOne(); $newCourse = Course::factory()->inNami(789)->create(); @@ -67,13 +67,13 @@ class UpdateTest extends TestCase 'organizer' => '::org::', ], $payload)); - $response->assertSessionHasErrors($errors); + $this->assertErrors($errors, $response); } public function testItUpdatesACourse(): void { $this->withoutExceptionHandling(); - $this->login()->init(); + $this->login()->loginNami(); app(CourseFake::class)->updatesSuccessful(123, 999); $member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne(); $newCourse = Course::factory()->inNami(789)->create(); @@ -101,9 +101,25 @@ class UpdateTest extends TestCase ]); } + public function testItThrowsErrorWhenLoginIsWrong(): void + { + $this->login()->failedNami(); + $member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne(); + $newCourse = Course::factory()->inNami(789)->create(); + + $response = $this->patch("/member/{$member->id}/course/{$member->courses->first()->id}", array_merge([ + 'course_id' => $newCourse->id, + 'completed_at' => '1999-02-03', + 'event_name' => '::newevent::', + 'organizer' => '::neworg::', + ])); + + $this->assertErrors(['nami' => 'NaMi Login fehlgeschlagen.'], $response); + } + public function testItReceivesUnknownErrors(): void { - $this->login()->init(); + $this->login()->loginNami(); app(CourseFake::class)->doesntUpdateWithError(123, 999); $member = Member::factory()->defaults()->inNami(123)->has(CourseMember::factory()->inNami(999)->for(Course::factory()), 'courses')->createOne(); $newCourse = Course::factory()->inNami(789)->create(); diff --git a/tests/Feature/Initialize/InitializeTest.php b/tests/Feature/Initialize/InitializeTest.php index 4f3e3d24..ae7391a2 100644 --- a/tests/Feature/Initialize/InitializeTest.php +++ b/tests/Feature/Initialize/InitializeTest.php @@ -17,6 +17,7 @@ use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Http; use Tests\TestCase; use Zoomyboy\LaravelNami\Backend\FakeBackend; +use Zoomyboy\LaravelNami\Fakes\GroupFake; class InitializeTest extends TestCase { @@ -25,8 +26,8 @@ class InitializeTest extends TestCase public function initializeProvider(callable $callback = null): void { + app(GroupFake::class)->get([1000 => ['name' => 'testgroup']]); $backend = app(FakeBackend::class) - ->fakeLogin('123') ->addSearch(123, ['entries_vorname' => '::firstname::', 'entries_nachname' => '::lastname::', 'entries_gruppierungId' => 1000]) ->fakeNationalities([['name' => 'deutsch', 'id' => 291]]) ->fakeFees(1000, [['name' => 'Family', 'id' => 300]]) @@ -67,9 +68,8 @@ class InitializeTest extends TestCase public function testItInitializesAll(): void { - $this->withoutExceptionHandling(); + $this->withoutExceptionHandling()->login()->loginNami(); $this->initializeProvider(); - $this->login(); $this->post('/initialize'); @@ -119,12 +119,12 @@ class InitializeTest extends TestCase ]); $this->assertEquals([306], Activity::where('nami_id', 305)->firstOrFail()->subactivities()->pluck('nami_id')->toArray()); - Http::assertSentCount(16); + Http::assertSentCount(15); } public function testItInitializesFromCommandLine(): void { - $this->withoutExceptionHandling(); + $this->withoutExceptionHandling()->loginNami(); $this->initializeProvider(); GeneralSettings::fake(['allowed_nami_accounts' => [123]]); @@ -142,7 +142,7 @@ class InitializeTest extends TestCase public function testSyncCoursesOfMember(): void { - $this->withoutExceptionHandling(); + $this->withoutExceptionHandling()->login()->loginNami(); $this->initializeProvider(function($backend) { $backend->fakeMembers([ $this->member(['courses' => [ ['bausteinId' => 506, 'id' => 788, 'veranstalter' => 'KJA', 'vstgName' => 'eventname', 'vstgTag' => '2021-11-12 00:00:00'] ]]) @@ -345,7 +345,7 @@ class InitializeTest extends TestCase if (!$backendCallback) { $backendCallback = function($backend) { return $backend; }; } - $this->withoutExceptionHandling(); + $this->withoutExceptionHandling()->login()->loginNami(); $this->initializeProvider(function($backend) use ($membership, $backendCallback) { $backend->fakeMembers([ $this->member([ @@ -361,7 +361,6 @@ class InitializeTest extends TestCase ]); $backendCallback($backend); }); - $this->login(); $this->post('/initialize'); @@ -370,7 +369,7 @@ class InitializeTest extends TestCase public function testItDoesntGetMembersWithNoJoinedAtDate(): void { - $this->withoutExceptionHandling(); + $this->withoutExceptionHandling()->login()->loginNami(); $this->initializeProvider(function($backend) { $backend->fakeMembers([$this->member(['eintrittsdatum' => null])]); }); @@ -401,7 +400,7 @@ class InitializeTest extends TestCase */ public function testItInitializesPages(int $num): void { - $this->withoutExceptionHandling(); + $this->withoutExceptionHandling()->login()->loginNami(); $this->initializeProvider(function($backend) use ($num) { $members = collect([]); diff --git a/tests/Feature/UserLoginTest.php b/tests/Feature/UserLoginTest.php index 5b1d2353..dc4d4ca9 100644 --- a/tests/Feature/UserLoginTest.php +++ b/tests/Feature/UserLoginTest.php @@ -30,14 +30,10 @@ class UserLoginTest extends TestCase $this->post('/login', [ 'email' => 'mail@example.com', - 'provider' => 'database', 'password' => 'secret' ]); - $key = session()->get('auth_key'); - $cache = Cache::get("namiauth-{$key}"); - $this->assertEquals($user->id, data_get($cache, 'id')); - $this->assertTrue(auth()->check()); + $this->assertAuthenticated(); } public function testItThrowsExceptionWhenLoginFailed(): void @@ -47,7 +43,6 @@ class UserLoginTest extends TestCase $this->post('/login', [ 'email' => 'mail@example.com', - 'provider' => 'database', 'password' => 'wrong' ])->assertRedirect('/'); diff --git a/tests/TestCase.php b/tests/TestCase.php index 11722ddc..2dabda3b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -13,7 +13,6 @@ use Tests\Lib\TestsInertia; use Zoomyboy\LaravelNami\Authentication\Auth; use Zoomyboy\LaravelNami\Backend\FakeBackend; use Zoomyboy\LaravelNami\Nami; -use Zoomyboy\LaravelNami\NamiUser; abstract class TestCase extends BaseTestCase {