diff --git a/app/Http/Middleware/RedirectIfNotInitializedMiddleware.php b/app/Http/Middleware/RedirectIfNotInitializedMiddleware.php index 0aaea334..8b01d049 100644 --- a/app/Http/Middleware/RedirectIfNotInitializedMiddleware.php +++ b/app/Http/Middleware/RedirectIfNotInitializedMiddleware.php @@ -11,7 +11,7 @@ class RedirectIfNotInitializedMiddleware /** * @var array */ - public array $dontRedirect = ['initialize.form', 'initialize.store', 'nami-login-check']; + public array $dontRedirect = ['initialize.form', 'initialize.store', 'nami.search']; /** * Handle an incoming request. diff --git a/app/Initialize/Actions/NamiSearchAction.php b/app/Initialize/Actions/NamiSearchAction.php new file mode 100644 index 00000000..e7de47ac --- /dev/null +++ b/app/Initialize/Actions/NamiSearchAction.php @@ -0,0 +1,35 @@ +pageSearch($params, $page, 10)->toArray(); + } + + public function rules(): array + { + return [ + 'mglnr' => 'required|numeric|min:0', + 'password' => 'required|string', + 'params' => 'array', + ]; + } + + public function asController(ActionRequest $request): JsonResponse + { + $api = Nami::login($request->input('mglnr'), $request->input('password')); + + return response()->json($this->handle($api, $request->input('page', 1), $request->input('params'))); + } +} diff --git a/packages/laravel-nami b/packages/laravel-nami index 75983ebb..7a290a10 160000 --- a/packages/laravel-nami +++ b/packages/laravel-nami @@ -1 +1 @@ -Subproject commit 75983ebb4bad205629b57e18915b2f15fa38e835 +Subproject commit 7a290a105f5ff9cdba262d1310c5fa75191d7de0 diff --git a/routes/web.php b/routes/web.php index 537809b8..8f6f4b1e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -17,7 +17,7 @@ use App\Dashboard\Actions\IndexAction as DashboardIndexAction; use App\Efz\ShowEfzDocumentAction; use App\Initialize\Actions\InitializeAction; use App\Initialize\Actions\InitializeFormAction; -use App\Initialize\Actions\NamiLoginCheckAction; +use App\Initialize\Actions\NamiSearchAction; use App\Member\Actions\ExportAction; use App\Member\Actions\MemberResyncAction; use App\Member\Actions\MemberShowAction; @@ -39,7 +39,7 @@ Route::group(['namespace' => 'App\\Http\\Controllers'], function (): void { Route::group(['middleware' => 'auth:web'], function (): void { Route::get('/', DashboardIndexAction::class)->name('home'); - Route::post('/nami-login-check', NamiLoginCheckAction::class)->name('nami-login-check'); + Route::post('/nami/search', NamiSearchAction::class)->name('nami.search'); Route::post('/api/member/search', SearchAction::class)->name('member.search'); Route::get('/initialize', InitializeFormAction::class)->name('initialize.form'); Route::post('/initialize', InitializeAction::class)->name('initialize.store'); diff --git a/tests/Feature/Initializer/SearchTest.php b/tests/Feature/Initializer/SearchTest.php new file mode 100644 index 00000000..b3159874 --- /dev/null +++ b/tests/Feature/Initializer/SearchTest.php @@ -0,0 +1,94 @@ +login(); + } + + public function testItSearchesForMembers(): void + { + $this->withoutExceptionHandling(); + app(SearchFake::class)->fetches(1, 0, 10, [ + ['id' => 2, 'entries_gruppierungId' => 100, 'entries_vorname' => 'Max', 'entries_nachname' => 'Muster', 'entries_stufe' => 'Wölfling', 'entries_geburtsDatum' => '2013-07-04 00:00:00'], + ['id' => 2, 'entries_gruppierungId' => 150, 'entries_vorname' => 'Jane', 'entries_nachname' => 'Muster', 'entries_stufe' => 'Wölfling', 'entries_geburtsDatum' => '2013-07-04 00:00:00'], + ]); + Auth::success(333, 'secret'); + + $repsonse = $this->postJson('/nami/search', [ + 'params' => [ + 'gruppierung1Id' => 100, + 'gruppierung2Id' => 101, + ], + 'mglnr' => 333, + 'password' => 'secret', + ]); + + $repsonse->assertOk(); + $repsonse->assertJsonPath('data.0.birthday_human', '04.07.2013'); + $repsonse->assertJsonPath('data.0.firstname', 'Max'); + $repsonse->assertJsonPath('data.0.lastname', 'Muster'); + $repsonse->assertJsonPath('data.0.id', 2); + $repsonse->assertJsonPath('data.0.groupId', 100); + $repsonse->assertJsonPath('data.0.agegroup', 'Wölfling'); + app(SearchFake::class)->assertFetched(1, 0, 10, [ + 'gruppierung1Id' => 100, + 'gruppierung2Id' => 101, + ]); + } + + public function testItDoesntNeedFirstname(): void + { + $this->withoutExceptionHandling(); + app(SearchFake::class)->fetches(1, 0, 10, [ + ['id' => 2, 'entries_gruppierungId' => 100, 'entries_vorname' => null, 'entries_nachname' => 'Muster', 'entries_stufe' => null, 'entries_geburtsDatum' => 'lalala'], + ]); + Auth::success(333, 'secret'); + + $this->postJson('/nami/search', [ + 'params' => [], + 'mglnr' => 333, + 'password' => 'secret', + 'birthday_human' => null, + 'agegroup' => null, + ])->assertJsonPath('data.0.firstname', null); + } + + public function testItGetsPageInformation(): void + { + $this->withoutExceptionHandling(); + app(SearchFake::class)->fetches(2, 10, 10, [ + ['id' => 2, 'entries_gruppierungId' => 100, 'entries_vorname' => 'Max', 'entries_nachname' => 'Muster'], + ['id' => 2, 'entries_gruppierungId' => 100, 'entries_vorname' => 'Max', 'entries_nachname' => 'Muster'], + ]); + Auth::success(333, 'secret'); + + $response = $this->postJson('/nami/search', [ + 'params' => [ + 'gruppierung1Id' => 100, + 'gruppierung2Id' => 101, + ], + 'page' => 2, + 'mglnr' => 333, + 'password' => 'secret', + ]); + + $response->assertOk(); + app(SearchFake::class)->assertFetched(2, 10, 10, [ + 'gruppierung1Id' => 100, + 'gruppierung2Id' => 101, + ]); + } +}