Lint tests
This commit is contained in:
parent
37c9021e76
commit
793f916581
|
@ -17,277 +17,220 @@ use App\Region;
|
||||||
use App\Subactivity;
|
use App\Subactivity;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Tests\Lib\MergesAttributes;
|
use Tests\Lib\MergesAttributes;
|
||||||
|
use Tests\RequestFactories\MemberStoreRequestFactory;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use Zoomyboy\LaravelNami\Fakes\MemberFake;
|
use Zoomyboy\LaravelNami\Fakes\MemberFake;
|
||||||
|
|
||||||
class StoreTest extends TestCase
|
uses(DatabaseTransactions::class);
|
||||||
{
|
|
||||||
use DatabaseTransactions;
|
|
||||||
use MergesAttributes;
|
|
||||||
|
|
||||||
public function testItCanStoreAMember(): void
|
it('can store a member', function () {
|
||||||
{
|
app(MemberFake::class)->stores(55, 103);
|
||||||
app(MemberFake::class)->stores(55, 103);
|
Fee::factory()->create();
|
||||||
Fee::factory()->create();
|
$this->withoutExceptionHandling()->login()->loginNami();
|
||||||
$this->withoutExceptionHandling()->login()->loginNami();
|
$country = Country::factory()->create();
|
||||||
$country = Country::factory()->create();
|
$gender = Gender::factory()->create();
|
||||||
$gender = Gender::factory()->create();
|
$region = Region::factory()->create();
|
||||||
$region = Region::factory()->create();
|
$nationality = Nationality::factory()->create();
|
||||||
$nationality = Nationality::factory()->create();
|
$activity = Activity::factory()->inNami(89)->create();
|
||||||
$activity = Activity::factory()->inNami(89)->create();
|
$subactivity = Subactivity::factory()->inNami(90)->create();
|
||||||
$subactivity = Subactivity::factory()->inNami(90)->create();
|
$subscription = Subscription::factory()->forFee()->create();
|
||||||
$subscription = Subscription::factory()->forFee()->create();
|
Confession::factory()->create(['is_null' => true]);
|
||||||
$confesstion = Confession::factory()->create(['is_null' => true]);
|
PullMemberAction::shouldRun();
|
||||||
PullMemberAction::shouldRun();
|
PullMembershipsAction::shouldRun();
|
||||||
PullMembershipsAction::shouldRun();
|
|
||||||
|
|
||||||
$response = $this
|
$response = $this
|
||||||
->from('/member/create')
|
->from('/member/create')
|
||||||
->post('/member', $this->attributes([
|
->post('/member', MemberStoreRequestFactory::new()->create([
|
||||||
'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' => 'Post',
|
|
||||||
'salutation' => 'Doktor',
|
|
||||||
'comment' => 'Lorem bla',
|
|
||||||
]))->assertSessionHasNoErrors();
|
|
||||||
|
|
||||||
$response->assertRedirect('/member')->assertSessionHasNoErrors();
|
|
||||||
$member = Member::firstWhere('firstname', 'Joe');
|
|
||||||
$this->assertDatabaseHas('members', [
|
|
||||||
'address' => 'Bavert 50',
|
|
||||||
'bill_kind' => 'Post',
|
|
||||||
'birthday' => '2013-02-19',
|
|
||||||
'children_phone' => '+49 176 70512778',
|
|
||||||
'country_id' => $country->id,
|
'country_id' => $country->id,
|
||||||
'email_parents' => 'osloot@aol.com',
|
|
||||||
'firstname' => 'Joe',
|
|
||||||
'gender_id' => $gender->id,
|
'gender_id' => $gender->id,
|
||||||
'joined_at' => '2022-08-12',
|
|
||||||
'lastname' => 'Muster',
|
|
||||||
'letter_address' => null,
|
|
||||||
'location' => 'Solingen',
|
|
||||||
'main_phone' => '+49 212 337056',
|
|
||||||
'mobile_phone' => '+49 176 70512774',
|
|
||||||
'nationality_id' => $nationality->id,
|
|
||||||
'region_id' => $region->id,
|
'region_id' => $region->id,
|
||||||
'send_newspaper' => '1',
|
'nationality_id' => $nationality->id,
|
||||||
|
'first_activity_id' => $activity->id,
|
||||||
|
'first_subactivity_id' => $subactivity->id,
|
||||||
'subscription_id' => $subscription->id,
|
'subscription_id' => $subscription->id,
|
||||||
'zip' => '42719',
|
'bill_kind' => 'Post',
|
||||||
'fax' => '+49 212 4732223',
|
|
||||||
'salutation' => 'Doktor',
|
'salutation' => 'Doktor',
|
||||||
'comment' => 'Lorem bla',
|
'comment' => 'Lorem bla',
|
||||||
]);
|
]))->assertSessionHasNoErrors();
|
||||||
|
|
||||||
app(MemberFake::class)->assertStored(55, [
|
$response->assertRedirect('/member')->assertSessionHasNoErrors();
|
||||||
'ersteTaetigkeitId' => 89,
|
$this->assertDatabaseHas('members', [
|
||||||
'ersteUntergliederungId' => 90,
|
'address' => 'Bavert 50',
|
||||||
]);
|
'bill_kind' => 'Post',
|
||||||
}
|
'birthday' => '2013-02-19',
|
||||||
|
'children_phone' => '+49 176 70512778',
|
||||||
|
'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 337056',
|
||||||
|
'mobile_phone' => '+49 176 70512774',
|
||||||
|
'nationality_id' => $nationality->id,
|
||||||
|
'region_id' => $region->id,
|
||||||
|
'send_newspaper' => '1',
|
||||||
|
'subscription_id' => $subscription->id,
|
||||||
|
'zip' => '42719',
|
||||||
|
'fax' => '+49 212 4732223',
|
||||||
|
'salutation' => 'Doktor',
|
||||||
|
'comment' => 'Lorem bla',
|
||||||
|
]);
|
||||||
|
|
||||||
public function testItStoresWiederverwendenFlag(): void
|
app(MemberFake::class)->assertStored(55, [
|
||||||
{
|
'ersteTaetigkeitId' => 89,
|
||||||
app(MemberFake::class)->stores(55, 103);
|
'ersteUntergliederungId' => 90,
|
||||||
Fee::factory()->create();
|
]);
|
||||||
$this->withoutExceptionHandling()->login()->loginNami();
|
});
|
||||||
$activity = Activity::factory()->inNami(89)->create();
|
|
||||||
$subactivity = Subactivity::factory()->inNami(90)->create();
|
|
||||||
$subscription = Subscription::factory()->forFee()->create();
|
|
||||||
$confesstion = Confession::factory()->create(['is_null' => true]);
|
|
||||||
PullMemberAction::shouldRun();
|
|
||||||
PullMembershipsAction::shouldRun();
|
|
||||||
|
|
||||||
$this
|
it('testItStoresWiederverwendenFlag', function () {
|
||||||
->from('/member/create')
|
app(MemberFake::class)->stores(55, 103);
|
||||||
->post('/member', $this->attributes([
|
Fee::factory()->create();
|
||||||
'first_activity_id' => $activity->id,
|
$this->withoutExceptionHandling()->login()->loginNami();
|
||||||
'first_subactivity_id' => $subactivity->id,
|
$activity = Activity::factory()->inNami(89)->create();
|
||||||
'subscription_id' => $subscription->id,
|
$subactivity = Subactivity::factory()->inNami(90)->create();
|
||||||
'keepdata' => true,
|
$subscription = Subscription::factory()->forFee()->create();
|
||||||
]))->assertSessionHasNoErrors();
|
$confesstion = Confession::factory()->create(['is_null' => true]);
|
||||||
|
PullMemberAction::shouldRun();
|
||||||
|
PullMembershipsAction::shouldRun();
|
||||||
|
|
||||||
$this->assertDatabaseHas('members', [
|
$this
|
||||||
|
->from('/member/create')
|
||||||
|
->post('/member', MemberStoreRequestFactory::new()->create([
|
||||||
|
'first_activity_id' => $activity->id,
|
||||||
|
'first_subactivity_id' => $subactivity->id,
|
||||||
|
'subscription_id' => $subscription->id,
|
||||||
'keepdata' => true,
|
'keepdata' => true,
|
||||||
]);
|
]))->assertSessionHasNoErrors();
|
||||||
app(MemberFake::class)->assertStored(55, [
|
|
||||||
'wiederverwendenFlag' => true,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testItCanStoreAMemberWithoutNami(): void
|
$this->assertDatabaseHas('members', [
|
||||||
{
|
'keepdata' => true,
|
||||||
$this->withoutExceptionHandling()->login()->loginNami();
|
]);
|
||||||
$activity = Activity::factory()->create();
|
app(MemberFake::class)->assertStored(55, [
|
||||||
$subactivity = Subactivity::factory()->create();
|
'wiederverwendenFlag' => true,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
$response = $this
|
it('testItCanStoreAMemberWithoutNami', function () {
|
||||||
->from('/member/create')
|
$this->withoutExceptionHandling()->login()->loginNami();
|
||||||
->post('/member', $this->attributes([
|
$activity = Activity::factory()->create();
|
||||||
'first_activity_id' => $activity->id,
|
$subactivity = Subactivity::factory()->create();
|
||||||
'first_subactivity_id' => $subactivity->id,
|
|
||||||
'has_nami' => false,
|
|
||||||
]));
|
|
||||||
|
|
||||||
$response->assertSessionHasNoErrors();
|
$response = $this
|
||||||
$this->assertDatabaseHas('members', [
|
->from('/member/create')
|
||||||
'nami_id' => null,
|
->post('/member', MemberStoreRequestFactory::new()->create([
|
||||||
]);
|
'first_activity_id' => $activity->id,
|
||||||
NamiPutMemberAction::spy()->shouldNotHaveReceived('handle');
|
'first_subactivity_id' => $subactivity->id,
|
||||||
}
|
|
||||||
|
|
||||||
public function testItUpdatesPhoneNumber(): void
|
|
||||||
{
|
|
||||||
$this->withoutExceptionHandling()->login()->loginNami();
|
|
||||||
|
|
||||||
$this->post('/member', $this->attributes([
|
|
||||||
'has_nami' => false,
|
'has_nami' => false,
|
||||||
'main_phone' => '02103 4455129',
|
|
||||||
'fax' => '02103 4455130',
|
|
||||||
'children_phone' => '02103 4455130',
|
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$this->assertDatabaseHas('members', [
|
$response->assertSessionHasNoErrors();
|
||||||
'main_phone' => '+49 2103 4455129',
|
$this->assertDatabaseHas('members', [
|
||||||
'fax' => '+49 2103 4455130',
|
'nami_id' => null,
|
||||||
'children_phone' => '+49 2103 4455130',
|
]);
|
||||||
]);
|
NamiPutMemberAction::spy()->shouldNotHaveReceived('handle');
|
||||||
}
|
});
|
||||||
|
|
||||||
public function testItHasErrorWhenPhoneNumberIsInvalid(): void
|
it('testItUpdatesPhoneNumber', function () {
|
||||||
{
|
$this->withoutExceptionHandling()->login()->loginNami();
|
||||||
$this->login()->loginNami();
|
|
||||||
|
|
||||||
$response = $this->post('/member', $this->attributes([
|
$this->post('/member', MemberStoreRequestFactory::new()->create([
|
||||||
'has_nami' => false,
|
'has_nami' => false,
|
||||||
'main_phone' => '1111111111111111',
|
'main_phone' => '02103 4455129',
|
||||||
'mobile_phone' => '1111111111111111',
|
'fax' => '02103 4455130',
|
||||||
'fax' => '1111111111111111',
|
'children_phone' => '02103 4455130',
|
||||||
'children_phone' => '1111111111111111',
|
]));
|
||||||
]));
|
|
||||||
|
|
||||||
$response->assertSessionHasErrors([
|
$this->assertDatabaseHas('members', [
|
||||||
'main_phone' => 'Telefon (Eltern) ist keine valide Nummer.',
|
'main_phone' => '+49 2103 4455129',
|
||||||
'mobile_phone' => 'Handy (Eltern) ist keine valide Nummer.',
|
'fax' => '+49 2103 4455130',
|
||||||
'children_phone' => 'Telefon (Kind) ist keine valide Nummer.',
|
'children_phone' => '+49 2103 4455130',
|
||||||
'fax' => 'Fax ist keine valide Nummer.',
|
]);
|
||||||
]);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
public function testItDoesntRequireBirthdayWhenNotInNami(): void
|
it('testItHasErrorWhenPhoneNumberIsInvalid', function () {
|
||||||
{
|
$this->login()->loginNami();
|
||||||
$this->login()->loginNami();
|
|
||||||
|
|
||||||
$this
|
$response = $this->post('/member', MemberStoreRequestFactory::new()->create([
|
||||||
->post('/member', $this->attributes([
|
'has_nami' => false,
|
||||||
'nationality_id' => null,
|
'main_phone' => '1111111111111111',
|
||||||
'birthday' => null,
|
'mobile_phone' => '1111111111111111',
|
||||||
'has_nami' => false,
|
'fax' => '1111111111111111',
|
||||||
'address' => null,
|
'children_phone' => '1111111111111111',
|
||||||
'zip' => null,
|
]));
|
||||||
'location' => null,
|
|
||||||
'joined_at' => null,
|
$response->assertSessionHasErrors([
|
||||||
]))->assertSessionDoesntHaveErrors();
|
'main_phone' => 'Telefon (Eltern) ist keine valide Nummer.',
|
||||||
$this->assertDatabaseHas('members', [
|
'mobile_phone' => 'Handy (Eltern) ist keine valide Nummer.',
|
||||||
|
'children_phone' => 'Telefon (Kind) ist keine valide Nummer.',
|
||||||
|
'fax' => 'Fax ist keine valide Nummer.',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('testItDoesntRequireBirthdayWhenNotInNami', function () {
|
||||||
|
$this->login()->loginNami();
|
||||||
|
|
||||||
|
$this
|
||||||
|
->post('/member', MemberStoreRequestFactory::new()->create([
|
||||||
'nationality_id' => null,
|
'nationality_id' => null,
|
||||||
'birthday' => null,
|
'birthday' => null,
|
||||||
|
'has_nami' => false,
|
||||||
'address' => null,
|
'address' => null,
|
||||||
'zip' => null,
|
'zip' => null,
|
||||||
'location' => null,
|
'location' => null,
|
||||||
'joined_at' => null,
|
'joined_at' => null,
|
||||||
]);
|
]))->assertSessionDoesntHaveErrors();
|
||||||
}
|
$this->assertDatabaseHas('members', [
|
||||||
|
'nationality_id' => null,
|
||||||
|
'birthday' => null,
|
||||||
|
'address' => null,
|
||||||
|
'zip' => null,
|
||||||
|
'location' => null,
|
||||||
|
'joined_at' => null,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
public function testItDoesntNeedSubscription(): void
|
it('testItDoesntNeedSubscription', function () {
|
||||||
{
|
$this->login()->loginNami();
|
||||||
$this->login()->loginNami();
|
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->post('/member', $this->attributes([
|
->post('/member', MemberStoreRequestFactory::new()->create([
|
||||||
'has_nami' => false,
|
'has_nami' => false,
|
||||||
'subscription_id' => null,
|
|
||||||
]))->assertSessionDoesntHaveErrors();
|
|
||||||
$this->assertDatabaseHas('members', [
|
|
||||||
'subscription_id' => null,
|
'subscription_id' => null,
|
||||||
]);
|
]))->assertSessionDoesntHaveErrors();
|
||||||
}
|
$this->assertDatabaseHas('members', [
|
||||||
|
'subscription_id' => null,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
public function testItRequiresFields(): void
|
it('testItRequiresFields', function () {
|
||||||
{
|
$this->login()->loginNami();
|
||||||
$this->login()->loginNami();
|
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->post('/member', $this->attributes([
|
->post('/member', MemberStoreRequestFactory::new()->create([
|
||||||
'nationality_id' => null,
|
'nationality_id' => null,
|
||||||
'birthday' => '',
|
'birthday' => '',
|
||||||
'address' => '',
|
'address' => '',
|
||||||
'zip' => '',
|
'zip' => '',
|
||||||
'location' => '',
|
'location' => '',
|
||||||
'joined_at' => '',
|
'joined_at' => '',
|
||||||
]))
|
]))
|
||||||
->assertSessionHasErrors(['nationality_id', 'birthday', 'address', 'zip', 'location', 'joined_at']);
|
->assertSessionHasErrors(['nationality_id', 'birthday', 'address', 'zip', 'location', 'joined_at']);
|
||||||
}
|
});
|
||||||
|
|
||||||
public function testSubscriptionIsRequiredIfFirstActivityIsPaid(): void
|
it('testSubscriptionIsRequiredIfFirstActivityIsPaid', function () {
|
||||||
{
|
$this->login()->loginNami();
|
||||||
$this->login()->loginNami();
|
$activity = Activity::factory()->name('€ Mitglied')->create();
|
||||||
$activity = Activity::factory()->name('€ Mitglied')->create();
|
$subactivity = Subactivity::factory()->create();
|
||||||
$subactivity = Subactivity::factory()->create();
|
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->from('/member/create')
|
->from('/member/create')
|
||||||
->post('/member', $this->attributes([
|
->post('/member', MemberStoreRequestFactory::new()->create([
|
||||||
'first_activity_id' => $activity->id,
|
'first_activity_id' => $activity->id,
|
||||||
'first_subactivity_id' => $subactivity->id,
|
'first_subactivity_id' => $subactivity->id,
|
||||||
'subscription_id' => null,
|
'subscription_id' => null,
|
||||||
]))
|
]))
|
||||||
->assertSessionHasErrors(['subscription_id' => 'Beitragsart ist erforderlich.']);
|
->assertSessionHasErrors(['subscription_id' => 'Beitragsart ist erforderlich.']);
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function defaults(): array
|
|
||||||
{
|
|
||||||
$country = Country::factory()->create();
|
|
||||||
$nationality = Nationality::factory()->create();
|
|
||||||
$subscription = Subscription::factory()->forFee()->create();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'address' => 'Bavert 50',
|
|
||||||
'birthday' => '2013-02-19',
|
|
||||||
'children_phone' => '+49 176 70512778',
|
|
||||||
'efz' => '',
|
|
||||||
'email' => '',
|
|
||||||
'email_parents' => 'osloot@aol.com',
|
|
||||||
'fax' => '+49 212 4732223',
|
|
||||||
'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 337056',
|
|
||||||
'mobile_phone' => '+49 176 70512774',
|
|
||||||
'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',
|
|
||||||
'country_id' => $country->id,
|
|
||||||
'nationality_id' => $nationality->id,
|
|
||||||
'subscription_id' => $subscription->id,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\RequestFactories;
|
||||||
|
|
||||||
|
use App\Country;
|
||||||
|
use App\Nationality;
|
||||||
|
use App\Payment\Subscription;
|
||||||
|
use Worksome\RequestFactories\RequestFactory;
|
||||||
|
|
||||||
|
class MemberStoreRequestFactory extends RequestFactory
|
||||||
|
{
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
$country = Country::factory()->create();
|
||||||
|
$nationality = Nationality::factory()->create();
|
||||||
|
$subscription = Subscription::factory()->forFee()->create();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'address' => 'Bavert 50',
|
||||||
|
'birthday' => '2013-02-19',
|
||||||
|
'children_phone' => '+49 176 70512778',
|
||||||
|
'efz' => '',
|
||||||
|
'email' => '',
|
||||||
|
'email_parents' => 'osloot@aol.com',
|
||||||
|
'fax' => '+49 212 4732223',
|
||||||
|
'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 337056',
|
||||||
|
'mobile_phone' => '+49 176 70512774',
|
||||||
|
'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',
|
||||||
|
'country_id' => $country->id,
|
||||||
|
'nationality_id' => $nationality->id,
|
||||||
|
'subscription_id' => $subscription->id,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue