Compare commits

...

3 Commits

Author SHA1 Message Date
philipp lang ff34c23032 Add: Update kontoverbindung 2025-03-29 03:03:12 +01:00
philipp lang fa12646ead Add test for filled kontoverbindung 2025-03-29 02:47:03 +01:00
philipp lang 1fe8ba8cf9 Add: Store Member with empty kontoverbindung 2025-03-29 02:34:54 +01:00
6 changed files with 154 additions and 21 deletions

View File

@ -153,7 +153,6 @@ class Api
if ($member->id) {
$existing = $this->rawMember($member->groupId, $member->id);
$payload = array_merge($existing, $member->toNami());
$payload['kontoverbindung'] = json_encode(data_get($payload, 'kontoverbindung', []));
$url = $this->url . '/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/' . $member->groupId . '/' . $member->id;
$response = $this->http()->put($url, $payload);
$this->assertOk($response, $url, 'Update failed');

View File

@ -4,14 +4,15 @@ namespace Zoomyboy\LaravelNami\Data;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Attributes\MapInputName;
use Zoomyboy\LaravelNami\Tests\Factories\BankAccountRequestFactory;
class BankAccount extends Data
{
public function __construct(
public int $id,
public ?int $id,
#[MapInputName('mitgliedsNummer')]
public int $memberId,
public ?int $memberId,
#[MapInputName('bankleitzahl')]
public ?string $blz = null,
@ -27,4 +28,27 @@ class BankAccount extends Data
public ?int $conditionId = null,
) {
}
public static function toFactory(): BankAccountRequestFactory
{
return BankAccountRequestFactory::new();
}
/**
* @return array<string, mixed>
*/
public function toNami(?int $memberId = null): string
{
return json_encode([
'id' => $this->id ?: '',
'zahlungsKonditionId' => $this->conditionId,
'mitgliedsNummer' => $memberId !== null ? $memberId : $this->memberId,
'institut' => $this->bankName ?: '',
'kontoinhaber' => $this->person ?: '',
'kontonummer' => $this->accountNumber ?: '',
'bankleitzahl' => $this->blz ?: '',
'iban' => $this->iban ?: '',
'bic' => $this->bic ?: '',
]);
}
}

View File

@ -159,6 +159,7 @@ class Member extends Data
'nameZusatz' => $this->furtherAddress,
'version' => $this->version,
'eintrittsdatum' => $this->joinedAt->format('Y-m-d 00:00:00'),
'kontoverbindung' => $this->bankAccount->toNami($this->memberId),
];
}

View File

@ -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,
]);
}
}

View File

@ -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
{
return $this->state([

View File

@ -2,6 +2,7 @@
namespace Zoomyboy\LaravelNami\Tests\Unit\Api;
use Zoomyboy\LaravelNami\Data\BankAccount;
use Zoomyboy\LaravelNami\Data\Member;
use Zoomyboy\LaravelNami\Fakes\MemberFake;
use Zoomyboy\LaravelNami\Tests\TestCase;
@ -74,6 +75,100 @@ 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 testItPutsFilledKontoverbindung(): void
{
app(MemberFake::class)->stores(103, 16);
$member = Member::toFactory()
->withBankAccount(BankAccount::toFactory()->empty()->state([
'zahlungsKonditionId' => 1,
'institut' => 'institut',
'kontoinhaber' => 'kontoinhaber',
'kontonummer' => 'kontonummer',
'bankleitzahl' => 'bankleitzahl',
'iban' => 'iban',
'bic' => 'bic',
]))
->toMember(['groupId' => 103]);
$response = $this->login()->putMember($member, 78, 79);
$this->assertEquals(16, $response);
app(MemberFake::class)->assertStored(103, [
'kontoverbindung' => json_encode([
'id' => '',
'zahlungsKonditionId' => 1,
'mitgliedsNummer' => null,
'institut' => 'institut',
'kontoinhaber' => 'kontoinhaber',
'kontonummer' => 'kontonummer',
'bankleitzahl' => 'bankleitzahl',
'iban' => 'iban',
'bic' => 'bic',
]),
]);
}
public function testItUpdatesKontoverbindung(): void
{
app(MemberFake::class)
->updatesSuccessfully(103, 16)
->shows(103, 16);
$member = Member::toFactory()
->withBankAccount(BankAccount::toFactory()->state([
'id' => 555,
'zahlungsKonditionId' => 1,
'institut' => 'institut',
'kontoinhaber' => 'kontoinhaber',
'kontonummer' => 'kontonummer',
'bankleitzahl' => 'bankleitzahl',
'iban' => 'iban',
'bic' => 'bic',
]))
->toMember(['groupId' => 103, 'id' => 16, 'mitgliedsNummer' => 18]);
$response = $this->login()->putMember($member);
$this->assertEquals(16, $response);
app(MemberFake::class)->assertUpdated(103, 16, [
'kontoverbindung' => json_encode([
'id' => 555,
'zahlungsKonditionId' => 1,
'mitgliedsNummer' => 18,
'institut' => 'institut',
'kontoinhaber' => 'kontoinhaber',
'kontonummer' => 'kontonummer',
'bankleitzahl' => 'bankleitzahl',
'iban' => 'iban',
'bic' => 'bic',
]),
]);
}
public function testUpdateAMemberWithForeignAttributes(): void
{
app(MemberFake::class)
@ -137,24 +232,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
{
app(MemberFake::class)