Compare commits

..

No commits in common. "a41b190cc2509ee940967b6c108a557b0a9c5def" and "70d36d76ac3d239508c9b992d073e376c7bab254" have entirely different histories.

23 changed files with 460 additions and 193 deletions

30
src/Activity.php Normal file
View File

@ -0,0 +1,30 @@
<?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);
}
}

View File

@ -10,15 +10,12 @@ use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Str;
use Zoomyboy\LaravelNami\Authentication\Authenticator;
use Zoomyboy\LaravelNami\Data\Activity;
use Zoomyboy\LaravelNami\Data\Baustein;
use Zoomyboy\LaravelNami\Data\Course;
use Zoomyboy\LaravelNami\Data\Group;
use Zoomyboy\LaravelNami\Data\Member;
use Zoomyboy\LaravelNami\Data\MemberEntry;
use Zoomyboy\LaravelNami\Data\Membership;
use Zoomyboy\LaravelNami\Data\MembershipEntry;
use Zoomyboy\LaravelNami\Data\Subactivity;
use Zoomyboy\LaravelNami\Exceptions\ConflictException;
use Zoomyboy\LaravelNami\Exceptions\HttpException;
use Zoomyboy\LaravelNami\Exceptions\MemberDataCorruptedException;
@ -111,6 +108,16 @@ class Api
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
{
$this->assertLoggedIn();
@ -191,17 +198,14 @@ class Api
}
}
/**
* @return Collection<int, Subactivity>
*/
public function subactivitiesOf(Activity $activity): Collection
public function subactivitiesOf(int $activityId): Collection
{
$this->assertLoggedIn();
return $this->fetchCollection(
'/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activity->id,
'/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activityId,
'Fetch subactivities failed'
)->map(fn ($subactivity) => Subactivity::from($subactivity));
)->map(fn ($subactivity) => Subactivity::fromNami($subactivity));
}
public function membership(int $memberId, int $membershipId): Membership
@ -227,7 +231,7 @@ class Api
}
/**
* @return Collection<int, Course>
* @return Collection<Course>
*/
public function coursesOf(int $memberId): Collection
{
@ -314,17 +318,14 @@ class Api
return false !== $this->groups()->search(fn ($group) => $group->id == $groupId);
}
/**
* @return Collection<int, Group>
*/
public function groups(?Group $parentGroup = null): Collection
public function groups(int $parentGroupId = null): Collection
{
$this->assertLoggedIn();
return $this->fetchCollection(
'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/'.($parentGroup ? $parentGroup->id : 'root'),
'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/'.($parentGroupId ?: 'root'),
'Group fetch failed'
)->map(fn ($group) => Group::from([...$group, 'parentId' => $parentGroup ? $parentGroup->id : null]));
)->map(fn ($group) => Group::fromResponse($group, $parentGroupId));
}
public function group(int $groupId): ?Group
@ -334,9 +335,13 @@ class Api
return $this->groups()->first(fn ($group) => $group->id == $groupId);
}
/**
* @return Collection<int, Gender>
*/
public function subgroupsOf(int $groupId): Collection
{
$this->assertLoggedIn();
return $this->groups($groupId);
}
public function genders(): Collection
{
$this->assertLoggedIn();
@ -347,9 +352,6 @@ class Api
->filter(fn ($gender) => !$gender->isNull);
}
/**
* @return Collection<int, Nationality>
*/
public function nationalities(): Collection
{
$this->assertLoggedIn();
@ -358,9 +360,6 @@ class Api
->map(fn ($nationality) => Nationality::fromNami($nationality));
}
/**
* @return Collection<int, Country>
*/
public function countries(): Collection
{
$this->assertLoggedIn();
@ -369,9 +368,6 @@ class Api
->map(fn ($country) => Country::fromNami($country));
}
/**
* @return Collection<int, Region>
*/
public function regions(): Collection
{
$this->assertLoggedIn();
@ -380,9 +376,6 @@ class Api
->map(fn ($region) => Region::fromNami($region));
}
/**
* @return Collection<int, Fee>
*/
public function feesOf(int $groupid): Collection
{
$this->assertLoggedIn();
@ -391,9 +384,6 @@ class Api
->map(fn ($fee) => Fee::fromNami($fee));
}
/**
* @return Collection<int, Confession>
*/
public function confessions(): Collection
{
$this->assertLoggedIn();
@ -402,15 +392,12 @@ class Api
->map(fn ($confession) => Confession::fromNami($confession));
}
/**
* @return Collection<int, Activity>
*/
public function activities(Group $group): Collection
public function activities(int $groupId): Collection
{
$this->assertLoggedIn();
return $this->fetchCollection("/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/{$group->id}", 'Fetch activities failed')
->map(fn ($activity) => Activity::from($activity));
return $this->fetchCollection("/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/{$groupId}", 'Fetch activities failed')
->map(fn ($activity) => Activity::fromNami($activity));
}
/**

View File

@ -7,19 +7,12 @@ use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Assert;
use Zoomyboy\LaravelNami\LoginException;
/**
* @template Account of array{mglnr: int, password: string}
*/
class FakeCookie extends Authenticator
{
/** @var array<int, Account> */
private array $validAccounts = [];
/** @var Account|null */
public ?array $invalidAccounts = null;
public ?array $authenticated = null;
/**
* @return self<Account>
*/
public function login(int $mglnr, string $password): self
{
$authenticated = collect($this->validAccounts)->search(
@ -57,6 +50,14 @@ class FakeCookie extends Authenticator
$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
{
Assert::assertSame($mglnr, data_get($this->authenticated, 'mglnr'));

264
src/Backend/FakeBackend.php Normal file
View File

@ -0,0 +1,264 @@
<?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);
}
}

View File

@ -1,25 +0,0 @@
<?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;
}
}

View File

@ -1,17 +0,0 @@
<?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);
}
}

View File

@ -1,33 +0,0 @@
<?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);
}
}

View File

@ -31,9 +31,6 @@ class Member extends Data
#[MapInputName('beitragsartId')]
public ?int $feeId,
#[MapInputName('beitragsart')]
public ?string $feeName,
#[MapInputName('eintrittsdatum')]
#[WithCast(CarbonCast::class, format: 'Y-m-d H:i:s')]
#[WithTransformer(CarbonTransformer::class, format: 'Y-m-d H:i:s')]
@ -155,7 +152,6 @@ class Member extends Data
'staatsangehoerigkeitText' => $this->otherCountry,
'nameZusatz' => $this->furtherAddress,
'version' => $this->version,
'eintrittsdatum' => $this->joinedAt->format('Y-m-d 00:00:00'),
];
}
@ -177,10 +173,6 @@ class Member extends Data
return false;
}
if (data_get($rawData, 'geburtsDatum') && Carbon::parse(data_get($rawData, 'geburtsDatum'))->diffInYears(now()) > 100) {
return false;
}
return true;
}
}

View File

@ -49,9 +49,4 @@ class Membership extends Data
'untergliederungId' => $this->subactivityId,
];
}
public function group(): Group {
return Group::from(['name' => $this->group ?: '', 'id' => $this->groupId]);
}
}

View File

@ -1,8 +0,0 @@
<?php
namespace Zoomyboy\LaravelNami\Data;
class Subactivity extends EnumData
{
}

View File

@ -16,9 +16,6 @@ abstract class Fake
]));
}
/**
* @param Collection<int, mixed> $collection
*/
public function collection(Collection $collection): PromiseInterface
{
return Http::response(json_encode([

View File

@ -17,9 +17,6 @@ class MemberFake extends Fake
});
}
/**
* @param array<string, mixed> $data
*/
public function shows(int $groupId, int $memberId, array $data = []): self
{
Http::fake(function ($request) use ($groupId, $memberId, $data) {

View File

@ -183,23 +183,23 @@ class MembershipFake extends Fake
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}";
Http::assertSent(function ($request) use ($url, $payload) {
if ($request->url() !== $url || 'POST' !== $request->method()) {
return false;
}
$requestBody = json_decode($request->body(), true);
foreach ($payload as $key => $value) {
if (!array_key_exists($key, $requestBody)) {
if (
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 ($requestBody[$key] !== $value) {
if (data_get($request, 'aktivVon') && $request['aktivVon'] !== data_get($payload, 'aktivVon')) {
return false;
}
}
return true;
});

62
src/Group.php Normal file
View File

@ -0,0 +1,62 @@
<?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);
}
}

35
src/Subactivity.php Normal file
View File

@ -0,0 +1,35 @@
<?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();
}
}

View File

@ -12,8 +12,6 @@ class Paginator
* @param callable(int): Response $responseFactory
* @param callable(Response): Generator $generator
* @param callable(Response): int $totalFetcher
*
* @return LazyCollection<int, mixed>
*/
public function result(callable $responseFactory, callable $generator, callable $totalFetcher): LazyCollection
{
@ -29,8 +27,6 @@ class Paginator
* @param callable(int, int): Response $responseFactory
* @param callable(Response): Generator $generator
* @param callable(Response): int $totalFetcher
*
* @return LazyCollection<int, mixed>
*/
public function startResult(int $perPage, callable $responseFactory, callable $generator, callable $totalFetcher): LazyCollection
{

View File

@ -48,6 +48,7 @@ class TestCase extends \Orchestra\Testbench\TestCase
public function loginWithWrongCredentials(): Api
{
Auth::fake();
Auth::fails(12345, 'wrong');
return Nami::login(12345, 'wrong');
}

View File

@ -1,6 +1,6 @@
<?php
namespace Zoomyboy\LaravelNami\Tests\Unit\Api;
namespace Zoomyboy\LaravelNami\Tests\Unit\Member;
use Zoomyboy\LaravelNami\Exceptions\MemberDataCorruptedException;
use Zoomyboy\LaravelNami\Exceptions\NotSuccessfulException;
@ -12,7 +12,6 @@ class FetchMemberTest extends TestCase
public function testGetASingleMember(): void
{
app(MemberFake::class)->shows(1000, 1001, [
'beitragsart' => 'Ba',
'beitragsartId' => 1,
'eintrittsdatum' => '2005-05-01 00:00:00',
'email' => 'pille@stamm-silva.de',
@ -46,7 +45,6 @@ class FetchMemberTest extends TestCase
$member = $this->login()->member(1000, 1001);
$this->assertSame(1, $member->feeId);
$this->assertSame('Ba', $member->feeName);
$this->assertSame('2005-05-01 00:00:00', $member->joinedAt->toDateTimeString());
$this->assertSame(1000, $member->groupId);
$this->assertSame(1001, $member->id);

View File

@ -35,8 +35,7 @@ class MembershipTest extends TestCase
$this->assertSame(1000, $membership->groupId);
$this->assertSame(15, $membership->activityId);
$this->assertSame(16, $membership->subactivityId);
$this->assertSame('::group::', $membership->group()->name);
$this->assertSame(1000, $membership->group()->id);
$this->assertSame('::group::', $membership->group);
}
public function testFetchesMembership(): void
@ -96,7 +95,7 @@ class MembershipTest extends TestCase
'taetigkeitId' => 2,
'untergliederungId' => 3,
'aktivVon' => '2022-02-03T00:00:00',
'aktivBis' => null,
'aktivBis' => '',
'gruppierungId' => 1400,
]);
}

View File

@ -70,7 +70,6 @@ class PutMemberTest extends TestCase
'staatsangehoerigkeitText' => 'Land',
'nameZusatz' => 'Name',
'version' => 40,
'eintrittsdatum' => '2021-02-02 00:00:00',
]);
}

View File

