Add nullable fields
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
241b46da53
commit
609d452e56
|
@ -175,9 +175,9 @@ class Member extends Model
|
|||
return $this->memberships()->isLeader()->exists();
|
||||
}
|
||||
|
||||
public function getAge(): int
|
||||
public function getAge(): ?int
|
||||
{
|
||||
return $this->birthday->diffInYears(now());
|
||||
return $this->birthday?->diffInYears(now());
|
||||
}
|
||||
|
||||
// ---------------------------------- Relations ----------------------------------
|
||||
|
|
|
@ -35,8 +35,8 @@ class MemberResource extends JsonResource
|
|||
'zip' => $this->zip,
|
||||
'location' => $this->location,
|
||||
'send_newspaper' => $this->send_newspaper,
|
||||
'birthday' => $this->birthday->format('Y-m-d'),
|
||||
'birthday_human' => $this->birthday->format('d.m.Y'),
|
||||
'birthday' => $this->birthday?->format('Y-m-d'),
|
||||
'birthday_human' => $this->birthday?->format('d.m.Y'),
|
||||
'joined_at' => $this->joined_at->format('Y-m-d'),
|
||||
'joined_at_human' => $this->joined_at->format('d.m.Y'),
|
||||
'id' => $this->id,
|
||||
|
@ -100,7 +100,7 @@ class MemberResource extends JsonResource
|
|||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
*/
|
||||
public static function meta(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class() extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('members', function (Blueprint $table) {
|
||||
$table->date('birthday')->nullable(true)->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('members', function (Blueprint $table) {
|
||||
$table->date('birthday')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class() extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('members', function (Blueprint $table) {
|
||||
$table->string('address')->nullable(true)->change();
|
||||
$table->string('zip')->nullable(true)->change();
|
||||
$table->string('location')->nullable(true)->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('members', function (Blueprint $table) {
|
||||
$table->string('address')->nullable(false)->change();
|
||||
$table->string('zip')->nullable(false)->change();
|
||||
$table->string('location')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
};
|
|
@ -8,7 +8,6 @@ use App\Member\Member;
|
|||
use App\Member\Membership;
|
||||
use App\Payment\Payment;
|
||||
use App\Subactivity;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\RequestFactories\Child;
|
||||
use Tests\TestCase;
|
||||
|
@ -36,6 +35,25 @@ class IndexTest extends TestCase
|
|||
$this->assertInertiaHas($group->id, $response, 'data.data.0.group_id');
|
||||
}
|
||||
|
||||
public function testFieldsCanBeNull(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$group = Group::factory()->create();
|
||||
Member::factory()->defaults()->for($group)->create([
|
||||
'birthday' => null,
|
||||
'address' => null,
|
||||
'zip' => null,
|
||||
'location' => null,
|
||||
]);
|
||||
|
||||
$response = $this->get('/member');
|
||||
|
||||
$this->assertInertiaHas(null, $response, 'data.data.0.birthday');
|
||||
$this->assertInertiaHas(null, $response, 'data.data.0.address');
|
||||
$this->assertInertiaHas(null, $response, 'data.data.0.zip');
|
||||
$this->assertInertiaHas(null, $response, 'data.data.0.location');
|
||||
}
|
||||
|
||||
public function testItShowsEfzForEfzMembership(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
|
@ -159,5 +177,4 @@ class IndexTest extends TestCase
|
|||
|
||||
$this->assertInertiaHas('UUI', $response, 'data.meta.groups.1.name');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue