Compare commits
10 Commits
70d36d76ac
...
a41b190cc2
Author | SHA1 | Date |
---|---|---|
philipp lang | a41b190cc2 | |
philipp lang | 419e8a1347 | |
Philipp Lang | 5b4ec86fe9 | |
philipp lang | 7b08f30cb2 | |
Philipp Lang | 315be84cf3 | |
Philipp Lang | 593e80b45b | |
Philipp Lang | 0ee7755077 | |
Philipp Lang | 3c3d0df50e | |
Philipp Lang | 07d1e67698 | |
Philipp Lang | 7077511494 |
|
@ -1,30 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Activity extends Model
|
|
||||||
{
|
|
||||||
protected $guarded = [];
|
|
||||||
|
|
||||||
public static function fromNami($item)
|
|
||||||
{
|
|
||||||
$item = collect($item)
|
|
||||||
->only(['descriptor', 'id'])
|
|
||||||
->mapWithKeys(function ($item, $key) {
|
|
||||||
if ('id' == $key) {
|
|
||||||
return ['id' => $item];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ['name' => $item];
|
|
||||||
})->toArray();
|
|
||||||
|
|
||||||
return new self($item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function subactivities()
|
|
||||||
{
|
|
||||||
return Nami::subactivitiesOf($this->id);
|
|
||||||
}
|
|
||||||
}
|
|
67
src/Api.php
67
src/Api.php
|
@ -10,12 +10,15 @@ use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\LazyCollection;
|
use Illuminate\Support\LazyCollection;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Zoomyboy\LaravelNami\Authentication\Authenticator;
|
use Zoomyboy\LaravelNami\Authentication\Authenticator;
|
||||||
|
use Zoomyboy\LaravelNami\Data\Activity;
|
||||||
use Zoomyboy\LaravelNami\Data\Baustein;
|
use Zoomyboy\LaravelNami\Data\Baustein;
|
||||||
use Zoomyboy\LaravelNami\Data\Course;
|
use Zoomyboy\LaravelNami\Data\Course;
|
||||||
|
use Zoomyboy\LaravelNami\Data\Group;
|
||||||
use Zoomyboy\LaravelNami\Data\Member;
|
use Zoomyboy\LaravelNami\Data\Member;
|
||||||
use Zoomyboy\LaravelNami\Data\MemberEntry;
|
use Zoomyboy\LaravelNami\Data\MemberEntry;
|
||||||
use Zoomyboy\LaravelNami\Data\Membership;
|
use Zoomyboy\LaravelNami\Data\Membership;
|
||||||
use Zoomyboy\LaravelNami\Data\MembershipEntry;
|
use Zoomyboy\LaravelNami\Data\MembershipEntry;
|
||||||
|
use Zoomyboy\LaravelNami\Data\Subactivity;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\ConflictException;
|
use Zoomyboy\LaravelNami\Exceptions\ConflictException;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\HttpException;
|
use Zoomyboy\LaravelNami\Exceptions\HttpException;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\MemberDataCorruptedException;
|
use Zoomyboy\LaravelNami\Exceptions\MemberDataCorruptedException;
|
||||||
|
@ -108,16 +111,6 @@ class Api
|
||||||
return $this->authenticator->isLoggedIn();
|
return $this->authenticator->isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function membersOf(int $groupId): Collection
|
|
||||||
{
|
|
||||||
$this->assertLoggedIn();
|
|
||||||
|
|
||||||
return $this->fetchCollection(
|
|
||||||
'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist',
|
|
||||||
'Member fetch failed'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function putMember(Member $member, ?int $firstActivity = null, ?int $firstSubactivity = null): int
|
public function putMember(Member $member, ?int $firstActivity = null, ?int $firstSubactivity = null): int
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
@ -198,14 +191,17 @@ class Api
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function subactivitiesOf(int $activityId): Collection
|
/**
|
||||||
|
* @return Collection<int, Subactivity>
|
||||||
|
*/
|
||||||
|
public function subactivitiesOf(Activity $activity): Collection
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
|
||||||
return $this->fetchCollection(
|
return $this->fetchCollection(
|
||||||
'/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activityId,
|
'/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activity->id,
|
||||||
'Fetch subactivities failed'
|
'Fetch subactivities failed'
|
||||||
)->map(fn ($subactivity) => Subactivity::fromNami($subactivity));
|
)->map(fn ($subactivity) => Subactivity::from($subactivity));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function membership(int $memberId, int $membershipId): Membership
|
public function membership(int $memberId, int $membershipId): Membership
|
||||||
|
@ -231,7 +227,7 @@ class Api
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection<Course>
|
* @return Collection<int, Course>
|
||||||
*/
|
*/
|
||||||
public function coursesOf(int $memberId): Collection
|
public function coursesOf(int $memberId): Collection
|
||||||
{
|
{
|
||||||
|
@ -318,14 +314,17 @@ class Api
|
||||||
return false !== $this->groups()->search(fn ($group) => $group->id == $groupId);
|
return false !== $this->groups()->search(fn ($group) => $group->id == $groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function groups(int $parentGroupId = null): Collection
|
/**
|
||||||
|
* @return Collection<int, Group>
|
||||||
|
*/
|
||||||
|
public function groups(?Group $parentGroup = null): Collection
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
|
||||||
return $this->fetchCollection(
|
return $this->fetchCollection(
|
||||||
'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/'.($parentGroupId ?: 'root'),
|
'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/'.($parentGroup ? $parentGroup->id : 'root'),
|
||||||
'Group fetch failed'
|
'Group fetch failed'
|
||||||
)->map(fn ($group) => Group::fromResponse($group, $parentGroupId));
|
)->map(fn ($group) => Group::from([...$group, 'parentId' => $parentGroup ? $parentGroup->id : null]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function group(int $groupId): ?Group
|
public function group(int $groupId): ?Group
|
||||||
|
@ -335,13 +334,9 @@ class Api
|
||||||
return $this->groups()->first(fn ($group) => $group->id == $groupId);
|
return $this->groups()->first(fn ($group) => $group->id == $groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function subgroupsOf(int $groupId): Collection
|
/**
|
||||||
{
|
* @return Collection<int, Gender>
|
||||||
$this->assertLoggedIn();
|
*/
|
||||||
|
|
||||||
return $this->groups($groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function genders(): Collection
|
public function genders(): Collection
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
@ -352,6 +347,9 @@ class Api
|
||||||
->filter(fn ($gender) => !$gender->isNull);
|
->filter(fn ($gender) => !$gender->isNull);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Nationality>
|
||||||
|
*/
|
||||||
public function nationalities(): Collection
|
public function nationalities(): Collection
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
@ -360,6 +358,9 @@ class Api
|
||||||
->map(fn ($nationality) => Nationality::fromNami($nationality));
|
->map(fn ($nationality) => Nationality::fromNami($nationality));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Country>
|
||||||
|
*/
|
||||||
public function countries(): Collection
|
public function countries(): Collection
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
@ -368,6 +369,9 @@ class Api
|
||||||
->map(fn ($country) => Country::fromNami($country));
|
->map(fn ($country) => Country::fromNami($country));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Region>
|
||||||
|
*/
|
||||||
public function regions(): Collection
|
public function regions(): Collection
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
@ -376,6 +380,9 @@ class Api
|
||||||
->map(fn ($region) => Region::fromNami($region));
|
->map(fn ($region) => Region::fromNami($region));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Fee>
|
||||||
|
*/
|
||||||
public function feesOf(int $groupid): Collection
|
public function feesOf(int $groupid): Collection
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
@ -384,6 +391,9 @@ class Api
|
||||||
->map(fn ($fee) => Fee::fromNami($fee));
|
->map(fn ($fee) => Fee::fromNami($fee));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Confession>
|
||||||
|
*/
|
||||||
public function confessions(): Collection
|
public function confessions(): Collection
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
@ -392,12 +402,15 @@ class Api
|
||||||
->map(fn ($confession) => Confession::fromNami($confession));
|
->map(fn ($confession) => Confession::fromNami($confession));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function activities(int $groupId): Collection
|
/**
|
||||||
|
* @return Collection<int, Activity>
|
||||||
|
*/
|
||||||
|
public function activities(Group $group): Collection
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
|
||||||
return $this->fetchCollection("/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/{$groupId}", 'Fetch activities failed')
|
return $this->fetchCollection("/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/{$group->id}", 'Fetch activities failed')
|
||||||
->map(fn ($activity) => Activity::fromNami($activity));
|
->map(fn ($activity) => Activity::from($activity));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,12 +7,19 @@ use Illuminate\Support\Facades\Http;
|
||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
use Zoomyboy\LaravelNami\LoginException;
|
use Zoomyboy\LaravelNami\LoginException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template Account of array{mglnr: int, password: string}
|
||||||
|
*/
|
||||||
class FakeCookie extends Authenticator
|
class FakeCookie extends Authenticator
|
||||||
{
|
{
|
||||||
|
/** @var array<int, Account> */
|
||||||
private array $validAccounts = [];
|
private array $validAccounts = [];
|
||||||
public ?array $invalidAccounts = null;
|
/** @var Account|null */
|
||||||
public ?array $authenticated = null;
|
public ?array $authenticated = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return self<Account>
|
||||||
|
*/
|
||||||
public function login(int $mglnr, string $password): self
|
public function login(int $mglnr, string $password): self
|
||||||
{
|
{
|
||||||
$authenticated = collect($this->validAccounts)->search(
|
$authenticated = collect($this->validAccounts)->search(
|
||||||
|
@ -50,14 +57,6 @@ class FakeCookie extends Authenticator
|
||||||
$this->validAccounts[] = ['mglnr' => $mglnr, 'password' => $password];
|
$this->validAccounts[] = ['mglnr' => $mglnr, 'password' => $password];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reisters an account that cannot login with the given password.
|
|
||||||
*/
|
|
||||||
public function fails(int $mglnr, string $password): void
|
|
||||||
{
|
|
||||||
$this->invalidAccounts[] = ['mglnr' => $mglnr, 'password' => $password];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function assertLoggedInWith(int $mglnr, string $password): void
|
public function assertLoggedInWith(int $mglnr, string $password): void
|
||||||
{
|
{
|
||||||
Assert::assertSame($mglnr, data_get($this->authenticated, 'mglnr'));
|
Assert::assertSame($mglnr, data_get($this->authenticated, 'mglnr'));
|
||||||
|
|
|
@ -1,264 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami\Backend;
|
|
||||||
|
|
||||||
use GuzzleHttp\Promise\PromiseInterface;
|
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Zoomyboy\LaravelNami\Fakes\CourseFake;
|
|
||||||
|
|
||||||
class FakeBackend
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param array <string, mixed> $data
|
|
||||||
*/
|
|
||||||
public function addSearch(int $mitgliedsNr, array $data): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data, $mitgliedsNr) {
|
|
||||||
if ($request->url() === 'https://nami.dpsg.de/ica/rest/nami/search-multi/result-list?searchedValues='.rawurlencode(json_encode(['mitgliedsNummber' => $mitgliedsNr]) ?: '{}').'&page=1&start=0&limit=100') {
|
|
||||||
$content = [
|
|
||||||
'success' => true,
|
|
||||||
'data' => [$data],
|
|
||||||
'responseType' => 'OK',
|
|
||||||
'totalEntries' => 1,
|
|
||||||
];
|
|
||||||
|
|
||||||
return Http::response(json_encode($content) ?: '{}', 200);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array{name: string, id: int}> $data
|
|
||||||
*/
|
|
||||||
public function fakeNationalities(array $data): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data) {
|
|
||||||
if ('https://nami.dpsg.de/ica/rest/baseadmin/staatsangehoerigkeit' === $request->url()) {
|
|
||||||
return $this->dataResponse($data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<string, string|int|true> $data
|
|
||||||
*/
|
|
||||||
public function fakeMember(array $data): self
|
|
||||||
{
|
|
||||||
return $this->fakeMembers([$data]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function singleMemberUrl(int $gruppierungId, int $memberId): string
|
|
||||||
{
|
|
||||||
return "https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{$gruppierungId}/{$memberId}";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array<string, mixed>> $data
|
|
||||||
*/
|
|
||||||
public function fakeMembers(array $data): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data) {
|
|
||||||
foreach ($data as $member) {
|
|
||||||
if ($request->url() === $this->singleMemberUrl($member['gruppierungId'], $member['id']) && 'GET' === $request->method()) {
|
|
||||||
$content = [
|
|
||||||
'success' => true,
|
|
||||||
'data' => $member,
|
|
||||||
];
|
|
||||||
|
|
||||||
return Http::response(json_encode($content) ?: '{}', 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->url() === "https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$member['id']}/flist") {
|
|
||||||
$content = [
|
|
||||||
'success' => true,
|
|
||||||
'data' => array_map(function ($membership) {
|
|
||||||
return (object) [
|
|
||||||
'entries_aktivVon' => $membership['aktivVon'],
|
|
||||||
'entries_aktivBis' => $membership['aktivBis'],
|
|
||||||
'entries_gruppierung' => $membership['gruppierung'],
|
|
||||||
'id' => $membership['id'],
|
|
||||||
'entries_taetigkeit' => $membership['taetigkeit'],
|
|
||||||
'entries_untergliederung' => $membership['untergliederung'],
|
|
||||||
];
|
|
||||||
}, $member['memberships'] ?? []),
|
|
||||||
];
|
|
||||||
|
|
||||||
return Http::response(json_encode($content) ?: '{}', 200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (collect($data)->chunk(100) as $i => $chunk) {
|
|
||||||
if ($request->url() === 'https://nami.dpsg.de/ica/rest/nami/search-multi/result-list?searchedValues='.rawurlencode('{}').'&page='.($i + 1).'&start='.($i * 100).'&limit=100') {
|
|
||||||
return Http::response(json_encode([
|
|
||||||
'success' => true,
|
|
||||||
'totalEntries' => count($data),
|
|
||||||
'data' => collect($chunk)->map(fn ($member) => [
|
|
||||||
'entries_id' => $member['id'],
|
|
||||||
'entries_gruppierungId' => $member['gruppierungId'],
|
|
||||||
])->toArray(),
|
|
||||||
]) ?: '{}', 200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach ($data as $member) {
|
|
||||||
$courseFake = app(CourseFake::class)
|
|
||||||
->fetches($member['id'], collect(data_get($member, 'courses', []))->pluck('id')->toArray());
|
|
||||||
foreach (data_get($member, 'courses', []) as $course) {
|
|
||||||
$courseFake->shows($member['id'], $course);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fakeSingleMembership(int $memberId, int $membershipId, array $data)
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data, $memberId, $membershipId) {
|
|
||||||
if ($request->url() === "https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}/{$membershipId}") {
|
|
||||||
$content = [
|
|
||||||
'success' => true,
|
|
||||||
'data' => $data,
|
|
||||||
'responseType' => 'OK',
|
|
||||||
];
|
|
||||||
|
|
||||||
return Http::response(json_encode($content) ?: '{}', 200);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array{name: string, id: int}> $data
|
|
||||||
*/
|
|
||||||
public function fakeCountries(array $data): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data) {
|
|
||||||
if ('https://nami.dpsg.de/ica/rest/baseadmin/land' === $request->url()) {
|
|
||||||
return $this->dataResponse($data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array{name: string, id: int}> $data
|
|
||||||
*/
|
|
||||||
public function fakeCourses(array $data): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data) {
|
|
||||||
if ('https://nami.dpsg.de/ica/rest/module/baustein' === $request->url()) {
|
|
||||||
return $this->dataResponse($data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array{name: string, id: int}> $data
|
|
||||||
*/
|
|
||||||
public function fakeGenders(array $data): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data) {
|
|
||||||
if ('https://nami.dpsg.de/ica/rest/baseadmin/geschlecht' === $request->url()) {
|
|
||||||
return $this->dataResponse($data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array{name: string, id: int}> $data
|
|
||||||
*/
|
|
||||||
public function fakeRegions(array $data): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data) {
|
|
||||||
if ('https://nami.dpsg.de/ica/rest/baseadmin/region' === $request->url()) {
|
|
||||||
return $this->dataResponse($data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array{name: string, id: int}> $data
|
|
||||||
*/
|
|
||||||
public function fakeActivities(int $groupId, array $data): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data, $groupId) {
|
|
||||||
if ($request->url() === "https://nami.dpsg.de/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/{$groupId}") {
|
|
||||||
return $this->dataResponse($data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array<int, array{name: string, id: int}>> $matches
|
|
||||||
*/
|
|
||||||
public function fakeSubactivities(array $matches): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($matches) {
|
|
||||||
foreach ($matches as $activityId => $data) {
|
|
||||||
if ($request->url() === "https://nami.dpsg.de/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/{$activityId}") {
|
|
||||||
return $this->dataResponse($data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array{name: string, id: int}> $data
|
|
||||||
*/
|
|
||||||
public function fakeFees(int $groupId, array $data): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data, $groupId) {
|
|
||||||
if ($request->url() === "https://nami.dpsg.de/ica/rest/namiBeitrag/beitragsartmgl/gruppierung/{$groupId}") {
|
|
||||||
return $this->dataResponse($data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array{name: string, id: int}> $data
|
|
||||||
*/
|
|
||||||
public function fakeConfessions(array $data): self
|
|
||||||
{
|
|
||||||
Http::fake(function ($request) use ($data) {
|
|
||||||
if ('https://nami.dpsg.de/ica/rest/baseadmin/konfession' === $request->url()) {
|
|
||||||
return $this->dataResponse($data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, array{name: string, id: int}> $data
|
|
||||||
*/
|
|
||||||
private function dataResponse(array $data): PromiseInterface
|
|
||||||
{
|
|
||||||
$content = [
|
|
||||||
'success' => true,
|
|
||||||
'data' => collect($data)->map(fn ($item) => ['descriptor' => $item['name'], 'id' => $item['id'], 'name' => ''])->toArray(),
|
|
||||||
'responseType' => 'OK',
|
|
||||||
'totalEntries' => count($data),
|
|
||||||
];
|
|
||||||
|
|
||||||
return Http::response(json_encode($content) ?: '{}', 200);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Casters;
|
||||||
|
|
||||||
|
use Spatie\LaravelData\Casts\Cast;
|
||||||
|
use Spatie\LaravelData\Support\DataProperty;
|
||||||
|
|
||||||
|
class GroupCast implements Cast
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $context
|
||||||
|
*/
|
||||||
|
public function cast(DataProperty $property, mixed $value, array $context): ?string
|
||||||
|
{
|
||||||
|
if ($property->type->isNullable && !$value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Data;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Zoomyboy\LaravelNami\Nami;
|
||||||
|
|
||||||
|
class Activity extends EnumData
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Subactivity>
|
||||||
|
*/
|
||||||
|
public function subactivities(): Collection
|
||||||
|
{
|
||||||
|
return Nami::subactivitiesOf($this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Data;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Spatie\LaravelData\Attributes\MapInputName;
|
||||||
|
use Zoomyboy\LaravelNami\Nami;
|
||||||
|
|
||||||
|
class Group extends EnumData
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $id,
|
||||||
|
#[MapInputName('descriptor')]
|
||||||
|
public string $name,
|
||||||
|
public ?int $parentId,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Activity>
|
||||||
|
*/
|
||||||
|
public function activities(): Collection
|
||||||
|
{
|
||||||
|
return Nami::activities($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, self>
|
||||||
|
*/
|
||||||
|
public function children(): Collection {
|
||||||
|
return Nami::groups($this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,9 @@ class Member extends Data
|
||||||
#[MapInputName('beitragsartId')]
|
#[MapInputName('beitragsartId')]
|
||||||
public ?int $feeId,
|
public ?int $feeId,
|
||||||
|
|
||||||
|
#[MapInputName('beitragsart')]
|
||||||
|
public ?string $feeName,
|
||||||
|
|
||||||
#[MapInputName('eintrittsdatum')]
|
#[MapInputName('eintrittsdatum')]
|
||||||
#[WithCast(CarbonCast::class, format: 'Y-m-d H:i:s')]
|
#[WithCast(CarbonCast::class, format: 'Y-m-d H:i:s')]
|
||||||
#[WithTransformer(CarbonTransformer::class, format: 'Y-m-d H:i:s')]
|
#[WithTransformer(CarbonTransformer::class, format: 'Y-m-d H:i:s')]
|
||||||
|
@ -152,6 +155,7 @@ class Member extends Data
|
||||||
'staatsangehoerigkeitText' => $this->otherCountry,
|
'staatsangehoerigkeitText' => $this->otherCountry,
|
||||||
'nameZusatz' => $this->furtherAddress,
|
'nameZusatz' => $this->furtherAddress,
|
||||||
'version' => $this->version,
|
'version' => $this->version,
|
||||||
|
'eintrittsdatum' => $this->joinedAt->format('Y-m-d 00:00:00'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +177,10 @@ class Member extends Data
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data_get($rawData, 'geburtsDatum') && Carbon::parse(data_get($rawData, 'geburtsDatum'))->diffInYears(now()) > 100) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,4 +49,9 @@ class Membership extends Data
|
||||||
'untergliederungId' => $this->subactivityId,
|
'untergliederungId' => $this->subactivityId,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function group(): Group {
|
||||||
|
return Group::from(['name' => $this->group ?: '', 'id' => $this->groupId]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Data;
|
||||||
|
|
||||||
|
class Subactivity extends EnumData
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -16,6 +16,9 @@ abstract class Fake
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection<int, mixed> $collection
|
||||||
|
*/
|
||||||
public function collection(Collection $collection): PromiseInterface
|
public function collection(Collection $collection): PromiseInterface
|
||||||
{
|
{
|
||||||
return Http::response(json_encode([
|
return Http::response(json_encode([
|
||||||
|
|
|
@ -17,6 +17,9 @@ class MemberFake extends Fake
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $data
|
||||||
|
*/
|
||||||
public function shows(int $groupId, int $memberId, array $data = []): self
|
public function shows(int $groupId, int $memberId, array $data = []): self
|
||||||
{
|
{
|
||||||
Http::fake(function ($request) use ($groupId, $memberId, $data) {
|
Http::fake(function ($request) use ($groupId, $memberId, $data) {
|
||||||
|
|
|
@ -183,22 +183,22 @@ class MembershipFake extends Fake
|
||||||
public function assertCreated(int $memberId, array $payload): void
|
public function assertCreated(int $memberId, array $payload): void
|
||||||
{
|
{
|
||||||
$url = "https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}";
|
$url = "https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}";
|
||||||
|
|
||||||
Http::assertSent(function ($request) use ($url, $payload) {
|
Http::assertSent(function ($request) use ($url, $payload) {
|
||||||
if ($request->url() !== $url || 'POST' !== $request->method()) {
|
if ($request->url() !== $url || 'POST' !== $request->method()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
$requestBody = json_decode($request->body(), true);
|
||||||
data_get($request, 'gruppierungId') !== data_get($payload, 'gruppierungId')
|
|
||||||
|| data_get($request, 'id') !== data_get($payload, 'id')
|
|
||||||
|| data_get($request, 'taetigkeitId') !== data_get($payload, 'taetigkeitId')
|
|
||||||
|| data_get($request, 'untergliederungId') !== data_get($payload, 'untergliederungId')
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data_get($request, 'aktivVon') && $request['aktivVon'] !== data_get($payload, 'aktivVon')) {
|
foreach ($payload as $key => $value) {
|
||||||
return false;
|
if (!array_key_exists($key, $requestBody)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($requestBody[$key] !== $value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami;
|
|
||||||
|
|
||||||
use Illuminate\Contracts\Support\Arrayable;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
class Group implements Arrayable
|
|
||||||
{
|
|
||||||
public string $name;
|
|
||||||
public int $id;
|
|
||||||
public ?int $parentId;
|
|
||||||
|
|
||||||
public static function fromResponse(array $response, ?int $parent): self
|
|
||||||
{
|
|
||||||
return (new self())
|
|
||||||
->setName($response['descriptor'])
|
|
||||||
->setId($response['id'])
|
|
||||||
->setParentId($parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName(string $name): self
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setId(int $id): self
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setParentId(?int $parentId = null): self
|
|
||||||
{
|
|
||||||
$this->parentId = $parentId;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toArray()
|
|
||||||
{
|
|
||||||
return ['id' => $this->id, 'name' => $this->name, 'parent_id' => $this->parentId];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function subgroups()
|
|
||||||
{
|
|
||||||
return Nami::subgroupsOf($this->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fees()
|
|
||||||
{
|
|
||||||
return Nami::feesOf($this->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function activities(): Collection
|
|
||||||
{
|
|
||||||
return Nami::activities($this->id);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Subactivity extends Model
|
|
||||||
{
|
|
||||||
protected $guarded = [];
|
|
||||||
|
|
||||||
public static function fromNami($item)
|
|
||||||
{
|
|
||||||
$item = collect($item)
|
|
||||||
->only(['descriptor', 'id'])
|
|
||||||
->mapWithKeys(function ($item, $key) {
|
|
||||||
if ('id' == $key) {
|
|
||||||
return ['id' => $item];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ['name' => $item];
|
|
||||||
})->toArray();
|
|
||||||
|
|
||||||
return new self($item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNameAttribute()
|
|
||||||
{
|
|
||||||
return ucfirst($this->attributes['name']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIsNullAttribute()
|
|
||||||
{
|
|
||||||
return $this->attributes['id'] == self::getNullValue();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,6 +12,8 @@ class Paginator
|
||||||
* @param callable(int): Response $responseFactory
|
* @param callable(int): Response $responseFactory
|
||||||
* @param callable(Response): Generator $generator
|
* @param callable(Response): Generator $generator
|
||||||
* @param callable(Response): int $totalFetcher
|
* @param callable(Response): int $totalFetcher
|
||||||
|
*
|
||||||
|
* @return LazyCollection<int, mixed>
|
||||||
*/
|
*/
|
||||||
public function result(callable $responseFactory, callable $generator, callable $totalFetcher): LazyCollection
|
public function result(callable $responseFactory, callable $generator, callable $totalFetcher): LazyCollection
|
||||||
{
|
{
|
||||||
|
@ -27,6 +29,8 @@ class Paginator
|
||||||
* @param callable(int, int): Response $responseFactory
|
* @param callable(int, int): Response $responseFactory
|
||||||
* @param callable(Response): Generator $generator
|
* @param callable(Response): Generator $generator
|
||||||
* @param callable(Response): int $totalFetcher
|
* @param callable(Response): int $totalFetcher
|
||||||
|
*
|
||||||
|
* @return LazyCollection<int, mixed>
|
||||||
*/
|
*/
|
||||||
public function startResult(int $perPage, callable $responseFactory, callable $generator, callable $totalFetcher): LazyCollection
|
public function startResult(int $perPage, callable $responseFactory, callable $generator, callable $totalFetcher): LazyCollection
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,6 @@ class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
public function loginWithWrongCredentials(): Api
|
public function loginWithWrongCredentials(): Api
|
||||||
{
|
{
|
||||||
Auth::fake();
|
Auth::fake();
|
||||||
Auth::fails(12345, 'wrong');
|
|
||||||
|
|
||||||
return Nami::login(12345, 'wrong');
|
return Nami::login(12345, 'wrong');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami\Tests\Unit\Member;
|
namespace Zoomyboy\LaravelNami\Tests\Unit\Api;
|
||||||
|
|
||||||
use Zoomyboy\LaravelNami\Exceptions\MemberDataCorruptedException;
|
use Zoomyboy\LaravelNami\Exceptions\MemberDataCorruptedException;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\NotSuccessfulException;
|
use Zoomyboy\LaravelNami\Exceptions\NotSuccessfulException;
|
||||||
|
@ -12,6 +12,7 @@ class FetchMemberTest extends TestCase
|
||||||
public function testGetASingleMember(): void
|
public function testGetASingleMember(): void
|
||||||
{
|
{
|
||||||
app(MemberFake::class)->shows(1000, 1001, [
|
app(MemberFake::class)->shows(1000, 1001, [
|
||||||
|
'beitragsart' => 'Ba',
|
||||||
'beitragsartId' => 1,
|
'beitragsartId' => 1,
|
||||||
'eintrittsdatum' => '2005-05-01 00:00:00',
|
'eintrittsdatum' => '2005-05-01 00:00:00',
|
||||||
'email' => 'pille@stamm-silva.de',
|
'email' => 'pille@stamm-silva.de',
|
||||||
|
@ -45,6 +46,7 @@ class FetchMemberTest extends TestCase
|
||||||
$member = $this->login()->member(1000, 1001);
|
$member = $this->login()->member(1000, 1001);
|
||||||
|
|
||||||
$this->assertSame(1, $member->feeId);
|
$this->assertSame(1, $member->feeId);
|
||||||
|
$this->assertSame('Ba', $member->feeName);
|
||||||
$this->assertSame('2005-05-01 00:00:00', $member->joinedAt->toDateTimeString());
|
$this->assertSame('2005-05-01 00:00:00', $member->joinedAt->toDateTimeString());
|
||||||
$this->assertSame(1000, $member->groupId);
|
$this->assertSame(1000, $member->groupId);
|
||||||
$this->assertSame(1001, $member->id);
|
$this->assertSame(1001, $member->id);
|
||||||
|
|
|
@ -35,7 +35,8 @@ class MembershipTest extends TestCase
|
||||||
$this->assertSame(1000, $membership->groupId);
|
$this->assertSame(1000, $membership->groupId);
|
||||||
$this->assertSame(15, $membership->activityId);
|
$this->assertSame(15, $membership->activityId);
|
||||||
$this->assertSame(16, $membership->subactivityId);
|
$this->assertSame(16, $membership->subactivityId);
|
||||||
$this->assertSame('::group::', $membership->group);
|
$this->assertSame('::group::', $membership->group()->name);
|
||||||
|
$this->assertSame(1000, $membership->group()->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFetchesMembership(): void
|
public function testFetchesMembership(): void
|
||||||
|
@ -95,7 +96,7 @@ class MembershipTest extends TestCase
|
||||||
'taetigkeitId' => 2,
|
'taetigkeitId' => 2,
|
||||||
'untergliederungId' => 3,
|
'untergliederungId' => 3,
|
||||||
'aktivVon' => '2022-02-03T00:00:00',
|
'aktivVon' => '2022-02-03T00:00:00',
|
||||||
'aktivBis' => '',
|
'aktivBis' => null,
|
||||||
'gruppierungId' => 1400,
|
'gruppierungId' => 1400,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ class PutMemberTest extends TestCase
|
||||||
'staatsangehoerigkeitText' => 'Land',
|
'staatsangehoerigkeitText' => 'Land',
|
||||||
'nameZusatz' => 'Name',
|
'nameZusatz' => 'Name',
|
||||||
'version' => 40,
|
'version' => 40,
|
||||||
|
'eintrittsdatum' => '2021-02-02 00:00:00',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Zoomyboy\LaravelNami\Group;
|
use Zoomyboy\LaravelNami\Data\Group;
|
||||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||||
|
|
||||||
class GetGroupsTest extends TestCase
|
class GetGroupsTest extends TestCase
|
||||||
|
@ -18,11 +18,11 @@ class GetGroupsTest extends TestCase
|
||||||
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$groups = $this->login()->groups();
|
$group = $this->login()->groups()->first();
|
||||||
|
|
||||||
$this->assertEquals([
|
$this->assertSame(100, $group->id);
|
||||||
['id' => 100, 'name' => 'Group', 'parent_id' => null],
|
$this->assertSame('Group', $group->name);
|
||||||
], $groups->toArray());
|
$this->assertNull($group->parentId);
|
||||||
Http::assertSent(function ($request) {
|
Http::assertSent(function ($request) {
|
||||||
return 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' == $request->url();
|
return 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' == $request->url();
|
||||||
});
|
});
|
||||||
|
@ -49,13 +49,13 @@ class GetGroupsTest extends TestCase
|
||||||
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/100' => Http::response($this->subgroupsResponse, 200),
|
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/100' => Http::response($this->subgroupsResponse, 200),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$subgroups = $this->login()->group(100)->subgroups();
|
$subgroups = $this->login()->group(100)->children();
|
||||||
|
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
['id' => 101300, 'parent_id' => 100, 'name' => 'Siebengebirge'],
|
['id' => 101300, 'parentId' => 100, 'name' => 'Siebengebirge'],
|
||||||
['id' => 100900, 'parent_id' => 100, 'name' => 'Sieg'],
|
['id' => 100900, 'parentId' => 100, 'name' => 'Sieg'],
|
||||||
['id' => 100900, 'parent_id' => 100, 'name' => 'Sieg'],
|
['id' => 100900, 'parentId' => 100, 'name' => 'Sieg'],
|
||||||
['id' => 101000, 'parent_id' => 100, 'name' => 'Voreifel'],
|
['id' => 101000, 'parentId' => 100, 'name' => 'Voreifel'],
|
||||||
], $subgroups->toArray());
|
], $subgroups->toArray());
|
||||||
$subgroups->each(function ($group) {
|
$subgroups->each(function ($group) {
|
||||||
$this->assertInstanceOf(Group::class, $group);
|
$this->assertInstanceOf(Group::class, $group);
|
||||||
|
|
|
@ -7,7 +7,7 @@ use Zoomyboy\LaravelNami\Exceptions\NoJsonReceivedException;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\NotAuthenticatedException;
|
use Zoomyboy\LaravelNami\Exceptions\NotAuthenticatedException;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\NotSuccessfulException;
|
use Zoomyboy\LaravelNami\Exceptions\NotSuccessfulException;
|
||||||
use Zoomyboy\LaravelNami\Fakes\GroupFake;
|
use Zoomyboy\LaravelNami\Fakes\GroupFake;
|
||||||
use Zoomyboy\LaravelNami\Group;
|
use Zoomyboy\LaravelNami\Data\Group;
|
||||||
use Zoomyboy\LaravelNami\Nami;
|
use Zoomyboy\LaravelNami\Nami;
|
||||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ class GroupsTest extends TestCase
|
||||||
$this->assertInstanceOf(Group::class, $group);
|
$this->assertInstanceOf(Group::class, $group);
|
||||||
$this->assertEquals('testgroup', $group->name);
|
$this->assertEquals('testgroup', $group->name);
|
||||||
$this->assertEquals(1234, $group->id);
|
$this->assertEquals(1234, $group->id);
|
||||||
|
$this->assertNull($group->parentId);
|
||||||
|
|
||||||
app(GroupFake::class)->assertRootFetched();
|
app(GroupFake::class)->assertRootFetched();
|
||||||
}
|
}
|
||||||
|
@ -45,10 +46,11 @@ class GroupsTest extends TestCase
|
||||||
555 => ['name' => 'ABC'],
|
555 => ['name' => 'ABC'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$group = Nami::login(12345, 'secret')->groups(1234)->first();
|
$group = Nami::login(12345, 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null]))->first();
|
||||||
|
|
||||||
$this->assertEquals('ABC', $group->name);
|
$this->assertEquals('ABC', $group->name);
|
||||||
$this->assertEquals(555, $group->id);
|
$this->assertEquals(555, $group->id);
|
||||||
|
$this->assertEquals(1234, $group->parentId);
|
||||||
|
|
||||||
app(GroupFake::class)->assertFetched(1234);
|
app(GroupFake::class)->assertFetched(1234);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +79,7 @@ class GroupsTest extends TestCase
|
||||||
]);
|
]);
|
||||||
app(GroupFake::class)->failsToFetch(1234);
|
app(GroupFake::class)->failsToFetch(1234);
|
||||||
|
|
||||||
Nami::login(12345, 'secret')->groups(1234);
|
Nami::login(12345, 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItDoesntReturnGroupWhenNoJsonIsReturned(): void
|
public function testItDoesntReturnGroupWhenNoJsonIsReturned(): void
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Zoomyboy\LaravelNami\Data\Activity;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\NoJsonReceivedException;
|
use Zoomyboy\LaravelNami\Exceptions\NoJsonReceivedException;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\NotSuccessfulException;
|
use Zoomyboy\LaravelNami\Exceptions\NotSuccessfulException;
|
||||||
use Zoomyboy\LaravelNami\Fakes\SubactivityFake;
|
use Zoomyboy\LaravelNami\Fakes\SubactivityFake;
|
||||||
|
@ -22,8 +23,8 @@ class PullActivitiesTest extends TestCase
|
||||||
$activities = $this->login()->group(103)->activities();
|
$activities = $this->login()->group(103)->activities();
|
||||||
|
|
||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
['name' => 'Ac1', 'id' => 4],
|
['id' => 4, 'name' => 'Ac1'],
|
||||||
['name' => 'Ac2', 'id' => 3],
|
['id' => 3, 'name' => 'Ac2'],
|
||||||
], $activities->toArray());
|
], $activities->toArray());
|
||||||
Http::assertSentCount(2);
|
Http::assertSentCount(2);
|
||||||
}
|
}
|
||||||
|
@ -39,8 +40,8 @@ class PullActivitiesTest extends TestCase
|
||||||
$subactivities = $this->login()->group(103)->activities()->first()->subactivities();
|
$subactivities = $this->login()->group(103)->activities()->first()->subactivities();
|
||||||
|
|
||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
['name' => 'Biber', 'id' => 40],
|
['id' => 40, 'name' => 'Biber'],
|
||||||
['name' => 'Wölfling', 'id' => 30],
|
['id' => 30, 'name' => 'Wölfling'],
|
||||||
], $subactivities->toArray());
|
], $subactivities->toArray());
|
||||||
Http::assertSentCount(3);
|
Http::assertSentCount(3);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +51,7 @@ class PullActivitiesTest extends TestCase
|
||||||
$this->expectException(NotSuccessfulException::class);
|
$this->expectException(NotSuccessfulException::class);
|
||||||
app(SubactivityFake::class)->fetchFails(4, 'sorry dude');
|
app(SubactivityFake::class)->fetchFails(4, 'sorry dude');
|
||||||
|
|
||||||
$subactivities = $this->login()->subactivitiesOf(4);
|
$this->login()->subactivitiesOf(Activity::from(['id' => 4]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testContinueIfSubactivitiesRequestReturnsHtml(): void
|
public function testContinueIfSubactivitiesRequestReturnsHtml(): void
|
||||||
|
@ -58,6 +59,6 @@ class PullActivitiesTest extends TestCase
|
||||||
$this->expectException(NoJsonReceivedException::class);
|
$this->expectException(NoJsonReceivedException::class);
|
||||||
app(SubactivityFake::class)->fetchFailsWithoutJson(4);
|
app(SubactivityFake::class)->fetchFailsWithoutJson(4);
|
||||||
|
|
||||||
$this->login()->subactivitiesOf(4);
|
$this->login()->subactivitiesOf(Activity::from(['id' => 4]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue