Add: Create membership
This commit is contained in:
parent
04d5e6f03a
commit
9f5324b0d0
12
src/Api.php
12
src/Api.php
|
@ -124,6 +124,18 @@ class Api {
|
|||
return $response->json()['data'];
|
||||
}
|
||||
|
||||
public function putMembership(int $memberId, array $data): int
|
||||
{
|
||||
$url = self::$url."/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}";
|
||||
|
||||
$response = $this->http()->post($url, $data);
|
||||
if (data_get($response->json(), 'success') !== true) {
|
||||
$this->exception('Update failed', ['url' => $url, 'data' => $data], $response->json());
|
||||
}
|
||||
|
||||
return $response->json()['data'];
|
||||
}
|
||||
|
||||
public function membershipsOf($memberId): Collection {
|
||||
$url = self::$url.'/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'.$memberId.'/flist';
|
||||
|
||||
|
|
|
@ -152,6 +152,16 @@ class Member extends Model {
|
|||
});
|
||||
}
|
||||
|
||||
public function putMembership(array $data): int
|
||||
{
|
||||
return Nami::putMembership($this->id, [
|
||||
'gruppierungId' => $data['group_id'],
|
||||
'taetigkeitId' => $data['activity_id'],
|
||||
'untergliederungId' => $data['subactivity_id'],
|
||||
'aktivVon' => $data['created_at']->format('Y-m-d').'T00:00:00',
|
||||
]);
|
||||
}
|
||||
|
||||
public function membership($id): ?Membership {
|
||||
try {
|
||||
return Membership::fromNami(Nami::membership($this->id, $id));
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Member;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
class PushMembershipsTest extends TestCase
|
||||
{
|
||||
|
||||
public function test_create_a_membership() {
|
||||
Carbon::setTestNow(Carbon::parse('2021-02-03 06:00:00'));
|
||||
Http::fake(array_merge($this->login(), [
|
||||
'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(),
|
||||
'group_id' => 150,
|
||||
'activity_id' => 56,
|
||||
'subactivity_id' => 89,
|
||||
]);
|
||||
$this->assertEquals(65, $id);
|
||||
|
||||
Http::assertSentCount(3);
|
||||
|
||||
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'
|
||||
&& $request['gruppierungId'] === 150
|
||||
&& $request['taetigkeitId'] === 56
|
||||
&& $request['untergliederungId'] === 89
|
||||
&& $request['aktivVon'] === '2021-02-03T00:00:00'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"data": 65,
|
||||
"responseType": "OK",
|
||||
"success": true
|
||||
}
|
Loading…
Reference in New Issue