Fixed: Dont abort when subactivities return html

This commit is contained in:
philipp lang 2022-02-19 23:08:29 +01:00
parent 423fb27f51
commit 899264db51
4 changed files with 27 additions and 9 deletions

View File

@ -174,7 +174,11 @@ class Api {
$url = $this->url.'/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activityId;
$response = $this->http()->get($url);
if ($response['success'] === false) {
if ($response->json() === null) {
return collect([]);
}
if (data_get($response, 'success') === false) {
$this->exception('Getting subactivities failed', $url, $response->json());
}

View File

@ -15,4 +15,9 @@ abstract class Fake {
]));
}
public function htmlResponse(): PromiseInterface
{
return Http::response('<html></html>');
}
}

View File

@ -16,4 +16,13 @@ class SubactivityFake extends Fake {
});
}
public function fetchFailsWithoutJson(int $activityId): void
{
Http::fake(function($request) use ($activityId) {
if ($request->url() === 'https://nami.dpsg.de/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activityId) {
return $this->htmlResponse();
}
});
}
}

View File

@ -54,17 +54,17 @@ class PullActivitiesTest extends TestCase
{
$this->expectException(NamiException::class);
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)
]);
$subactivities = $this->login()->subactivitiesOf(4);
}
public function test_continue_if_subactivities_request_returns_html(): void
{
app(SubactivityFake::class)->fetchFailsWithoutJson(4);
$subactivities = $this->login()->subactivitiesOf(4);
$this->assertSame([
[ 'name' => 'Biber', 'id' => 40 ],
[ 'name' => 'Wölfling', 'id' => 30 ]
], $subactivities->toArray());
Http::assertSentCount(3);
$this->assertCount(0, $subactivities);
}
}