Fix: Store memebr
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2022-08-12 22:07:59 +02:00
parent c38f92314e
commit 9d53dfc772
12 changed files with 242 additions and 2 deletions

View File

@ -2,10 +2,13 @@
namespace App\Bill;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class BillKind extends Model
{
use HasFactory;
public $fillable = ['name'];
public $timestamps = false;
}

View File

@ -3,11 +3,13 @@
namespace App;
use App\Nami\HasNamiField;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Gender extends Model
{
use HasNamiField;
use HasFactory;
public $fillable = ['name', 'nami_id'];
}

View File

@ -65,13 +65,24 @@ class MemberRequest extends FormRequest
'without_efz_at' => 'nullable|date_format:Y-m-d',
'multiply_pv' => 'boolean',
'multiply_more_pv' => 'boolean',
'send_newspaper' => 'boolean',
'main_phone' => '',
'mobile_phone' => '',
'letter_address' => '',
'gender_id' => 'nullable|exists:genders,id',
'region_id' => 'nullable|exists:regions,id',
'nationality_id' => 'nullable|exists:nationalities,id',
'children_phone' => '',
'fax' => '',
];
}
public function persistCreate(NamiSettings $settings): void
{
$this->merge(['group_id' => Group::where('nami_id', $settings->default_group_id)->firstOrFail()->id]);
$member = Member::create($this->input());
$member = Member::create([
...$this->validated(),
'group_id' => Group::where('nami_id', $settings->default_group_id)->firstOrFail()->id,
]);
if ($this->input('has_nami')) {
CreateJob::dispatch($member);
}

View File

@ -3,10 +3,12 @@
namespace App;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Region extends Model
{
use HasFactory;
public $timestamps = false;
public $fillable = ['name', 'nami_id', 'is_null'];

View File

@ -0,0 +1,26 @@
<?php
namespace Database\Factories\Bill;
use App\Bill\BillKind;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<BillKind>
*/
class BillKindFactory extends Factory
{
public $model = BillKind::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'name' => $this->faker->words(3, true),
];
}
}

View File

@ -5,6 +5,9 @@ namespace Database\Factories;
use App\Country;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Country>
*/
class CountryFactory extends Factory
{
protected $model = Country::class;

View File

@ -0,0 +1,24 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Gender>
*/
class GenderFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'name' => $this->faker->words(3, true),
'nami_id' => $this->faker->numberBetween(100, 200),
];
}
}

View File

@ -5,6 +5,9 @@ namespace Database\Factories;
use App\Nationality;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Nationality>
*/
class NationalityFactory extends Factory
{
protected $model = Nationality::class;

View File

@ -0,0 +1,25 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Region>
*/
class RegionFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'name' => $this->faker->words(3, true),
'nami_id' => $this->faker->numberBetween(100, 200),
'is_null' => false,
];
}
}

View File

@ -0,0 +1,119 @@
<?php
namespace Tests\Feature\Member;
use App\Activity;
use App\Bill\BillKind;
use App\Country;
use App\Fee;
use App\Gender;
use App\Member\CreateJob;
use App\Member\Member;
use App\Nationality;
use App\Payment\Subscription;
use App\Region;
use App\Setting\NamiSettings;
use App\Subactivity;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Queue;
use Tests\Lib\MergesAttributes;
use Tests\TestCase;
class StoreTest extends TestCase
{
use DatabaseTransactions;
use MergesAttributes;
public function testItCanStoreAMember(): void
{
Queue::fake();
Fee::factory()->create();
NamiSettings::fake([
'default_group_id' => 55,
'password' => 'tt',
]);
$this->withoutExceptionHandling()->login()->loginNami();
$country = Country::factory()->create();
$gender = Gender::factory()->create();
$region = Region::factory()->create();
$nationality = Nationality::factory()->create();
$activity = Activity::factory()->create();
$subactivity = Subactivity::factory()->create();
$subscription = Subscription::factory()->create();
$billKind = BillKind::factory()->create();
$response = $this
->from('/member/create')
->post('/member', $this->attributes([
'country_id' => $country->id,
'gender_id' => $gender->id,
'region_id' => $region->id,
'nationality_id' => $nationality->id,
'first_activity_id' => $activity->id,
'first_subactivity_id' => $subactivity->id,
'subscription_id' => $subscription->id,
'bill_kind_id' => $billKind->id,
]));
$response->assertStatus(302)->assertSessionHasNoErrors();
$response->assertRedirect('/member');
$member = Member::firstWhere('firstname', 'Joe');
Queue::assertPushed(CreateJob::class, fn ($job) => $job->memberId === $member->id);
$this->assertDatabaseHas('members', [
'address' => 'Bavert 50',
'bill_kind_id' => $billKind->id,
'birthday' => '2013-02-19',
'children_phone' => '+49 123 44444',
'country_id' => $country->id,
'email_parents' => 'osloot@aol.com',
'firstname' => 'Joe',
'gender_id' => $gender->id,
'joined_at' => '2022-08-12',
'lastname' => 'Muster',
'letter_address' => null,
'location' => 'Solingen',
'main_phone' => '+49 212 2334322',
'mobile_phone' => '+49 157 53180451',
'nationality_id' => $nationality->id,
'region_id' => $region->id,
'send_newspaper' => '1',
'subscription_id' => $subscription->id,
'zip' => '42719',
'fax' => '+49 666',
]);
}
public function defaults(): array
{
return [
'address' => 'Bavert 50',
'birthday' => '2013-02-19',
'children_phone' => '+49 123 44444',
'efz' => '',
'email' => '',
'email_parents' => 'osloot@aol.com',
'fax' => '+49 666',
'firstname' => 'Joe',
'further_address' => '',
'has_nami' => true,
'has_svk' => false,
'has_vk' => false,
'joined_at' => '2022-08-12',
'lastname' => 'Muster',
'letter_address' => '',
'location' => 'Solingen',
'main_phone' => '+49 212 2334322',
'mobile_phone' => '+49 157 53180451',
'more_ps_at' => '',
'multiply_more_pv' => false,
'multiply_pv' => false,
'other_country' => '',
'ps_at' => '',
'send_newspaper' => true,
'without_education_at' => '',
'without_efz_at' => '',
'work_phone' => '',
'zip' => '42719',
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Tests\Lib;
trait MergesAttributes
{
abstract public function defaults();
public function attributes(?array $overwrites = []): array
{
$defaults = collect($this->defaults());
foreach ($overwrites as $key => $value) {
$defaults->put($key, $value);
}
return $defaults->toArray();
}
}

View File

@ -2,6 +2,7 @@
namespace Tests;
use App\Group;
use App\Member\Member;
use App\Setting\NamiSettings;
use App\User;
@ -30,7 +31,9 @@ abstract class TestCase extends BaseTestCase
NamiSettings::fake([
'mglnr' => $mglnr,
'password' => $password,
'default_group_id' => 55,
]);
Group::factory()->create(['nami_id' => 55]);
return $this;
}