2020-07-15 22:55:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
|
|
|
|
2022-02-11 00:14:48 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2020-07-15 22:55:52 +02:00
|
|
|
use Illuminate\Support\Facades\Config;
|
2022-02-11 00:14:48 +01:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2020-07-15 22:55:52 +02:00
|
|
|
use Zoomyboy\LaravelNami\Group;
|
2022-02-11 00:14:48 +01:00
|
|
|
use Zoomyboy\LaravelNami\LoginException;
|
2020-07-15 22:55:52 +02:00
|
|
|
use Zoomyboy\LaravelNami\Member;
|
2022-02-11 00:14:48 +01:00
|
|
|
use Zoomyboy\LaravelNami\Nami;
|
|
|
|
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
|
|
|
use Zoomyboy\LaravelNami\Tests\TestCase;
|
2020-07-15 22:55:52 +02:00
|
|
|
|
2021-04-11 16:58:10 +02:00
|
|
|
class PushMemberTest extends TestCase
|
2020-07-15 22:55:52 +02:00
|
|
|
{
|
2022-02-11 00:14:48 +01:00
|
|
|
public array $attributes = [
|
2020-07-15 22:55:52 +02:00
|
|
|
[
|
|
|
|
'firstname' => 'Max',
|
|
|
|
'lastname' => 'Nach1',
|
|
|
|
'group_id' => 103,
|
|
|
|
'nickname' => 'spitz1',
|
2021-04-11 16:58:10 +02:00
|
|
|
'gender_id' => 17,
|
2021-06-21 22:37:23 +02:00
|
|
|
'joined_at' => '2021-02-02T00:00:00',
|
|
|
|
'birthday' => '2021-02-02',
|
2021-04-11 16:58:10 +02:00
|
|
|
'id' => 16,
|
2020-07-15 22:55:52 +02:00
|
|
|
], [
|
|
|
|
'firstname' => 'Jane',
|
|
|
|
'lastname' => 'Nach2',
|
|
|
|
'nickname' => null,
|
|
|
|
'group_id' => 103,
|
2021-04-11 16:58:10 +02:00
|
|
|
'gender_id' => null,
|
2021-06-21 22:37:23 +02:00
|
|
|
'joined_at' => '2021-02-02T00:00:00',
|
|
|
|
'birthday' => '2021-02-02',
|
2021-04-11 16:58:10 +02:00
|
|
|
'id' => 17,
|
2020-07-15 22:55:52 +02:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2022-02-11 00:14:48 +01:00
|
|
|
public function dataProvider(): array {
|
2020-07-15 22:55:52 +02:00
|
|
|
return [
|
2022-02-11 00:14:48 +01:00
|
|
|
'firstname' => [['firstname' => 'Max'], ['vorname' => 'Max']],
|
|
|
|
'lastname' => [['lastname' => 'Nach1'], ['nachname' => 'Nach1']],
|
|
|
|
'nickname' => [['nickname' => 'nick'], ['spitzname' => 'nick']],
|
|
|
|
'nicknameEmpty' => [['nickname' => null], ['spitzname' => '']],
|
|
|
|
'gender_id' => [['gender_id' => 17], ['geschlechtId' => 17]],
|
2020-07-15 22:55:52 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataProvider
|
|
|
|
*/
|
2022-02-11 00:14:48 +01:00
|
|
|
public function test_push_a_single_member(array $overwrites, array $check): void {
|
2022-02-18 18:29:02 +01:00
|
|
|
Http::fake([
|
2021-06-23 01:57:19 +02:00
|
|
|
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response('{"success": true, "data": {"id": 16}}', 200),
|
2022-02-18 18:29:02 +01:00
|
|
|
]);
|
2020-07-15 22:55:52 +02:00
|
|
|
|
2022-02-11 00:14:48 +01:00
|
|
|
$res = Nami::putMember(array_merge($this->attributes[0], $overwrites));
|
|
|
|
$this->assertEquals(16, $res['id']);
|
2020-07-15 22:55:52 +02:00
|
|
|
|
2022-02-11 00:14:48 +01:00
|
|
|
Http::assertSent(function($request) use ($check) {
|
2022-02-11 01:23:31 +01:00
|
|
|
if ($request->url() != 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' || $request->method() !== 'PUT') {
|
2022-02-11 00:14:48 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-07-15 22:55:52 +02:00
|
|
|
|
2022-02-11 00:14:48 +01:00
|
|
|
foreach ($check as $key => $value) {
|
|
|
|
if ($request[$key] !== $value) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-07-15 22:55:52 +02:00
|
|
|
|
2022-02-11 00:14:48 +01:00
|
|
|
return $request->method() === 'PUT';
|
2020-07-15 22:55:52 +02:00
|
|
|
});
|
|
|
|
|
2022-02-11 01:23:31 +01:00
|
|
|
Http::assertSentCount(2);
|
2020-07-15 22:55:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|