Add create member
This commit is contained in:
parent
38fe258f5c
commit
a1b3d132bd
14
src/Api.php
14
src/Api.php
|
@ -90,10 +90,18 @@ class Api {
|
|||
|
||||
public function putMember(array $attributes) {
|
||||
$member = Member::fromAttributes($attributes);
|
||||
$response = $this->http()->put(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id.'/'.$member->id, $member->toNami());
|
||||
if (data_get($attributes, 'id')) {
|
||||
$response = $this->http()->put(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id.'/'.$member->id, $member->toNami());
|
||||
if (data_get($response->json(), 'success') !== true) {
|
||||
$this->exception('Update failed', $member->toNami(), $response->json());
|
||||
}
|
||||
} else {
|
||||
$response = $this->http()->post(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id, $member->toNami());
|
||||
if (data_get($response->json(), 'success') !== true) {
|
||||
$this->exception('Update failed', $member->toNami(), $response->json());
|
||||
}
|
||||
|
||||
if (data_get($response->json(), 'success') !== true) {
|
||||
$this->exception('Update failed', $member->toNami(), $response->json());
|
||||
return ['id' => $response->json()['data']];
|
||||
}
|
||||
|
||||
return $response->json()['data'];
|
||||
|
|
|
@ -98,6 +98,8 @@ class Member extends Model {
|
|||
'nameZusatz' => $this->further_address ?: '',
|
||||
'konfessionId' => $this->confession_id,
|
||||
'staatsangehoerigkeitText' => $this->other_country ?: '',
|
||||
'ersteTaetigkeitId' => $this->first_activity_id ?: null,
|
||||
'ersteUntergliederungId' => $this->first_subactivity_id ?: null,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -74,15 +74,16 @@ class PushMemberTest extends TestCase
|
|||
*/
|
||||
public function test_push_a_single_member($key, $values) {
|
||||
Http::fake(array_merge($this->login(), [
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response('{"id": 16}', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/17' => Http::response('{"id": 17}', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response('{"success": true, "data": {"id": 16}}', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/17' => Http::response('{"success": true, "data": {"id": 17}}', 200),
|
||||
]));
|
||||
|
||||
$this->setCredentials();
|
||||
Nami::login();
|
||||
|
||||
Nami::putMember($this->attributes[0]);
|
||||
Nami::putMember($this->attributes[1]);
|
||||
$res = Nami::putMember($this->attributes[1]);
|
||||
$this->assertEquals(17, $res['id']);
|
||||
|
||||
Http::assertSent(function($request) use ($key, $values) {
|
||||
return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16'
|
||||
|
|
Loading…
Reference in New Issue