fixed: member data can be corrupted

This commit is contained in:
philipp lang 2023-02-07 23:15:44 +01:00
parent a8fc9b44cf
commit d51b0ec389
5 changed files with 59 additions and 1 deletions

View File

@ -14,6 +14,7 @@ use Zoomyboy\LaravelNami\Data\Member;
use Zoomyboy\LaravelNami\Data\MemberEntry;
use Zoomyboy\LaravelNami\Data\Membership;
use Zoomyboy\LaravelNami\Data\MembershipEntry;
use Zoomyboy\LaravelNami\Exceptions\MemberDataCorruptedException;
use Zoomyboy\LaravelNami\Exceptions\NotAuthenticatedException;
use Zoomyboy\LaravelNami\Support\Paginator;
@ -294,7 +295,11 @@ class Api
public function member(int $groupId, int $memberId): Member
{
return Member::from($this->rawMember($groupId, $memberId));
$rawMember = $this->rawMember($groupId, $memberId);
throw_unless(Member::isCorrupted($rawMember), MemberDataCorruptedException::class, $rawMember);
return Member::from($rawMember);
}
public function hasGroup(int $groupId): bool

View File

@ -155,4 +155,20 @@ class Member extends Data
{
return MemberRequestFactory::new();
}
/**
* @param array<string, mixed> $rawData
*/
public static function isCorrupted(array $rawData): bool
{
if (!data_get($rawData, 'eintrittsdatum')) {
return false;
}
if (!data_get($rawData, 'landId')) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Zoomyboy\LaravelNami\Exceptions;
use Exception;
class MemberDataCorruptedException extends Exception implements Skippable
{
/**
* @param array<string, mixed> $rawMember
*/
public function __construct(public array $rawMember)
{
parent::__construct('Member data corrupted');
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace Zoomyboy\LaravelNami\Exceptions;
interface Skippable
{
}

View File

@ -2,6 +2,7 @@
namespace Zoomyboy\LaravelNami\Tests\Unit\Member;
use Zoomyboy\LaravelNami\Exceptions\MemberDataCorruptedException;
use Zoomyboy\LaravelNami\Fakes\MemberFake;
use Zoomyboy\LaravelNami\NamiException;
use Zoomyboy\LaravelNami\Tests\TestCase;
@ -112,6 +113,19 @@ class FetchMemberTest extends TestCase
$this->assertNull($member->genderId);
}
/**
* @testWith [{"eintrittsdatum": null}]
* [{"landId": null}]
*/
public function testFailsFetchingWhenJoinedAtDateIsMissing(array $data): void
{
$this->expectException(MemberDataCorruptedException::class);
app(MemberFake::class)->shows(1000, 1001, $data);
$this->login()->member(1000, 1001);
}
public function testMemberFetchCanFail(): void
{
$this->expectException(NamiException::class);