Add membership test
This commit is contained in:
parent
534ce18491
commit
85167fef88
|
@ -53,4 +53,16 @@ class MembershipFake extends Fake {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function failsToShow(int $memberId, int $membershipId, string $error): self
|
||||
{
|
||||
Http::fake(function($request) use ($memberId, $membershipId, $error) {
|
||||
$url = 'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'.$memberId.'/'.$membershipId;
|
||||
if ($request->url() === $url && $request->method() === 'GET') {
|
||||
return $this->errorResponse($error);
|
||||
}
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Exceptions\RightException;
|
||||
use Zoomyboy\LaravelNami\Fakes\MembershipFake;
|
||||
use Zoomyboy\LaravelNami\Member;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
class MembershipTest extends TestCase
|
||||
{
|
||||
|
||||
public function test_get_all_memberships_of_a_member(): void
|
||||
{
|
||||
$data = [
|
||||
"id" => 68,
|
||||
"gruppierung" => "Diözesanleitung Köln 100000",
|
||||
"gruppierungId" => 103,
|
||||
"taetigkeit" => "ReferentIn",
|
||||
"taetigkeitId" => 33,
|
||||
"untergliederung" => "Pfadfinder",
|
||||
"untergliederungId" => 55,
|
||||
"aktivVon" => "2017-02-11 00:00:00",
|
||||
"aktivBis" => "2017-03-11 00:00:00"
|
||||
];
|
||||
app(MembershipFake::class)->shows(16, $data);
|
||||
|
||||
$this->assertSame($data, $this->login()->membership(16, 68));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testWith ["Sicherheitsverletzung: Zugriff auf Rechte Recht (n:2001002 o:2) fehlgeschlagen", "Access denied - no right for requested operation"]
|
||||
*/
|
||||
public function test_it_gets_no_memberships_with_no_rights(string $error): void
|
||||
{
|
||||
$this->expectException(RightException::class);
|
||||
app(MembershipFake::class)->failsToShow(16, 68, $error);
|
||||
|
||||
$this->login()->membership(16, 68);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Member;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
class PullMembershipsTest extends TestCase
|
||||
{
|
||||
|
||||
public function errorProvider(): array
|
||||
{
|
||||
return [
|
||||
'unauth' => ['{"success":false,"data":null,"responseType":"EXCEPTION","message":"Access denied - no right for requested operation","title":"Exception"}'],
|
||||
'noright' => ['{"success":false,"responseType":"EXCEPTION","message":"Sicherheitsverletzung: Zugriff auf Rechte Recht (n:2001002 o:2) fehlgeschlagen"}']
|
||||
];
|
||||
}
|
||||
|
||||
public function dataProvider(): array
|
||||
{
|
||||
return [
|
||||
'id' => ['id', [68, 69]],
|
||||
'group_id' => ['group_id', [103,104]],
|
||||
'activity_id' => ['activity_id', [33, 34]],
|
||||
'subactivity_id' => ['subactivity_id', [55, null]],
|
||||
'starts_at' => ['starts_at', ['2017-02-11', '2017-11-12']],
|
||||
'ends_at' => ['ends_at', ['2017-03-11', null]],
|
||||
'activity_name' => ['activity_name', ['ReferentIn', 'Wö']],
|
||||
'subactivity_name' => ['subactivity_name', ['Pfadfinder', null]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function test_get_all_memberships_of_a_member(string $key, array $values): void
|
||||
{
|
||||
Http::fake([
|
||||
'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/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)
|
||||
]);
|
||||
$this->login();
|
||||
|
||||
$member = new Member(['id' => 16]);
|
||||
|
||||
$memberships = $member->memberships();
|
||||
|
||||
foreach ($memberships as $i => $m) {
|
||||
$this->assertSame($values[$i], $m->toArray()[$key]);
|
||||
}
|
||||
|
||||
Http::assertSentCount(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider errorProvider
|
||||
*/
|
||||
public function test_it_gets_no_memberships_with_no_rights(string $error): void
|
||||
{
|
||||
Http::fake([
|
||||
'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]);
|
||||
|
||||
$memberships = $member->memberships();
|
||||
$this->assertSame([], $member->memberships()->toArray());
|
||||
|
||||
Http::assertSentCount(2);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue