Add: Fetch subgroups of group
This commit is contained in:
parent
4cf210abda
commit
6506480d20
20
src/Api.php
20
src/Api.php
|
@ -64,15 +64,23 @@ class Api {
|
|||
}) !== false;
|
||||
}
|
||||
|
||||
public function groups(): Collection {
|
||||
return collect($this->http()->get(self::$url.'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root')->json()['data'])->map(function($group) {
|
||||
return (object) [
|
||||
'name' => $group['descriptor'],
|
||||
'id' => $group['id']
|
||||
];
|
||||
public function groups($parentGroupId = null): Collection {
|
||||
$parentGroupId = $parentGroupId ?: 'root';
|
||||
return collect($this->http()->get(self::$url.'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/'.$parentGroupId)->json()['data'])->map(function($group) {
|
||||
return Group::fromResponse($group);
|
||||
});
|
||||
}
|
||||
|
||||
public function group($groupId) {
|
||||
return $this->groups()->first(function($group) use ($groupId) {
|
||||
return $group->id == $groupId;
|
||||
});
|
||||
}
|
||||
|
||||
public function subgroupsOf($groupId) {
|
||||
return $this->groups($groupId);
|
||||
}
|
||||
|
||||
public function fees() {
|
||||
$response = $this->client->get("/ica/rest/namiBeitrag/beitragsartmgl/gruppierung/{$this->user->getNamiGroupId()}", [
|
||||
'cookies' => $this->cookie
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami;
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
class Group implements Arrayable {
|
||||
|
||||
public $name;
|
||||
public $id;
|
||||
|
||||
public static function fromResponse($response) {
|
||||
$group = new self();
|
||||
$group->name = $response['descriptor'];
|
||||
$group->id = $response['id'];
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [ 'id' => $this->id, 'name' => $this->name ];
|
||||
}
|
||||
|
||||
public function subgroups() {
|
||||
return Nami::subgroupsOf($this->id);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,11 +8,14 @@ use Illuminate\Support\Facades\Http;
|
|||
use Illuminate\Support\Facades\Config;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Group;
|
||||
|
||||
class GetGroupsTest extends TestCase
|
||||
{
|
||||
|
||||
public $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":100}],"responseType":"OK"}';
|
||||
public $subgroupsResponse = '{ "success": true, "data": [ { "descriptor": "Siebengebirge", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 101300 }, { "descriptor": "Sieg", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100900 }, { "descriptor": "Sieg", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100900 }, { "descriptor": "Voreifel", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 101000 } ], "responseType": "OK" }';
|
||||
public $subsubgroupsResponse = '{ "success": true, "data": [ { "descriptor": "Silva", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100105 } ], "responseType": "OK" }';
|
||||
|
||||
public function test_get_all_groups()
|
||||
{
|
||||
|
@ -26,7 +29,7 @@ class GetGroupsTest extends TestCase
|
|||
|
||||
Nami::login();
|
||||
$this->assertEquals([
|
||||
(object) ['id' => 100, 'name' => 'Group']
|
||||
['id' => 100, 'name' => 'Group']
|
||||
], Nami::groups()->toArray());
|
||||
|
||||
Http::assertSent(function($request) {
|
||||
|
@ -51,4 +54,39 @@ class GetGroupsTest extends TestCase
|
|||
|
||||
Http::assertSentCount(4);
|
||||
}
|
||||
|
||||
public function test_get_subgroups_for_a_group() {
|
||||
Http::fake([
|
||||
'https://nami.dpsg.de/ica/pages/login.jsp' => Http::response('<html></html>', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::response($this->successJson, 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/100' => Http::response($this->subgroupsResponse, 200)
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
|
||||
$subgroups = Nami::group(100)->subgroups();
|
||||
|
||||
$this->assertEquals([
|
||||
['id' => 101300, 'name' => 'Siebengebirge'],
|
||||
['id' => 100900, 'name' => 'Sieg'],
|
||||
['id' => 100900, 'name' => 'Sieg'],
|
||||
['id' => 101000, 'name' => 'Voreifel']
|
||||
], $subgroups->toArray());
|
||||
|
||||
$subgroups->each(function($group) {
|
||||
$this->assertInstanceOf(Group::class, $group);
|
||||
});
|
||||
|
||||
Http::assertSent(function($request) {
|
||||
return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root';
|
||||
});
|
||||
Http::assertSent(function($request) {
|
||||
return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/100';
|
||||
});
|
||||
|
||||
Http::assertSentCount(4);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue