Fixed tests

This commit is contained in:
philipp lang 2022-02-19 18:05:52 +01:00
parent d6167f1b7f
commit 63cef42385
5 changed files with 30 additions and 21 deletions

View File

@ -35,6 +35,7 @@ class Api {
public function findNr(int $nr): Member public function findNr(int $nr): Member
{ {
$this->assertLoggedIn();
return $this->find(['mitgliedsNummber' => $nr]); return $this->find(['mitgliedsNummber' => $nr]);
} }
@ -43,6 +44,7 @@ class Api {
*/ */
public function find(array $payload): ?Member public function find(array $payload): ?Member
{ {
$this->assertLoggedIn();
return $this->search($payload)->first(); return $this->search($payload)->first();
} }
@ -52,6 +54,7 @@ class Api {
*/ */
public function search(array $payload): LazyCollection public function search(array $payload): LazyCollection
{ {
$this->assertLoggedIn();
return LazyCollection::make(function() use ($payload) { return LazyCollection::make(function() use ($payload) {
$page = 1; $page = 1;
while (!isset ($totalEntries) || ($page-1) * 100 + 1 <= $totalEntries) { while (!isset ($totalEntries) || ($page-1) * 100 + 1 <= $totalEntries) {
@ -73,6 +76,7 @@ class Api {
} }
public function deleteMember($id) { public function deleteMember($id) {
$this->assertLoggedIn();
$url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/mglschaft-beenden'; $url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/mglschaft-beenden';
$payload = [ $payload = [
'id' => $id, 'id' => $id,
@ -99,10 +103,12 @@ class Api {
} }
public function membersOf($groupId): Collection { public function membersOf($groupId): Collection {
$this->assertLoggedIn();
return collect($this->http()->get($this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist')->json()['data']); return collect($this->http()->get($this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist')->json()['data']);
} }
public function putMember(array $attributes) { public function putMember(array $attributes) {
$this->assertLoggedIn();
$member = Member::fromAttributes($attributes); $member = Member::fromAttributes($attributes);
$existing = $this->member($member->group_id, $member->id); $existing = $this->member($member->group_id, $member->id);
if (data_get($attributes, 'id')) { if (data_get($attributes, 'id')) {
@ -129,6 +135,7 @@ class Api {
public function putMembership(int $memberId, array $data): int public function putMembership(int $memberId, array $data): int
{ {
$this->assertLoggedIn();
if (data_get($data, 'id')) { if (data_get($data, 'id')) {
$url = $this->url."/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}/{$data['id']}"; $url = $this->url."/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}/{$data['id']}";
$response = $this->http()->put($url, $data); $response = $this->http()->put($url, $data);
@ -148,6 +155,7 @@ class Api {
} }
public function membershipsOf($memberId): Collection { public function membershipsOf($memberId): Collection {
$this->assertLoggedIn();
$url = $this->url.'/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'.$memberId.'/flist'; $url = $this->url.'/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'.$memberId.'/flist';
$r = $this->http()->get($url); $r = $this->http()->get($url);
@ -162,12 +170,14 @@ class Api {
} }
public function subactivitiesOf($activityId) { public function subactivitiesOf($activityId) {
$this->assertLoggedIn();
return collect($this->http()->get($this->url.'/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activityId)->json()['data'])->map(function($subactivity) { return collect($this->http()->get($this->url.'/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activityId)->json()['data'])->map(function($subactivity) {
return Subactivity::fromNami($subactivity); return Subactivity::fromNami($subactivity);
});; });;
} }
public function membership($memberId, $membershipId) { public function membership($memberId, $membershipId) {
$this->assertLoggedIn();
$url = $this->url.'/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'.$memberId.'/'.$membershipId; $url = $this->url.'/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'.$memberId.'/'.$membershipId;
$response = $this->http()->get($url); $response = $this->http()->get($url);
@ -182,6 +192,7 @@ class Api {
public function courses(): Collection public function courses(): Collection
{ {
$this->assertLoggedIn();
$url = $this->url.'/ica/rest/module/baustein'; $url = $this->url.'/ica/rest/module/baustein';
$response = $this->http()->get($url); $response = $this->http()->get($url);
@ -243,6 +254,7 @@ class Api {
*/ */
public function updateCourse(int $memberId, int $courseId, array $payload): void public function updateCourse(int $memberId, int $courseId, array $payload): void
{ {
$this->assertLoggedIn();
$response = $this->http()->put($this->url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}", [ $response = $this->http()->put($this->url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}", [
'bausteinId' => $payload['course_id'], 'bausteinId' => $payload['course_id'],
'vstgName' => $payload['event_name'], 'vstgName' => $payload['event_name'],
@ -257,6 +269,7 @@ class Api {
public function deleteCourse(int $memberId, int $courseId): void public function deleteCourse(int $memberId, int $courseId): void
{ {
$this->assertLoggedIn();
$response = $this->http()->delete($this->url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}"); $response = $this->http()->delete($this->url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}");
if ($response->json() !== null && data_get($response->json(), 'success') !== true) { if ($response->json() !== null && data_get($response->json(), 'success') !== true) {
@ -265,6 +278,7 @@ class Api {
} }
public function member($groupId, $memberId) { public function member($groupId, $memberId) {
$this->assertLoggedIn();
$url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId; $url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId;
$response = $this->http()->get($url); $response = $this->http()->get($url);
@ -291,28 +305,33 @@ class Api {
} }
public function hasGroup($groupId): bool { public function hasGroup($groupId): bool {
$this->assertLoggedIn();
return $this->groups()->search(function($group) use ($groupId) { return $this->groups()->search(function($group) use ($groupId) {
return $group->id == $groupId; return $group->id == $groupId;
}) !== false; }) !== false;
} }
public function groups($parentGroupId = null): Collection { public function groups($parentGroupId = null): Collection {
$this->assertLoggedIn();
return collect($this->http()->get($this->url.'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/'.($parentGroupId ?: 'root'))->json()['data'])->map(function($group) use ($parentGroupId) { return collect($this->http()->get($this->url.'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/'.($parentGroupId ?: 'root'))->json()['data'])->map(function($group) use ($parentGroupId) {
return Group::fromResponse($group, $parentGroupId); return Group::fromResponse($group, $parentGroupId);
}); });
} }
public function group($groupId): Group { public function group($groupId): Group {
$this->assertLoggedIn();
return $this->groups()->first(function($group) use ($groupId) { return $this->groups()->first(function($group) use ($groupId) {
return $group->id == $groupId; return $group->id == $groupId;
}); });
} }
public function subgroupsOf($groupId) { public function subgroupsOf($groupId) {
$this->assertLoggedIn();
return $this->groups($groupId); return $this->groups($groupId);
} }
public function genders(): Collection { public function genders(): Collection {
$this->assertLoggedIn();
return collect($this->http()->get($this->url."/ica/rest/baseadmin/geschlecht")['data'])->map(function($gender) { return collect($this->http()->get($this->url."/ica/rest/baseadmin/geschlecht")['data'])->map(function($gender) {
return Gender::fromNami($gender); return Gender::fromNami($gender);
})->filter(fn($gender) => !$gender->isNull); })->filter(fn($gender) => !$gender->isNull);
@ -326,12 +345,14 @@ class Api {
} }
public function countries() { public function countries() {
$this->assertLoggedIn();
return collect($this->http()->get($this->url."/ica/rest/baseadmin/land")['data'])->map(function($country) { return collect($this->http()->get($this->url."/ica/rest/baseadmin/land")['data'])->map(function($country) {
return Country::fromNami($country); return Country::fromNami($country);
}); });
} }
public function regions() { public function regions() {
$this->assertLoggedIn();
return collect($this->http()->get($this->url."/ica/rest/baseadmin/region")['data'])->map(function($region) { return collect($this->http()->get($this->url."/ica/rest/baseadmin/region")['data'])->map(function($region) {
return Region::fromNami($region); return Region::fromNami($region);
}); });
@ -339,18 +360,21 @@ class Api {
public function feesOf($groupid) { public function feesOf($groupid) {
$this->assertLoggedIn();
return collect($this->http()->get($this->url."/ica/rest/namiBeitrag/beitragsartmgl/gruppierung/{$groupid}")['data'])->map(function($fee) { return collect($this->http()->get($this->url."/ica/rest/namiBeitrag/beitragsartmgl/gruppierung/{$groupid}")['data'])->map(function($fee) {
return Fee::fromNami($fee); return Fee::fromNami($fee);
}); });
} }
public function confessions(): Collection { public function confessions(): Collection {
$this->assertLoggedIn();
return collect($this->http()->get($this->url."/ica/rest/baseadmin/konfession")['data'])->map(function($gender) { return collect($this->http()->get($this->url."/ica/rest/baseadmin/konfession")['data'])->map(function($gender) {
return Confession::fromNami($gender); return Confession::fromNami($gender);
}); });
} }
public function activities($groupId) { public function activities($groupId) {
$this->assertLoggedIn();
return collect($this->http()->get($this->url."/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/".$groupId)['data'])->map(function($activity) { return collect($this->http()->get($this->url."/ica/rest/nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/".$groupId)['data'])->map(function($activity) {
return Activity::fromNami($activity); return Activity::fromNami($activity);
}); });
@ -358,6 +382,7 @@ class Api {
public function memberOverviewOf(int $groupId): Collection public function memberOverviewOf(int $groupId): Collection
{ {
$this->assertLoggedIn();
$url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist'; $url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist';
$response = $this->http()->get($url); $response = $this->http()->get($url);
@ -372,6 +397,7 @@ class Api {
} }
private function singleMemberFallback($groupId, $memberId) { private function singleMemberFallback($groupId, $memberId) {
$this->assertLoggedIn();
$url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist'; $url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist';
$response = $this->http()->get($url); $response = $this->http()->get($url);

View File

@ -36,27 +36,6 @@ class FakeBackend {
return $this; return $this;
} }
/**
* @param array $data
*/
public function fakeGroups(array $data): self
{
Http::fake(function($request) use ($data) {
if ($request->url() === 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root') {
$data = collect($data)->mapWithKeys(fn ($group, $id) =>
$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 * @param array<int, array{name: string, id: int}> $data
*/ */

View File

@ -42,6 +42,7 @@ class PullMembershipsTest extends TestCase
'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16/68' => Http::response($this->fakeJson('membership-68.json'), 200), 'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16/68' => Http::response($this->fakeJson('membership-68.json'), 200),
'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16/69' => Http::response($this->fakeJson('membership-69.json'), 200) 'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16/69' => Http::response($this->fakeJson('membership-69.json'), 200)
]); ]);
$this->login();
$member = new Member(['id' => 16]); $member = new Member(['id' => 16]);
@ -62,6 +63,7 @@ class PullMembershipsTest extends TestCase
Http::fake([ Http::fake([
'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16/flist' => Http::response($error, 200) 'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16/flist' => Http::response($error, 200)
]); ]);
$this->login();
$member = new Member(['id' => 16]); $member = new Member(['id' => 16]);

View File

@ -53,6 +53,7 @@ class PushMemberTest extends TestCase
Http::fake([ Http::fake([
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response('{"success": true, "data": {"id": 16}}', 200), 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response('{"success": true, "data": {"id": 16}}', 200),
]); ]);
$this->login();
$res = Nami::putMember(array_merge($this->attributes[0], $overwrites)); $res = Nami::putMember(array_merge($this->attributes[0], $overwrites));
$this->assertEquals(16, $res['id']); $this->assertEquals(16, $res['id']);

View File

@ -18,6 +18,7 @@ class PushMembershipsTest extends TestCase
'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16/flist' => Http::response($this->fakeJson('membership-overview.json'), 200), 'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16/flist' => Http::response($this->fakeJson('membership-overview.json'), 200),
'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16' => Http::response($this->fakeJson('membership-create.json'), 200), 'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16' => Http::response($this->fakeJson('membership-create.json'), 200),
]); ]);
$this->login();
$member = new Member(['id' => 16]); $member = new Member(['id' => 16]);
$id = $member->putMembership([ $id = $member->putMembership([