laravel-nami-api/tests/Unit/PullActivitiesTest.php

71 lines
2.8 KiB
PHP
Raw Normal View History

2020-07-04 21:23:10 +02:00
<?php
namespace Zoomyboy\LaravelNami\Tests\Unit;
use Illuminate\Support\Facades\Config;
2022-02-18 18:29:02 +01:00
use Illuminate\Support\Facades\Http;
2022-02-19 22:00:50 +01:00
use Zoomyboy\LaravelNami\Fakes\SubactivityFake;
2020-07-04 21:23:10 +02:00
use Zoomyboy\LaravelNami\Group;
2022-02-18 18:29:02 +01:00
use Zoomyboy\LaravelNami\LoginException;
use Zoomyboy\LaravelNami\Nami;
2022-02-19 22:00:50 +01:00
use Zoomyboy\LaravelNami\NamiException;
2022-02-18 18:29:02 +01:00
use Zoomyboy\LaravelNami\NamiServiceProvider;
use Zoomyboy\LaravelNami\Tests\TestCase;
2020-07-04 21:23:10 +02:00
class PullActivitiesTest extends TestCase
{
2022-02-18 18:29:02 +01:00
public string $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":103}],"responseType":"OK"}';
2020-07-04 21:23:10 +02:00
2022-02-18 18:29:02 +01:00
public function test_get_all_activities(): void
{
Http::fake([
2020-07-04 21:23:10 +02:00
'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/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/103' => Http::response($this->fakeJson('activities.json'), 200)
2022-02-18 18:29:02 +01:00
]);
2020-07-04 21:23:10 +02:00
2022-02-18 18:29:02 +01:00
$activities = $this->login()->group(103)->activities();
2020-07-04 21:23:10 +02:00
$this->assertSame([
[ 'name' => 'Ac1', 'id' => 4 ],
[ 'name' => 'Ac2', 'id' => 3 ]
2022-02-18 18:29:02 +01:00
], $activities->toArray());
Http::assertSentCount(2);
2020-07-04 21:23:10 +02:00
}
2022-02-18 18:29:02 +01:00
public function test_get_all_subactivities(): void
{
Http::fake([
2020-07-04 21:23:10 +02:00
'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/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/103' => Http::response($this->fakeJson('activities.json'), 200),
'https://nami.dpsg.de/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/4' => Http::response($this->fakeJson('subactivities-4.json'), 200)
2022-02-18 18:29:02 +01:00
]);
2020-07-04 21:23:10 +02:00
2022-02-18 18:29:02 +01:00
$subactivities = $this->login()->group(103)->activities()->first()->subactivities();
2020-07-04 21:23:10 +02:00
$this->assertSame([
[ 'name' => 'Biber', 'id' => 40 ],
[ 'name' => 'Wölfling', 'id' => 30 ]
2022-02-18 18:29:02 +01:00
], $subactivities->toArray());
Http::assertSentCount(3);
2020-07-04 21:23:10 +02:00
}
2022-02-19 22:00:50 +01:00
public function test_throw_error_when_subactivities_request_fails(): void
{
$this->expectException(NamiException::class);
app(SubactivityFake::class)->fetchFailed(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);
$this->assertSame([
[ 'name' => 'Biber', 'id' => 40 ],
[ 'name' => 'Wölfling', 'id' => 30 ]
], $subactivities->toArray());
Http::assertSentCount(3);
}
2020-07-04 21:23:10 +02:00
}