diff --git a/src/Api.php b/src/Api.php index 0ab3eb9..da9cdb3 100644 --- a/src/Api.php +++ b/src/Api.php @@ -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", [ diff --git a/src/Gender.php b/src/Gender.php new file mode 100644 index 0000000..dab8b8b --- /dev/null +++ b/src/Gender.php @@ -0,0 +1,31 @@ +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'; + } + +} diff --git a/src/Nullable.php b/src/Nullable.php new file mode 100644 index 0000000..f2eed24 --- /dev/null +++ b/src/Nullable.php @@ -0,0 +1,9 @@ + Http::response($this->fakeJson('genders.json'), 200) + ]; + } + } diff --git a/tests/Unit/PullGenderTest.php b/tests/Unit/PullGenderTest.php new file mode 100644 index 0000000..585fd22 --- /dev/null +++ b/tests/Unit/PullGenderTest.php @@ -0,0 +1,44 @@ +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); + } + +} diff --git a/tests/Unit/PullMemberTest.php b/tests/Unit/PullMemberTest.php index a6470c1..910f68a 100644 --- a/tests/Unit/PullMemberTest.php +++ b/tests/Unit/PullMemberTest.php @@ -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); + } + } diff --git a/tests/json/genders.json b/tests/json/genders.json new file mode 100644 index 0000000..f7b4a49 --- /dev/null +++ b/tests/json/genders.json @@ -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 + } + ] + } +}