Add search api
This commit is contained in:
parent
f690246a7e
commit
ab53a80c4d
|
@ -11,7 +11,7 @@ class RedirectIfNotInitializedMiddleware
|
|||
/**
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public array $dontRedirect = ['initialize.form', 'initialize.store', 'nami-login-check'];
|
||||
public array $dontRedirect = ['initialize.form', 'initialize.store', 'nami.search'];
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Initialize\Actions;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Lorisleiva\Actions\ActionRequest;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
use Zoomyboy\LaravelNami\Api;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
|
||||
class NamiSearchAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
public function handle(Api $api, int $page, array $params)
|
||||
{
|
||||
return $api->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')));
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
Subproject commit 75983ebb4bad205629b57e18915b2f15fa38e835
|
||||
Subproject commit 7a290a105f5ff9cdba262d1310c5fa75191d7de0
|
|
@ -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');
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Initializer;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
use Zoomyboy\LaravelNami\Authentication\Auth;
|
||||
use Zoomyboy\LaravelNami\Fakes\SearchFake;
|
||||
|
||||
class SearchTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->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,
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue