2021-06-19 00:44:56 +02:00
< ? php
namespace Zoomyboy\LaravelNami\Tests\Unit ;
2021-11-18 19:57:59 +01:00
use Illuminate\Database\Eloquent\Model ;
2021-06-19 00:44:56 +02:00
use Illuminate\Support\Facades\Config ;
2021-11-18 19:57:59 +01:00
use Illuminate\Support\Facades\Http ;
2021-06-19 00:44:56 +02:00
use Zoomyboy\LaravelNami\Group ;
2021-11-18 19:57:59 +01:00
use Zoomyboy\LaravelNami\LoginException ;
2021-06-19 00:44:56 +02:00
use Zoomyboy\LaravelNami\Member ;
2021-11-18 19:57:59 +01:00
use Zoomyboy\LaravelNami\Nami ;
use Zoomyboy\LaravelNami\NamiServiceProvider ;
use Zoomyboy\LaravelNami\Tests\TestCase ;
2021-06-19 00:44:56 +02:00
class SearchTest extends TestCase
{
public $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":103}],"responseType":"OK"}' ;
public $unauthorizedResponse = '{"success":false,"data":null,"responseType":"EXCEPTION","message":"Access denied - no right for requested operation","title":"Exception"}' ;
public $attributes = [
[
'firstname' => 'Max' ,
'lastname' => 'Nach1' ,
'group_id' => 103 ,
'nickname' => 'spitz1' ,
'gender_id' => 17 ,
'id' => 16 ,
], [
'firstname' => 'Jane' ,
'lastname' => 'Nach2' ,
'nickname' => null ,
'group_id' => 103 ,
'gender_id' => null ,
'id' => 17 ,
]
];
public function dataProvider () {
return [
'firstname' => [ 'vorname' , [ 'Max' , 'Jane' ]],
];
}
public function test_find_a_member_by_mglnr () {
Http :: fake ( array_merge ( $this -> login (), [
$this -> url ([ 'mitgliedsNummber' => 150 ]) => Http :: response ( $this -> fakeJson ( 'searchResponse.json' ), 200 ),
]));
$this -> setCredentials ();
Nami :: login ();
$member = Nami :: findNr ( 150 );
$this -> assertEquals ( 'Philipp' , $member -> firstname );
Http :: assertSent ( function ( $request ) {
return $request -> url () == $this -> url ([ 'mitgliedsNummber' => 150 ])
&& $request -> method () == 'GET' ;
});
Http :: assertSentCount ( 3 );
}
private function url ( $payload ) {
$payload = rawurlencode ( json_encode ( $payload ));
2021-11-18 19:57:59 +01:00
return " https://nami.dpsg.de/ica/rest/nami/search-multi/result-list?searchedValues= { $payload } &page=1&start=0&limit=100 " ;
2021-06-19 00:44:56 +02:00
}
}