Add: Store Member with empty kontoverbindung
This commit is contained in:
parent
51c3a489ee
commit
1fe8ba8cf9
|
@ -4,14 +4,15 @@ namespace Zoomyboy\LaravelNami\Data;
|
||||||
|
|
||||||
use Spatie\LaravelData\Data;
|
use Spatie\LaravelData\Data;
|
||||||
use Spatie\LaravelData\Attributes\MapInputName;
|
use Spatie\LaravelData\Attributes\MapInputName;
|
||||||
|
use Zoomyboy\LaravelNami\Tests\Factories\BankAccountRequestFactory;
|
||||||
|
|
||||||
class BankAccount extends Data
|
class BankAccount extends Data
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public int $id,
|
public ?int $id,
|
||||||
|
|
||||||
#[MapInputName('mitgliedsNummer')]
|
#[MapInputName('mitgliedsNummer')]
|
||||||
public int $memberId,
|
public ?int $memberId,
|
||||||
|
|
||||||
#[MapInputName('bankleitzahl')]
|
#[MapInputName('bankleitzahl')]
|
||||||
public ?string $blz = null,
|
public ?string $blz = null,
|
||||||
|
@ -27,4 +28,27 @@ class BankAccount extends Data
|
||||||
public ?int $conditionId = null,
|
public ?int $conditionId = null,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function toFactory(): BankAccountRequestFactory
|
||||||
|
{
|
||||||
|
return BankAccountRequestFactory::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toNami(): string
|
||||||
|
{
|
||||||
|
return json_encode([
|
||||||
|
'id' => $this->id ?: '',
|
||||||
|
'zahlungsKonditionId' => $this->conditionId,
|
||||||
|
'mitgliedsNummer' => $this->memberId,
|
||||||
|
'institut' => $this->bankName ?: '',
|
||||||
|
'kontoinhaber' => $this->person ?: '',
|
||||||
|
'kontonummer' => $this->accountNumber ?: '',
|
||||||
|
'bankleitzahl' => $this->blz ?: '',
|
||||||
|
'iban' => $this->iban ?: '',
|
||||||
|
'bic' => $this->bic ?: '',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,7 @@ class Member extends Data
|
||||||
'nameZusatz' => $this->furtherAddress,
|
'nameZusatz' => $this->furtherAddress,
|
||||||
'version' => $this->version,
|
'version' => $this->version,
|
||||||
'eintrittsdatum' => $this->joinedAt->format('Y-m-d 00:00:00'),
|
'eintrittsdatum' => $this->joinedAt->format('Y-m-d 00:00:00'),
|
||||||
|
'kontoverbindung' => $this->bankAccount->toNami(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Tests\Factories;
|
||||||
|
|
||||||
|
use Worksome\RequestFactories\RequestFactory;
|
||||||
|
|
||||||
|
class BankAccountRequestFactory extends RequestFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->faker->numberBetween(500, 1000),
|
||||||
|
'memberId' => $this->faker->numberBetween(500, 1000),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function empty(): self
|
||||||
|
{
|
||||||
|
return $this->state([
|
||||||
|
'id' => null,
|
||||||
|
'memberId' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,6 +35,11 @@ class MemberRequestFactory extends RequestFactory
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withBankAccount(BankAccountRequestFactory $bankAccount): self
|
||||||
|
{
|
||||||
|
return $this->state(['kontoverbindung' => $bankAccount->create()]);
|
||||||
|
}
|
||||||
|
|
||||||
public function inNami(int $groupId, int $namiId): self
|
public function inNami(int $groupId, int $namiId): self
|
||||||
{
|
{
|
||||||
return $this->state([
|
return $this->state([
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami\Tests\Unit\Api;
|
namespace Zoomyboy\LaravelNami\Tests\Unit\Api;
|
||||||
|
|
||||||
|
use Zoomyboy\LaravelNami\Data\BankAccount;
|
||||||
use Zoomyboy\LaravelNami\Data\Member;
|
use Zoomyboy\LaravelNami\Data\Member;
|
||||||
use Zoomyboy\LaravelNami\Fakes\MemberFake;
|
use Zoomyboy\LaravelNami\Fakes\MemberFake;
|
||||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||||
|
@ -74,6 +75,31 @@ class PutMemberTest extends TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItPutsEmptyKontoverbindung(): void
|
||||||
|
{
|
||||||
|
app(MemberFake::class)->stores(103, 16);
|
||||||
|
$member = Member::toFactory()
|
||||||
|
->withBankAccount(BankAccount::toFactory()->empty())
|
||||||
|
->toMember(['groupId' => 103]);
|
||||||
|
$response = $this->login()->putMember($member, 78, 79);
|
||||||
|
|
||||||
|
$this->assertEquals(16, $response);
|
||||||
|
|
||||||
|
app(MemberFake::class)->assertStored(103, [
|
||||||
|
'kontoverbindung' => json_encode([
|
||||||
|
'id' => '',
|
||||||
|
'zahlungsKonditionId' => null,
|
||||||
|
'mitgliedsNummer' => null,
|
||||||
|
'institut' => '',
|
||||||
|
'kontoinhaber' => '',
|
||||||
|
'kontonummer' => '',
|
||||||
|
'bankleitzahl' => '',
|
||||||
|
'iban' => '',
|
||||||
|
'bic' => '',
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function testUpdateAMemberWithForeignAttributes(): void
|
public function testUpdateAMemberWithForeignAttributes(): void
|
||||||
{
|
{
|
||||||
app(MemberFake::class)
|
app(MemberFake::class)
|
||||||
|
@ -137,24 +163,6 @@ class PutMemberTest extends TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItMergesKontoverbindung(): void
|
|
||||||
{
|
|
||||||
app(MemberFake::class)
|
|
||||||
->updatesSuccessfully(103, 16)
|
|
||||||
->shows(103, 16, [
|
|
||||||
'foreign' => 'fff',
|
|
||||||
'kontoverbindung' => ['a' => 'b'],
|
|
||||||
]);
|
|
||||||
$response = $this->login()->putMember(Member::toFactory()->inNami(103, 16)->toMember());
|
|
||||||
|
|
||||||
$this->assertEquals(16, $response);
|
|
||||||
|
|
||||||
app(MemberFake::class)->assertUpdated(103, 16, [
|
|
||||||
'kontoverbindung' => '{"a":"b"}',
|
|
||||||
'foreign' => 'fff',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUpdateToDefaultGenderIdAndRegionIdIfTheyAreNull(): void
|
public function testUpdateToDefaultGenderIdAndRegionIdIfTheyAreNull(): void
|
||||||
{
|
{
|
||||||
app(MemberFake::class)
|
app(MemberFake::class)
|
||||||
|
|
Loading…
Reference in New Issue