Remove genders that are null

This commit is contained in:
philipp lang 2021-04-11 16:45:37 +02:00
parent cd3a165504
commit 0a34e92a5b
3 changed files with 6 additions and 27 deletions

View File

@ -156,7 +156,7 @@ class Api {
public function genders(): Collection { public function genders(): Collection {
return collect($this->http()->get(self::$url."/ica/rest/baseadmin/geschlecht")['data'])->map(function($gender) { return collect($this->http()->get(self::$url."/ica/rest/baseadmin/geschlecht")['data'])->map(function($gender) {
return Gender::fromNami($gender); return Gender::fromNami($gender);
}); })->filter(fn($gender) => !$gender->isNull);
} }
public function nationalities(): Collection { public function nationalities(): Collection {

View File

@ -14,22 +14,14 @@ class Gender extends Model implements Nullable {
} }
public static function fromNami($item) { public static function fromNami($item) {
$item = collect($item) return new self([
->only(['descriptor', 'id']) 'id' => $item['id'],
->mapWithKeys(function($item,$key) { 'name' => ucfirst($item['descriptor'])
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() { public function getIsNullAttribute() {
return $this->attributes['id'] == self::getNullValue(); return $this->id == self::getNullValue();
} }
} }

View File

@ -21,7 +21,6 @@ class PullGenderTest extends TestCase
Nami::login(); Nami::login();
$this->assertEquals([ $this->assertEquals([
23 => 'Keine Angabe',
19 => 'Männlich', 19 => 'Männlich',
20 => 'Weiblich' 20 => 'Weiblich'
], Nami::genders()->pluck('name', 'id')->toArray()); ], Nami::genders()->pluck('name', 'id')->toArray());
@ -29,16 +28,4 @@ class PullGenderTest extends TestCase
Http::assertSentCount(3); 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);
}
} }