From 5243b7341dc466fe1eccf9f0304caad14138418d Mon Sep 17 00:00:00 2001 From: philipp lang Date: Mon, 6 Feb 2023 00:23:34 +0100 Subject: [PATCH] Lint tests --- src/Data/Member.php | 6 +++++ tests/Factories/MemberRequestFactory.php | 34 ++++++++++++++++++++++-- tests/Unit/Api/PutMemberTest.php | 25 +++++++++++++---- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/Data/Member.php b/src/Data/Member.php index 62baacf..31fd072 100644 --- a/src/Data/Member.php +++ b/src/Data/Member.php @@ -8,6 +8,7 @@ use Spatie\LaravelData\Attributes\WithCast; use Spatie\LaravelData\Data; use Zoomyboy\LaravelNami\Casters\CarbonCast; use Zoomyboy\LaravelNami\Casters\StringCast; +use Zoomyboy\LaravelNami\Tests\Factories\MemberRequestFactory; class Member extends Data { @@ -134,4 +135,9 @@ class Member extends Data 'zeitschriftenversand' => $this->sendNewspaper, ]; } + + public static function factory(): MemberRequestFactory + { + return MemberRequestFactory::new(); + } } diff --git a/tests/Factories/MemberRequestFactory.php b/tests/Factories/MemberRequestFactory.php index fd1f73a..37351aa 100644 --- a/tests/Factories/MemberRequestFactory.php +++ b/tests/Factories/MemberRequestFactory.php @@ -5,18 +5,40 @@ namespace Zoomyboy\LaravelNami\Tests\Factories; use GuzzleHttp\Promise\FulfilledPromise; use Illuminate\Support\Facades\Http; use Worksome\RequestFactories\RequestFactory; +use Zoomyboy\LaravelNami\Data\Member; class MemberRequestFactory extends RequestFactory { public function definition(): array { return [ - 'vorname' => $this->faker->firstName, - 'nachname' => $this->faker->lastName, + 'firstname' => $this->faker->firstName, + 'lastname' => $this->faker->lastName, 'nickname' => $this->faker->firstName, + 'groupId' => $this->faker->numberBetween(100, 200), + 'genderId' => $this->faker->numberBetween(100, 200), + 'confessionId' => $this->faker->numberBetween(100, 200), + 'joinedAt' => $this->faker->dateTime()->format('Y-m-d').' 00:00:00', + 'birthday' => $this->faker->dateTime()->format('Y-m-d').' 00:00:00', + 'email' => $this->faker->safeEmail(), + 'countryId' => $this->faker->numberBetween(100, 200), + 'keepdata' => $this->faker->boolean(), + 'sendNewspaper' => $this->faker->boolean(), + 'regionId' => $this->faker->numberBetween(100, 200), + 'nationalityId' => $this->faker->numberBetween(100, 200), + 'beitragsartId' => $this->faker->numberBetween(100, 200), + 'id' => null, ]; } + public function inNami(int $groupId, int $namiId): self + { + return $this->state([ + 'id' => $namiId, + 'groupId' => $groupId, + ]); + } + public function withEmptyNames(): self { return $this->state([ @@ -36,4 +58,12 @@ class MemberRequestFactory extends RequestFactory 'responseType' => null, ]), 200); } + + /** + * @param array $attributes + */ + public function toMember(array $attributes = []): Member + { + return Member::from($this->create($attributes)); + } } diff --git a/tests/Unit/Api/PutMemberTest.php b/tests/Unit/Api/PutMemberTest.php index fa5ca05..d9c33e5 100644 --- a/tests/Unit/Api/PutMemberTest.php +++ b/tests/Unit/Api/PutMemberTest.php @@ -11,7 +11,7 @@ class PutMemberTest extends TestCase public function testPushASingleMember(): void { app(MemberFake::class)->createsSuccessfully(103, 16); - $member = Member::from([ + $member = Member::factory()->toMember([ 'firstname' => 'Max', 'lastname' => 'Nach1', 'nickname' => 'spitz1', @@ -55,10 +55,8 @@ class PutMemberTest extends TestCase { app(MemberFake::class) ->updatesSuccessfully(103, 16) - ->shows(103, 16, [ - 'foreign' => 'fff', - ]); - $member = Member::from([ + ->shows(103, 16); + $member = Member::factory()->toMember([ 'firstname' => 'Max', 'lastname' => 'Nach1', 'nickname' => 'spitz1', @@ -94,6 +92,23 @@ class PutMemberTest extends TestCase 'zeitschriftenversand' => false, 'regionId' => 11, 'staatsangehoerigkeitId' => 12, + ]); + } + + public function testItMergesKontoverbindung(): void + { + app(MemberFake::class) + ->updatesSuccessfully(103, 16) + ->shows(103, 16, [ + 'foreign' => 'fff', + 'kontoverbindung' => ['a' => 'b'], + ]); + $response = $this->login()->putMember(Member::factory()->inNami(103, 16)->toMember()); + + $this->assertEquals(16, $response); + + app(MemberFake::class)->assertUpdated(103, 16, [ + 'kontoverbindung' => '{"a":"b"}', 'foreign' => 'fff', ]); }