This commit is contained in:
parent
fe8ea63fa5
commit
17a6a34957
|
@ -24,10 +24,11 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Scout\Attributes\SearchUsingFullText;
|
||||
use Laravel\Scout\Searchable;
|
||||
use Sabre\VObject\Component\VCard;
|
||||
use Sabre\VObject\Reader;
|
||||
use Spatie\LaravelData\Lazy;
|
||||
use Laravel\Scout\Searchable;
|
||||
use Zoomyboy\Phone\HasPhoneNumbers;
|
||||
|
||||
/**
|
||||
* @property string $subscription_name
|
||||
|
@ -40,6 +41,7 @@ class Member extends Model
|
|||
use HasFactory;
|
||||
use Sluggable;
|
||||
use Searchable;
|
||||
use HasPhoneNumbers;
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
|
@ -77,6 +79,14 @@ class Member extends Model
|
|||
'mitgliedsnr' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function phoneNumbers(): array
|
||||
{
|
||||
return ['main_phone', 'mobile_phone', 'work_phone', 'children_phone', 'fax'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{source: array<int, string>}>
|
||||
*/
|
||||
|
@ -283,6 +293,7 @@ class Member extends Model
|
|||
// ---------------------------------- Scopes -----------------------------------
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
*
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeOrdered(Builder $query): Builder
|
||||
|
@ -292,6 +303,7 @@ class Member extends Model
|
|||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
*
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeWithPendingPayment(Builder $query): Builder
|
||||
|
@ -307,6 +319,7 @@ class Member extends Model
|
|||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
*
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeWhereHasPendingPayment(Builder $query): Builder
|
||||
|
@ -318,6 +331,7 @@ class Member extends Model
|
|||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
*
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeWhereAusstand(Builder $query): Builder
|
||||
|
@ -329,6 +343,7 @@ class Member extends Model
|
|||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
*
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopePayable(Builder $query): Builder
|
||||
|
@ -338,6 +353,7 @@ class Member extends Model
|
|||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
*
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeWhereNoPayment(Builder $query, int $year): Builder
|
||||
|
@ -349,6 +365,7 @@ class Member extends Model
|
|||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
*
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeForDashboard(Builder $query): Builder
|
||||
|
@ -358,8 +375,10 @@ class Member extends Model
|
|||
|
||||
/**
|
||||
* @todo refactor this to an actual filter model
|
||||
* @param Builder<self> $query
|
||||
*
|
||||
* @param Builder<self> $query
|
||||
* @param array<string, mixed> $filter
|
||||
*
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeFilter(Builder $query, array $filter): Builder
|
||||
|
@ -387,6 +406,7 @@ class Member extends Model
|
|||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
*
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeWhereCurrentGroup(Builder $query): Builder
|
||||
|
|
|
@ -11,6 +11,7 @@ use App\Subactivity;
|
|||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Zoomyboy\Phone\ValidPhoneRule;
|
||||
|
||||
class MemberRequest extends FormRequest
|
||||
{
|
||||
|
@ -69,14 +70,14 @@ class MemberRequest extends FormRequest
|
|||
'multiply_pv' => 'boolean',
|
||||
'multiply_more_pv' => 'boolean',
|
||||
'send_newspaper' => 'boolean',
|
||||
'main_phone' => '',
|
||||
'mobile_phone' => '',
|
||||
'main_phone' => ['nullable', new ValidPhoneRule('Telefon (Eltern)')],
|
||||
'mobile_phone' => ['nullable', new ValidPhoneRule('Handy (Eltern)')],
|
||||
'letter_address' => '',
|
||||
'gender_id' => 'nullable|exists:genders,id',
|
||||
'region_id' => 'nullable|exists:regions,id',
|
||||
'nationality_id' => 'required|exists:nationalities,id',
|
||||
'children_phone' => '',
|
||||
'fax' => '',
|
||||
'children_phone' => ['nullable', new ValidPhoneRule('Telefon (Kind)')],
|
||||
'fax' => ['nullable', new ValidPhoneRule('Fax')],
|
||||
'other_country' => '',
|
||||
'salutation' => '',
|
||||
'comment' => '',
|
||||
|
@ -85,10 +86,12 @@ class MemberRequest extends FormRequest
|
|||
|
||||
public function persistCreate(NamiSettings $settings): void
|
||||
{
|
||||
$member = Member::create([
|
||||
$member = new Member([
|
||||
...$this->validated(),
|
||||
'group_id' => Group::where('nami_id', $settings->default_group_id)->firstOrFail()->id,
|
||||
]);
|
||||
$member->updatePhoneNumbers()->save();
|
||||
|
||||
if ($this->input('has_nami')) {
|
||||
NamiPutMemberAction::run(
|
||||
$member,
|
||||
|
@ -100,7 +103,7 @@ class MemberRequest extends FormRequest
|
|||
|
||||
public function persistUpdate(Member $member): void
|
||||
{
|
||||
$member->fill($this->validated());
|
||||
$member->fill($this->validated())->updatePhoneNumbers();
|
||||
|
||||
$namiSync = $member->isDirty(Member::$namiFields);
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
"spatie/laravel-settings": "^2.2",
|
||||
"worksome/request-factories": "^2.5",
|
||||
"zoomyboy/laravel-nami": "dev-master",
|
||||
"zoomyboy/phone": "^1.0",
|
||||
"zoomyboy/tex": "dev-main as 1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -116,6 +116,7 @@ return [
|
|||
'uploaded' => ':attribute konnte nicht hochgeladen werden.',
|
||||
'url' => ':attribute muss eine URL sein.',
|
||||
'uuid' => ':attribute muss ein UUID sein.',
|
||||
'phone_number' => ':attribute ist keine valide Nummer.',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -55,7 +55,7 @@ class StoreTest extends TestCase
|
|||
'address' => 'Bavert 50',
|
||||
'bill_kind' => 'Post',
|
||||
'birthday' => '2013-02-19',
|
||||
'children_phone' => '+49 123 44444',
|
||||
'children_phone' => '+49 176 8574112',
|
||||
'country_id' => $country->id,
|
||||
'email_parents' => 'osloot@aol.com',
|
||||
'firstname' => 'Joe',
|
||||
|
@ -65,13 +65,13 @@ class StoreTest extends TestCase
|
|||
'letter_address' => null,
|
||||
'location' => 'Solingen',
|
||||
'main_phone' => '+49 212 2334322',
|
||||
'mobile_phone' => '+49 157 53180451',
|
||||
'mobile_phone' => '+49 176 3033053',
|
||||
'nationality_id' => $nationality->id,
|
||||
'region_id' => $region->id,
|
||||
'send_newspaper' => '1',
|
||||
'subscription_id' => $subscription->id,
|
||||
'zip' => '42719',
|
||||
'fax' => '+49 666',
|
||||
'fax' => '+49 212 4732223',
|
||||
'salutation' => 'Doktor',
|
||||
'comment' => 'Lorem bla',
|
||||
]);
|
||||
|
@ -102,6 +102,44 @@ class StoreTest extends TestCase
|
|||
NamiPutMemberAction::spy()->shouldNotHaveReceived('handle');
|
||||
}
|
||||
|
||||
public function testItUpdatesPhoneNumber(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
|
||||
$this->post('/member', $this->attributes([
|
||||
'has_nami' => false,
|
||||
'main_phone' => '02103 4455129',
|
||||
'fax' => '02103 4455130',
|
||||
'children_phone' => '02103 4455130',
|
||||
]));
|
||||
|
||||
$this->assertDatabaseHas('members', [
|
||||
'main_phone' => '+49 2103 4455129',
|
||||
'fax' => '+49 2103 4455130',
|
||||
'children_phone' => '+49 2103 4455130',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testItHasErrorWhenPhoneNumberIsInvalid(): void
|
||||
{
|
||||
$this->login()->loginNami();
|
||||
|
||||
$response = $this->post('/member', $this->attributes([
|
||||
'has_nami' => false,
|
||||
'main_phone' => '1111111111111111',
|
||||
'mobile_phone' => '1111111111111111',
|
||||
'fax' => '1111111111111111',
|
||||
'children_phone' => '1111111111111111',
|
||||
]));
|
||||
|
||||
$response->assertSessionHasErrors([
|
||||
'main_phone' => 'Telefon (Eltern) ist keine valide Nummer.',
|
||||
'mobile_phone' => 'Handy (Eltern) ist keine valide Nummer.',
|
||||
'children_phone' => 'Telefon (Kind) ist keine valide Nummer.',
|
||||
'fax' => 'Fax ist keine valide Nummer.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testItRequiresFields(): void
|
||||
{
|
||||
$this->login()->loginNami();
|
||||
|
@ -138,11 +176,11 @@ class StoreTest extends TestCase
|
|||
return [
|
||||
'address' => 'Bavert 50',
|
||||
'birthday' => '2013-02-19',
|
||||
'children_phone' => '+49 123 44444',
|
||||
'children_phone' => '+49 176 8574112',
|
||||
'efz' => '',
|
||||
'email' => '',
|
||||
'email_parents' => 'osloot@aol.com',
|
||||
'fax' => '+49 666',
|
||||
'fax' => '+49 212 4732223',
|
||||
'firstname' => 'Joe',
|
||||
'further_address' => '',
|
||||
'has_nami' => true,
|
||||
|
@ -153,7 +191,7 @@ class StoreTest extends TestCase
|
|||
'letter_address' => '',
|
||||
'location' => 'Solingen',
|
||||
'main_phone' => '+49 212 2334322',
|
||||
'mobile_phone' => '+49 157 53180451',
|
||||
'mobile_phone' => '+49 176 3033053',
|
||||
'more_ps_at' => '',
|
||||
'multiply_more_pv' => false,
|
||||
'multiply_pv' => false,
|
||||
|
|
|
@ -15,7 +15,6 @@ use App\Subactivity;
|
|||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
use Zoomyboy\LaravelNami\Backend\FakeBackend;
|
||||
|
||||
class UpdateTest extends TestCase
|
||||
{
|
||||
|
@ -53,6 +52,27 @@ class UpdateTest extends TestCase
|
|||
$response->assertRedirect("/member/{$member->id}/edit?conflict=1");
|
||||
}
|
||||
|
||||
public function testItUpdatesPhoneNumber(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$member = $this->member();
|
||||
$this->fakeRequest();
|
||||
NamiPutMemberAction::allowToRun();
|
||||
|
||||
$this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [
|
||||
'main_phone' => '02103 4455129',
|
||||
'fax' => '02103 4455130',
|
||||
'children_phone' => '02103 4455130',
|
||||
'has_nami' => true,
|
||||
]));
|
||||
|
||||
$this->assertDatabaseHas('members', [
|
||||
'main_phone' => '+49 2103 4455129',
|
||||
'fax' => '+49 2103 4455130',
|
||||
'children_phone' => '+49 2103 4455130',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testItUpdatesContact(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
|
|
Loading…
Reference in New Issue