Add genders

This commit is contained in:
philipp lang 2020-06-29 23:12:16 +02:00
parent fbe9498cdf
commit 8c70ed7c16
7 changed files with 180 additions and 7 deletions

View File

@ -94,6 +94,14 @@ class Api {
return $this->groups($groupId);
}
public function genders(): Collection {
return collect($this->http()->get(self::$url."/ica/rest/baseadmin/geschlecht")['data'])->map(function($gender) {
return Gender::fromNami($gender);
});
}
// -------------------------------------
public function fees() {
$response = $this->client->get("/ica/rest/namiBeitrag/beitragsartmgl/gruppierung/{$this->user->getNamiGroupId()}", [
'cookies' => $this->cookie
@ -118,13 +126,6 @@ class Api {
return json_decode((string)$response->getBody());
}
public function genders() {
$response = $this->client->get("/ica/rest/baseadmin/geschlecht", [
'cookies' => $this->cookie
]);
return json_decode((string)$response->getBody());
}
public function regions() {
$response = $this->client->get("/ica/rest/baseadmin/region", [

31
src/Gender.php Normal file
View File

@ -0,0 +1,31 @@
<?php
namespace Zoomyboy\LaravelNami;
use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;
class Gender extends Model implements Nullable {
protected $guarded = [];
public static function fromNami($item) {
$item = collect($item)
->only(['descriptor', 'id'])
->mapWithKeys(function($item,$key) {
if ($key == 'id') { return ['id' => $item]; }
return ['name' => $item];
})->toArray();
return (new self($item));
}
public function getNameAttribute() {
return ucfirst($this->attributes['name']);
}
public function getIsNullAttribute() {
return $this->attributes['name'] == 'keine Angabe';
}
}

9
src/Nullable.php Normal file
View File

@ -0,0 +1,9 @@
<?php
namespace Zoomyboy\LaravelNami;
interface Nullable {
public function getIsNullAttribute();
}

View File

@ -39,4 +39,10 @@ class TestCase extends \Orchestra\Testbench\TestCase
return file_get_contents(__DIR__.'/json/'.$file);
}
public function fakeGenders() {
return [
'https://nami.dpsg.de/ica/rest/baseadmin/geschlecht' => Http::response($this->fakeJson('genders.json'), 200)
];
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace Zoomyboy\LaravelNami\Tests\Unit;
use Zoomyboy\LaravelNami\Nami;
use Zoomyboy\LaravelNami\Tests\TestCase;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Config;
use Zoomyboy\LaravelNami\NamiServiceProvider;
use Zoomyboy\LaravelNami\LoginException;
use Zoomyboy\LaravelNami\Group;
class PullGenderTest extends TestCase
{
public function test_get_all_genders() {
Http::fake(array_merge($this->login(), $this->fakeGenders()));
$this->setCredentials();
Nami::login();
$this->assertEquals([
23 => 'Keine Angabe',
19 => 'Männlich',
20 => 'Weiblich'
], Nami::genders()->pluck('name', 'id')->toArray());
Http::assertSentCount(3);
}
public function test_a_gender_can_be_null() {
Http::fake(array_merge($this->login(), $this->fakeGenders()));
$this->setCredentials();
Nami::login();
$this->assertEquals([true, false, false], Nami::genders()->pluck('isNull')->toArray());
Http::assertSentCount(3);
}
}

View File

@ -33,6 +33,12 @@ class PullMemberTest extends TestCase
];
}
public function relationProvider() {
return [
'firstname' => ['firstname', ['Max', 'Jane']],
];
}
/**
* @dataProvider dataProvider
*/
@ -78,4 +84,27 @@ class PullMemberTest extends TestCase
Http::assertSentCount(6);
}
/**
* @dataProvider relationProvider
*/
public function test_set_relations($key, $values) {
Http::fake(array_merge($this->login(), [
'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/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/flist' => Http::response($this->fakeJson('member_overview.json'), 200),
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response($this->fakeJson('member-16.json'), 200),
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/17' => Http::response($this->fakeJson('member-17.json'), 200)
]));
$this->setCredentials();
Nami::login();
$this->assertEquals([
16 => $values[0],
17 => $values[1]
], Nami::group(103)->members()->pluck($key, 'id')->toArray());
Http::assertSentCount(6);
}
}

53
tests/json/genders.json Normal file
View File

@ -0,0 +1,53 @@
{
"success": true,
"data":
[
{
"descriptor": "keine Angabe",
"name": "",
"representedClass": "de.iconcept.nami.entity.base.Geschlecht",
"id": 23
},
{
"descriptor": "männlich",
"name": "",
"representedClass": "de.iconcept.nami.entity.base.Geschlecht",
"id": 19
},
{
"descriptor": "weiblich",
"name": "",
"representedClass": "de.iconcept.nami.entity.base.Geschlecht",
"id": 20
}
],
"responseType": "OK",
"totalEntries": 3,
"metaData":
{
"totalProperty": "totalEntries",
"root": "data",
"id": "id",
"fields":
[
{
"name": "id",
"header": null,
"hidden": false,
"width": 80
},
{
"name": "descriptor",
"header": null,
"hidden": false,
"flex": 3
},
{
"name": "name",
"header": null,
"hidden": false,
"flex": 3
}
]
}
}