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

74 lines
2.7 KiB
PHP
Raw Normal View History

2020-07-04 20:47:30 +02:00
<?php
namespace Zoomyboy\LaravelNami\Tests\Unit;
use Illuminate\Support\Facades\Http;
use Zoomyboy\LaravelNami\Member;
2022-01-02 21:49:57 +01:00
use Zoomyboy\LaravelNami\Nami;
use Zoomyboy\LaravelNami\Tests\TestCase;
2020-07-04 20:47:30 +02:00
class PullMembershipsTest extends TestCase
{
2022-02-18 18:29:02 +01:00
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"}']
];
}
2020-07-04 20:47:30 +02:00
2022-02-18 18:29:02 +01:00
public function dataProvider(): array
{
2020-07-04 20:47:30 +02:00
return [
'id' => ['id', [68, 69]],
'group_id' => ['group_id', [103,104]],
'activity_id' => ['activity_id', [33, 34]],
'subactivity_id' => ['subactivity_id', [55, null]],
2020-07-04 20:47:30 +02:00
'starts_at' => ['starts_at', ['2017-02-11', '2017-11-12']],
2020-07-04 23:31:03 +02:00
'ends_at' => ['ends_at', ['2017-03-11', null]],
'activity_name' => ['activity_name', ['ReferentIn', 'Wö']],
'subactivity_name' => ['subactivity_name', ['Pfadfinder', null]],
2020-07-04 20:47:30 +02:00
];
}
/**
* @dataProvider dataProvider
*/
2022-02-18 18:29:02 +01:00
public function test_get_all_memberships_of_a_member(string $key, array $values): void
{
Http::fake([
2020-07-04 20:47:30 +02:00
'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)
2022-02-18 18:29:02 +01:00
]);
2020-07-04 20:47:30 +02:00
$member = new Member(['id' => 16]);
$memberships = $member->memberships();
foreach ($memberships as $i => $m) {
$this->assertSame($values[$i], $m->toArray()[$key]);
}
2022-02-18 18:29:02 +01:00
Http::assertSentCount(3);
2020-07-04 20:47:30 +02:00
}
/**
* @dataProvider errorProvider
*/
2022-02-18 18:29:02 +01:00
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)
2022-02-18 18:29:02 +01:00
]);
$member = new Member(['id' => 16]);
$memberships = $member->memberships();
$this->assertSame([], $member->memberships()->toArray());
2022-02-18 18:29:02 +01:00
Http::assertSentCount(2);
}
2020-07-04 20:47:30 +02:00
}