@ -3,7 +3,7 @@
namespace Zoomyboy\LaravelNami\Tests\Unit;
use Illuminate\Support\Facades\Http;
use Zoomyboy\LaravelNami\Data\Group;
use Zoomyboy\LaravelNami\Group;
use Zoomyboy\LaravelNami\Tests\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),
]);
$group = $this->login()->groups()->first();
$groups = $this->login()->groups();
$this->assertSame(100, $group->id);
$this->assertSame('Group', $group->name);
$this->assertNull($group->parentId);
$this->assertEquals([
['id' => 100, 'name' => 'Group', 'parent_id' => null],
], $groups->toArray());
Http::assertSent(function ($request) {
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),
]);
$subgroups = $this->login()->group(100)->children();
$subgroups = $this->login()->group(100)->subgroups();
$this->assertEquals([
['id' => 101300, 'parentId' => 100, 'name' => 'Siebengebirge'],
['id' => 100900, 'parentId' => 100, 'name' => 'Sieg'],
['id' => 100900, 'parentId' => 100, 'name' => 'Sieg'],
['id' => 101000, 'parentId' => 100, 'name' => 'Voreifel'],
['id' => 101300, 'parent_id' => 100, 'name' => 'Siebengebirge'],
['id' => 100900, 'parent_id' => 100, 'name' => 'Sieg'],
['id' => 100900, 'parent_id' => 100, 'name' => 'Sieg'],
['id' => 101000, 'parent_id' => 100, 'name' => 'Voreifel'],
], $subgroups->toArray());
$subgroups->each(function ($group) {
$this->assertInstanceOf(Group::class, $group);

View File

@ -7,7 +7,7 @@ use Zoomyboy\LaravelNami\Exceptions\NoJsonReceivedException;
use Zoomyboy\LaravelNami\Exceptions\NotAuthenticatedException;
use Zoomyboy\LaravelNami\Exceptions\NotSuccessfulException;
use Zoomyboy\LaravelNami\Fakes\GroupFake;
use Zoomyboy\LaravelNami\Data\Group;
use Zoomyboy\LaravelNami\Group;
use Zoomyboy\LaravelNami\Nami;
use Zoomyboy\LaravelNami\Tests\TestCase;
@ -32,7 +32,6 @@ class GroupsTest extends TestCase
$this->assertInstanceOf(Group::class, $group);
$this->assertEquals('testgroup', $group->name);
$this->assertEquals(1234, $group->id);
$this->assertNull($group->parentId);
app(GroupFake::class)->assertRootFetched();
}
@ -46,11 +45,10 @@ class GroupsTest extends TestCase
555 => ['name' => 'ABC'],
]);
$group = Nami::login(12345, 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null]))->first();
$group = Nami::login(12345, 'secret')->groups(1234)->first();
$this->assertEquals('ABC', $group->name);
$this->assertEquals(555, $group->id);
$this->assertEquals(1234, $group->parentId);
app(GroupFake::class)->assertFetched(1234);
}
@ -79,7 +77,7 @@ class GroupsTest extends TestCase
]);
app(GroupFake::class)->failsToFetch(1234);
Nami::login(12345, 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null]));
Nami::login(12345, 'secret')->groups(1234);
}
public function testItDoesntReturnGroupWhenNoJsonIsReturned(): void

View File

@ -3,7 +3,6 @@
namespace Zoomyboy\LaravelNami\Tests\Unit;
use Illuminate\Support\Facades\Http;
use Zoomyboy\LaravelNami\Data\Activity;
use Zoomyboy\LaravelNami\Exceptions\NoJsonReceivedException;
use Zoomyboy\LaravelNami\Exceptions\NotSuccessfulException;
use Zoomyboy\LaravelNami\Fakes\SubactivityFake;
@ -23,8 +22,8 @@ class PullActivitiesTest extends TestCase
$activities = $this->login()->group(103)->activities();
$this->assertSame([
['id' => 4, 'name' => 'Ac1'],
['id' => 3, 'name' => 'Ac2'],
['name' => 'Ac1', 'id' => 4],
['name' => 'Ac2', 'id' => 3],
], $activities->toArray());
Http::assertSentCount(2);
}
@ -40,8 +39,8 @@ class PullActivitiesTest extends TestCase
$subactivities = $this->login()->group(103)->activities()->first()->subactivities();
$this->assertSame([
['id' => 40, 'name' => 'Biber'],
['id' => 30, 'name' => 'Wölfling'],
['name' => 'Biber', 'id' => 40],
['name' => 'Wölfling', 'id' => 30],
], $subactivities->toArray());
Http::assertSentCount(3);
}
@ -51,7 +50,7 @@ class PullActivitiesTest extends TestCase
$this->expectException(NotSuccessfulException::class);
app(SubactivityFake::class)->fetchFails(4, 'sorry dude');
$this->login()->subactivitiesOf(Activity::from(['id' => 4]));
$subactivities = $this->login()->subactivitiesOf(4);
}
public function testContinueIfSubactivitiesRequestReturnsHtml(): void
@ -59,6 +58,6 @@ class PullActivitiesTest extends TestCase
$this->expectException(NoJsonReceivedException::class);
app(SubactivityFake::class)->fetchFailsWithoutJson(4);
$this->login()->subactivitiesOf(Activity::from(['id' => 4]));
$this->login()->subactivitiesOf(4);
}
}