Compare commits
	
		
			3 Commits
		
	
	
		
			51c3a489ee
			...
			ff34c23032
		
	
	| Author | SHA1 | Date | 
|---|---|---|
|  | ff34c23032 | |
|  | fa12646ead | |
|  | 1fe8ba8cf9 | 
|  | @ -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'); | ||||
|  |  | |||
|  | @ -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 ?: '', | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -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), | ||||
|         ]; | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 | ||||
|     { | ||||
|         return $this->state([ | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue