Add gender as a nami field

This commit is contained in:
philipp lang 2024-06-12 00:14:25 +02:00
parent 700d69d1a2
commit 86aaf55d21
3 changed files with 32 additions and 5 deletions

View File

@ -18,6 +18,7 @@ enum NamiType: string
case ADDRESS = 'Adresse';
case ZIP = 'PLZ';
case LOCATION = 'Ort';
case GENDER = 'Geschlecht';
/**
* @return array<int, array{name: string, id: string}>
@ -42,6 +43,7 @@ enum NamiType: string
static::ZIP => $member->zip,
static::LOCATION => $member->location,
static::NICKNAME => $member->nickname,
static::GENDER => $member->gender?->name,
};
}

View File

@ -3,7 +3,7 @@
namespace Database\Factories\Member;
use App\Country;
use App\Fee;
use App\Gender;
use App\Group;
use App\Invoice\BillKind;
use App\Member\Member;
@ -68,6 +68,16 @@ class MemberFactory extends Factory
]);
}
public function male(): self
{
return $this->for(Gender::factory()->male());
}
public function female(): self
{
return $this->for(Gender::factory()->female());
}
public function emailBillKind(): self
{
return $this->state([

View File

@ -10,6 +10,7 @@ use App\Group;
use App\Group\Enums\Level;
use App\Member\Member;
use Carbon\Carbon;
use Database\Factories\Member\MemberFactory;
use Generator;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Mail;
@ -480,6 +481,19 @@ class FormRegisterActionTest extends FormTestCase
NamiType::BIRTHDAY,
'2023-06-06'
];
yield [
[],
NamiType::GENDER,
'Männlich',
fn (MemberFactory $factory) => $factory->male(),
];
yield [
['gender_id' => null],
NamiType::GENDER,
'',
];
}
/**
@ -487,10 +501,10 @@ class FormRegisterActionTest extends FormTestCase
* @param array<string, string> $memberAttributes
* @param mixed $participantValue
*/
public function testItSynchsMemberAttributes(array $memberAttributes, NamiType $type, mixed $participantValue): void
public function testItSynchsMemberAttributes(array $memberAttributes, NamiType $type, mixed $participantValue, ?callable $factory = null): void
{
$this->login()->loginNami();
$this->createMember(['mitgliedsnr' => '5505', ...$memberAttributes]);
$this->createMember(['mitgliedsnr' => '5505', ...$memberAttributes], $factory);
$form = Form::factory()->fields([
$this->namiField('members'),
$this->textField('other')->required(true)->namiType($type),
@ -666,9 +680,10 @@ class FormRegisterActionTest extends FormTestCase
/**
* @param array<string, mixed> $attributes
*/
protected function createMember(array $attributes): Member
protected function createMember(array $attributes, ?callable $factoryCallback = null): Member
{
return Member::factory()->defaults()->create($attributes);
return call_user_func($factoryCallback ?: fn ($factory) => $factory, Member::factory()->defaults())
->create($attributes);
}
/**