Add error handling for failed member fetch
This commit is contained in:
parent
96269d16c7
commit
3916d72837
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami\Fakes;
|
||||
|
||||
use Illuminate\Http\Client\Response;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class MemberFake extends Fake {
|
||||
|
||||
public function fetchFails(int $groupId, int $memberId, string $error = 'wrong message'): void
|
||||
{
|
||||
Http::fake(function($request) use ($groupId, $memberId, $error) {
|
||||
$url = 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId;
|
||||
if ($request->url() === $url && $request->method() === 'GET') {
|
||||
return $this->errorResponse($error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Http;
|
|||
|
||||
class SubactivityFake extends Fake {
|
||||
|
||||
public function fetchFailed(int $activityId, ?string $error = 'wrong message'): void
|
||||
public function fetchFails(int $activityId, ?string $error = 'wrong message'): void
|
||||
{
|
||||
Http::fake(function($request) use ($activityId, $error) {
|
||||
if ($request->url() === 'https://nami.dpsg.de/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activityId) {
|
||||
|
|
|
@ -53,7 +53,7 @@ class PullActivitiesTest extends TestCase
|
|||
public function test_throw_error_when_subactivities_request_fails(): void
|
||||
{
|
||||
$this->expectException(NamiException::class);
|
||||
app(SubactivityFake::class)->fetchFailed(4, 'sorry dude');
|
||||
app(SubactivityFake::class)->fetchFails(4, 'sorry dude');
|
||||
Http::fake([
|
||||
'https://nami.dpsg.de/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/4' => Http::response($this->fakeJson('subactivities-4.json'), 200)
|
||||
]);
|
||||
|
|
|
@ -4,9 +4,11 @@ namespace Zoomyboy\LaravelNami\Tests\Unit;
|
|||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Fakes\MemberFake;
|
||||
use Zoomyboy\LaravelNami\Group;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\NamiException;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
|
@ -177,4 +179,12 @@ class PullMemberTest extends TestCase
|
|||
Http::assertSentCount(3);
|
||||
}
|
||||
|
||||
public function test_member_fetch_can_fail(): void
|
||||
{
|
||||
$this->expectException(NamiException::class);
|
||||
app(MemberFake::class)->fetchFails(103, 16);
|
||||
|
||||
$this->login()->member(103, 16);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue