Fixed tests
This commit is contained in:
parent
b78b0a5b21
commit
54826f0f73
|
@ -85,16 +85,14 @@ class Api {
|
|||
}
|
||||
}
|
||||
|
||||
public function login($mglnr = null, $password = null): self {
|
||||
public function login(int $mglnr, string $password): self
|
||||
{
|
||||
if ($this->cookie->isLoggedIn()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->cookie->beforeLogin();
|
||||
|
||||
$mglnr = $mglnr ?: config('nami.auth.mglnr');
|
||||
$password = $password ?: config('nami.auth.password');
|
||||
|
||||
$this->http()->get($this->url.'/ica/pages/login.jsp');
|
||||
$response = $this->http()->asForm()->post($this->url.'/ica/rest/nami/auth/manual/sessionStartup', [
|
||||
'Login' => 'API',
|
||||
|
@ -109,7 +107,6 @@ class Api {
|
|||
throw $e;
|
||||
}
|
||||
|
||||
$this->loggedIn = $mglnr;
|
||||
$this->cookie->afterLogin();
|
||||
|
||||
return $this;
|
||||
|
|
|
@ -12,7 +12,7 @@ class Cookie {
|
|||
|
||||
/**
|
||||
* Loads the cookie for a new request
|
||||
*
|
||||
*
|
||||
* @return FileCookieJar
|
||||
*/
|
||||
public function load(): FileCookieJar
|
||||
|
@ -55,7 +55,7 @@ class Cookie {
|
|||
|
||||
private function newFileName(): string
|
||||
{
|
||||
return $this->path.'/'.time().'.txt';
|
||||
return $this->path.'/'.time().'.txt';
|
||||
}
|
||||
|
||||
private function isExpired(): bool
|
||||
|
|
|
@ -4,6 +4,9 @@ namespace Zoomyboy\LaravelNami;
|
|||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @method static \Zoomyboy\LaravelNami\Api login(int $mglnr, string $password)
|
||||
*/
|
||||
class Nami extends Facade {
|
||||
protected static function getFacadeAccessor() { return 'nami.api'; }
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@ namespace Zoomyboy\LaravelNami\Tests;
|
|||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Api;
|
||||
use Zoomyboy\LaravelNami\Cookies\Cookie;
|
||||
use Zoomyboy\LaravelNami\Cookies\FakeCookie;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Providers\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\Tests\Stub\Member;
|
||||
|
||||
|
@ -36,10 +38,11 @@ class TestCase extends \Orchestra\Testbench\TestCase
|
|||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function fakeGenders() {
|
||||
return [
|
||||
'https://nami.dpsg.de/ica/rest/baseadmin/geschlecht' => Http::response($this->fakeJson('genders.json'), 200)
|
||||
];
|
||||
public function login(): Api
|
||||
{
|
||||
touch (__DIR__.'/../.cookies/'.time().'.txt');
|
||||
|
||||
return Nami::login(123, 'secret');
|
||||
}
|
||||
|
||||
private function clearCookies(): void
|
||||
|
|
|
@ -2,72 +2,59 @@
|
|||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Group;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
class GetGroupsTest extends TestCase
|
||||
{
|
||||
|
||||
public $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":100}],"responseType":"OK"}';
|
||||
public $subgroupsResponse = '{ "success": true, "data": [ { "descriptor": "Siebengebirge", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 101300 }, { "descriptor": "Sieg", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100900 }, { "descriptor": "Sieg", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100900 }, { "descriptor": "Voreifel", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 101000 } ], "responseType": "OK" }';
|
||||
public $subsubgroupsResponse = '{ "success": true, "data": [ { "descriptor": "Silva", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100105 } ], "responseType": "OK" }';
|
||||
public string $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":100}],"responseType":"OK"}';
|
||||
public string $subgroupsResponse = '{ "success": true, "data": [ { "descriptor": "Siebengebirge", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 101300 }, { "descriptor": "Sieg", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100900 }, { "descriptor": "Sieg", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100900 }, { "descriptor": "Voreifel", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 101000 } ], "responseType": "OK" }';
|
||||
public string $subsubgroupsResponse = '{ "success": true, "data": [ { "descriptor": "Silva", "name": "", "representedClass": "de.iconcept.nami.entity.org.Gruppierung", "id": 100105 } ], "responseType": "OK" }';
|
||||
|
||||
public function test_get_all_groups()
|
||||
public function test_get_all_groups(): void
|
||||
{
|
||||
Http::fake([
|
||||
'https://nami.dpsg.de/ica/pages/login.jsp' => Http::response('<html></html>', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::response($this->successJson, 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
$groups = $this->login()->groups();
|
||||
|
||||
Nami::login();
|
||||
$this->assertEquals([
|
||||
['id' => 100, 'name' => 'Group', 'parent_id' => null]
|
||||
], Nami::groups()->toArray());
|
||||
|
||||
], $groups->toArray());
|
||||
Http::assertSent(function($request) {
|
||||
return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root';
|
||||
});
|
||||
Http::assertSentCount(3);
|
||||
Http::assertSentCount(1);
|
||||
}
|
||||
|
||||
public function test_has_group_access()
|
||||
public function test_has_group_access(): void
|
||||
{
|
||||
Http::fake([
|
||||
'https://nami.dpsg.de/ica/pages/login.jsp' => Http::response('<html></html>', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::response($this->successJson, 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
||||
]);
|
||||
$api = $this->login();
|
||||
|
||||
$this->setCredentials();
|
||||
$this->assertTrue($api->hasGroup(100));
|
||||
$this->assertFalse($api->hasGroup(10101));
|
||||
|
||||
Nami::login();
|
||||
$this->assertTrue(Nami::hasGroup(100));
|
||||
$this->assertFalse(Nami::hasGroup(10101));
|
||||
|
||||
Http::assertSentCount(4);
|
||||
Http::assertSentCount(2);
|
||||
}
|
||||
|
||||
public function test_get_subgroups_for_a_group() {
|
||||
public function test_get_subgroups_for_a_group(): void
|
||||
{
|
||||
Http::fake([
|
||||
'https://nami.dpsg.de/ica/pages/login.jsp' => Http::response('<html></html>', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::response($this->successJson, 200),
|
||||
'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/gruppierungen/filtered-for-navigation/gruppierung/node/100' => Http::response($this->subgroupsResponse, 200)
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
|
||||
$subgroups = Nami::group(100)->subgroups();
|
||||
$subgroups = $this->login()->group(100)->subgroups();
|
||||
|
||||
$this->assertEquals([
|
||||
['id' => 101300, 'parent_id' => 100, 'name' => 'Siebengebirge'],
|
||||
|
@ -75,18 +62,15 @@ class GetGroupsTest extends TestCase
|
|||
['id' => 100900, 'parent_id' => 100, 'name' => 'Sieg'],
|
||||
['id' => 101000, 'parent_id' => 100, 'name' => 'Voreifel']
|
||||
], $subgroups->toArray());
|
||||
|
||||
$subgroups->each(function($group) {
|
||||
$this->assertInstanceOf(Group::class, $group);
|
||||
});
|
||||
|
||||
Http::assertSent(function($request) {
|
||||
return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root';
|
||||
});
|
||||
Http::assertSent(function($request) {
|
||||
return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/100';
|
||||
});
|
||||
|
||||
Http::assertSentCount(4);
|
||||
Http::assertSentCount(2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ class LoginTest extends TestCase
|
|||
|
||||
public function test_delete_expired_cookie_before_login(): void
|
||||
{
|
||||
$lastLogin = now()->subHour(2)->timestamp;
|
||||
$lastLogin = now()->subHours(2)->timestamp;
|
||||
touch(__DIR__."/../../.cookies/{$lastLogin}.txt");
|
||||
Http::fake($this->fakeSuccessfulLogin());
|
||||
|
||||
|
|
|
@ -2,54 +2,50 @@
|
|||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Group;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
class PullActivitiesTest extends TestCase
|
||||
{
|
||||
|
||||
public $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":103}],"responseType":"OK"}';
|
||||
public string $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":103}],"responseType":"OK"}';
|
||||
|
||||
public function test_get_all_activities() {
|
||||
Http::fake(array_merge($this->login(),[
|
||||
public function test_get_all_activities(): void
|
||||
{
|
||||
Http::fake([
|
||||
'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)
|
||||
]));
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
$activities = $this->login()->group(103)->activities();
|
||||
|
||||
$this->assertSame([
|
||||
[ 'name' => 'Ac1', 'id' => 4 ],
|
||||
[ 'name' => 'Ac2', 'id' => 3 ]
|
||||
], Nami::group(103)->activities()->toArray());
|
||||
|
||||
Http::assertSentCount(4);
|
||||
], $activities->toArray());
|
||||
Http::assertSentCount(2);
|
||||
}
|
||||
|
||||
public function test_get_all_subactivities() {
|
||||
Http::fake(array_merge($this->login(),[
|
||||
public function test_get_all_subactivities(): void
|
||||
{
|
||||
Http::fake([
|
||||
'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)
|
||||
]));
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
$subactivities = $this->login()->group(103)->activities()->first()->subactivities();
|
||||
|
||||
$this->assertSame([
|
||||
[ 'name' => 'Biber', 'id' => 40 ],
|
||||
[ 'name' => 'Wölfling', 'id' => 30 ]
|
||||
], Nami::group(103)->activities()->first()->subactivities()->toArray());
|
||||
|
||||
Http::assertSentCount(5);
|
||||
], $subactivities->toArray());
|
||||
Http::assertSentCount(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,31 +2,30 @@
|
|||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Group;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
class PullConfessionTest extends TestCase
|
||||
{
|
||||
|
||||
public function test_get_all_confessions() {
|
||||
Http::fake(array_merge($this->login(), [
|
||||
public function test_get_all_confessions(): void
|
||||
{
|
||||
Http::fake([
|
||||
'https://nami.dpsg.de/ica/rest/baseadmin/konfession' => Http::response($this->fakeJson('confession.json'), 200)
|
||||
]));
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
$confessions = $this->login()->confessions();
|
||||
|
||||
$this->assertEquals([
|
||||
1 => 'römisch-katholisch'
|
||||
], Nami::confessions()->pluck('name', 'id')->toArray());
|
||||
], $confessions->pluck('name', 'id')->toArray());
|
||||
|
||||
Http::assertSentCount(3);
|
||||
Http::assertSentCount(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,30 +2,31 @@
|
|||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Group;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
class PullGenderTest extends TestCase
|
||||
{
|
||||
|
||||
public function test_get_all_genders() {
|
||||
Http::fake(array_merge($this->login(), $this->fakeGenders()));
|
||||
public function test_get_all_genders(): void
|
||||
{
|
||||
Http::fake([
|
||||
'https://nami.dpsg.de/ica/rest/baseadmin/geschlecht' => Http::response($this->fakeJson('genders.json'), 200)
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
$genders = $this->login()->genders();
|
||||
|
||||
$this->assertEquals([
|
||||
19 => 'Männlich',
|
||||
20 => 'Weiblich'
|
||||
], Nami::genders()->pluck('name', 'id')->toArray());
|
||||
], $genders->pluck('name', 'id')->toArray());
|
||||
|
||||
Http::assertSentCount(3);
|
||||
Http::assertSentCount(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,20 +86,18 @@ class PullMemberTest extends TestCase
|
|||
*/
|
||||
public function test_get_a_single_member(array $input, array $check): void
|
||||
{
|
||||
Http::fake(array_merge($this->login(), [
|
||||
Http::fake([
|
||||
'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/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response($this->fakeJson('member-16.json', ['data' => $input]), 200),
|
||||
]));
|
||||
$this->setCredentials();
|
||||
Nami::login();
|
||||
]);
|
||||
|
||||
$group = Nami::group(103);
|
||||
$group = $this->login()->group(103);
|
||||
|
||||
foreach ($check as $key => $value) {
|
||||
$this->assertSame($value, $group->member(16)->toArray()[$key]);
|
||||
}
|
||||
|
||||
Http::assertSentCount(4);
|
||||
Http::assertSentCount(2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,20 +105,18 @@ class PullMemberTest extends TestCase
|
|||
*/
|
||||
public function test_get_attribute_of_member_collection(array $input, array $check): void
|
||||
{
|
||||
Http::fake(array_merge($this->login(), [
|
||||
Http::fake([
|
||||
'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/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/flist' => Http::response($this->fakeJson('member_overview.json'), 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response($this->fakeJson('member-16.json', ['data' => $input]), 200),
|
||||
]));
|
||||
$this->setCredentials();
|
||||
Nami::login();
|
||||
]);
|
||||
|
||||
$member = Nami::group(103)->members()->first();
|
||||
$member = $this->login()->group(103)->members()->first();
|
||||
|
||||
foreach ($check as $key => $value) {
|
||||
$this->assertSame($value, $member->toArray()[$key]);
|
||||
}
|
||||
Http::assertSentCount(5);
|
||||
Http::assertSentCount(3);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,21 +124,17 @@ class PullMemberTest extends TestCase
|
|||
*/
|
||||
public function test_get_attribute_of_member_overview(string $key, array $values): void
|
||||
{
|
||||
Http::fake(array_merge($this->login(), [
|
||||
Http::fake([
|
||||
'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/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/flist' => Http::response($this->fakeJson('member_overview.json'), 200)
|
||||
]));
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
|
||||
$members = Nami::group(103)->memberOverview();
|
||||
$members = $this->login()->group(103)->memberOverview();
|
||||
foreach ($members as $i => $m) {
|
||||
$this->assertSame($values[$i], $m->toArray()[$key]);
|
||||
}
|
||||
|
||||
Http::assertSentCount(4);
|
||||
Http::assertSentCount(2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -150,23 +142,21 @@ class PullMemberTest extends TestCase
|
|||
*/
|
||||
public function test_set_relations(string $key, array $values): void
|
||||
{
|
||||
Http::fake(array_merge($this->login(), [
|
||||
Http::fake([
|
||||
'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/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/flist' => Http::response($this->fakeJson('member_overview.json'), 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response($this->fakeJson('member-16.json'), 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/17' => Http::response($this->fakeJson('member-17.json'), 200)
|
||||
]));
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
$members = $this->login()->group(103)->members();
|
||||
|
||||
$this->assertSame([
|
||||
16 => $values[0],
|
||||
17 => $values[1]
|
||||
], Nami::group(103)->members()->pluck($key, 'id')->toArray());
|
||||
], $members->pluck($key, 'id')->toArray());
|
||||
|
||||
Http::assertSentCount(6);
|
||||
Http::assertSentCount(4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,21 +164,17 @@ class PullMemberTest extends TestCase
|
|||
*/
|
||||
public function test_get_a_member_from_overview_with_no_rights(string $key, array $values): void
|
||||
{
|
||||
Http::fake(array_merge($this->login(), [
|
||||
Http::fake([
|
||||
'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/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response($this->unauthorizedResponse, 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/flist' => Http::response($this->fakeJson('member_overview.json'), 200)
|
||||
]));
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
$member = $this->login()->group(103)->member(16);
|
||||
|
||||
Nami::login();
|
||||
$this->assertSame($values[0], $member->toArray()[$key]);
|
||||
|
||||
$group = Nami::group(103);
|
||||
|
||||
$this->assertSame($values[0], $group->member(16)->toArray()[$key]);
|
||||
|
||||
Http::assertSentCount(5);
|
||||
Http::assertSentCount(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,17 +9,17 @@ use Zoomyboy\LaravelNami\Tests\TestCase;
|
|||
|
||||
class PullMembershipsTest extends TestCase
|
||||
{
|
||||
public $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":103}],"responseType":"OK"}';
|
||||
public $unauthorizedResponse = '';
|
||||
|
||||
public function errorProvider() {
|
||||
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() {
|
||||
public function dataProvider(): array
|
||||
{
|
||||
return [
|
||||
'id' => ['id', [68, 69]],
|
||||
'group_id' => ['group_id', [103,104]],
|
||||
|
@ -35,16 +35,14 @@ class PullMembershipsTest extends TestCase
|
|||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function test_get_all_memberships_of_a_member($key, $values) {
|
||||
Http::fake(array_merge($this->login(), [
|
||||
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->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
$member = new Member(['id' => 16]);
|
||||
|
||||
$memberships = $member->memberships();
|
||||
|
@ -53,25 +51,23 @@ class PullMembershipsTest extends TestCase
|
|||
$this->assertSame($values[$i], $m->toArray()[$key]);
|
||||
}
|
||||
|
||||
Http::assertSentCount(5);
|
||||
Http::assertSentCount(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider errorProvider
|
||||
*/
|
||||
public function test_it_gets_no_memberships_with_no_rights($error) {
|
||||
Http::fake(array_merge($this->login(), [
|
||||
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->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
$member = new Member(['id' => 16]);
|
||||
|
||||
$memberships = $member->memberships();
|
||||
$this->assertSame([], $member->memberships()->toArray());
|
||||
|
||||
Http::assertSentCount(4);
|
||||
Http::assertSentCount(2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,31 +2,30 @@
|
|||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Group;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
class PullNationalityTest extends TestCase
|
||||
{
|
||||
|
||||
public function test_get_all_nationalities() {
|
||||
Http::fake(array_merge($this->login(), [
|
||||
public function test_get_all_nationalities(): void
|
||||
{
|
||||
Http::fake([
|
||||
'https://nami.dpsg.de/ica/rest/baseadmin/staatsangehoerigkeit' => Http::response($this->fakeJson('nationalities.json'))
|
||||
]));
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
$nationalities = $this->login()->nationalities();
|
||||
|
||||
$this->assertEquals([
|
||||
['name' => 'deutsch', 'id' => 1054]
|
||||
], Nami::nationalities()->toArray());
|
||||
], $nationalities->toArray());
|
||||
|
||||
Http::assertSentCount(3);
|
||||
Http::assertSentCount(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,9 +50,9 @@ class PushMemberTest extends TestCase
|
|||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function test_push_a_single_member(array $overwrites, array $check): void {
|
||||
Http::fake(array_merge([
|
||||
Http::fake([
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response('{"success": true, "data": {"id": 16}}', 200),
|
||||
]));
|
||||
]);
|
||||
|
||||
$res = Nami::putMember(array_merge($this->attributes[0], $overwrites));
|
||||
$this->assertEquals(16, $res['id']);
|
||||
|
|
|
@ -11,16 +11,14 @@ use Zoomyboy\LaravelNami\Tests\TestCase;
|
|||
class PushMembershipsTest extends TestCase
|
||||
{
|
||||
|
||||
public function test_create_a_membership() {
|
||||
public function test_create_a_membership(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2021-02-03 06:00:00'));
|
||||
Http::fake(array_merge($this->login(), [
|
||||
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' => Http::response($this->fakeJson('membership-create.json'), 200),
|
||||
]));
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
$member = new Member(['id' => 16]);
|
||||
$id = $member->putMembership([
|
||||
'created_at' => now(),
|
||||
|
@ -31,7 +29,7 @@ class PushMembershipsTest extends TestCase
|
|||
]);
|
||||
$this->assertEquals(65, $id);
|
||||
|
||||
Http::assertSentCount(3);
|
||||
Http::assertSentCount(1);
|
||||
|
||||
Http::assertSent(fn ($request) => $request->method() === 'POST'
|
||||
&& $request->url() === 'https://nami.dpsg.de/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/16'
|
||||
|
|
|
@ -14,10 +14,8 @@ use Zoomyboy\LaravelNami\Tests\TestCase;
|
|||
|
||||
class SearchTest extends TestCase
|
||||
{
|
||||
public $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":103}],"responseType":"OK"}';
|
||||
public $unauthorizedResponse = '{"success":false,"data":null,"responseType":"EXCEPTION","message":"Access denied - no right for requested operation","title":"Exception"}';
|
||||
|
||||
public $attributes = [
|
||||
public array $attributes = [
|
||||
[
|
||||
'firstname' => 'Max',
|
||||
'lastname' => 'Nach1',
|
||||
|
@ -35,33 +33,34 @@ class SearchTest extends TestCase
|
|||
]
|
||||
];
|
||||
|
||||
public function dataProvider() {
|
||||
public function dataProvider(): array
|
||||
{
|
||||
return [
|
||||
'firstname' => ['vorname', ['Max', 'Jane']],
|
||||
];
|
||||
}
|
||||
|
||||
public function test_find_a_member_by_mglnr() {
|
||||
Http::fake(array_merge($this->login(), [
|
||||
public function test_find_a_member_by_mglnr(): void
|
||||
{
|
||||
Http::fake([
|
||||
$this->url(['mitgliedsNummber' => 150]) => Http::response($this->fakeJson('searchResponse.json'), 200),
|
||||
]));
|
||||
]);
|
||||
|
||||
$this->setCredentials();
|
||||
Nami::login();
|
||||
$member = $this->login()->findNr(150);
|
||||
|
||||
$member = Nami::findNr(150);
|
||||
$this->assertEquals('Philipp', $member->firstname);
|
||||
|
||||
Http::assertSent(function($request) {
|
||||
return $request->url() == $this->url(['mitgliedsNummber' => 150])
|
||||
&& $request->method() == 'GET';
|
||||
});
|
||||
|
||||
Http::assertSentCount(3);
|
||||
Http::assertSentCount(1);
|
||||
}
|
||||
|
||||
private function url($payload) {
|
||||
private function url(array $payload): string
|
||||
{
|
||||
$payload = rawurlencode(json_encode($payload));
|
||||
|
||||
return "https://nami.dpsg.de/ica/rest/nami/search-multi/result-list?searchedValues={$payload}&page=1&start=0&limit=100";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue