2022-02-11 01:24:09 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Member;
|
|
|
|
|
|
|
|
use App\Confession;
|
|
|
|
use App\Country;
|
|
|
|
use App\Course\Models\Course;
|
|
|
|
use App\Course\Models\CourseMember;
|
|
|
|
use App\Fee;
|
|
|
|
use App\Group;
|
|
|
|
use App\Member\Member;
|
|
|
|
use App\Nationality;
|
|
|
|
use App\Payment\Subscription;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2022-02-11 01:56:02 +01:00
|
|
|
use Illuminate\Support\Str;
|
2022-02-11 01:24:09 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
use Zoomyboy\LaravelNami\Backend\FakeBackend;
|
|
|
|
|
|
|
|
class UpdateTest extends TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
public function testItRedirectsToMemberOverview(): void
|
|
|
|
{
|
2022-02-19 18:08:29 +01:00
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
2022-02-11 01:24:09 +01:00
|
|
|
$member = $this->member();
|
|
|
|
$this->fakeRequest();
|
|
|
|
|
|
|
|
$response = $this
|
|
|
|
->from("/member/{$member->id}")
|
|
|
|
->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true]));
|
|
|
|
|
|
|
|
$response->assertRedirect('/member');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItHasPutRequest(): void
|
|
|
|
{
|
2022-02-19 18:08:29 +01:00
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
2022-02-11 01:24:09 +01:00
|
|
|
$member = $this->member();
|
|
|
|
$this->fakeRequest();
|
|
|
|
|
|
|
|
$response = $this
|
|
|
|
->from("/member/{$member->id}")
|
|
|
|
->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true, 'firstname' => '::firstname::']));
|
|
|
|
|
|
|
|
Http::assertSent(fn ($request) => $request->method() === 'PUT'
|
|
|
|
&& $request['vorname'] === '::firstname::'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItMergesExistingData(): void
|
|
|
|
{
|
2022-02-19 18:08:29 +01:00
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
2022-02-11 01:24:09 +01:00
|
|
|
$member = $this->member();
|
|
|
|
$this->fakeRequest();
|
|
|
|
|
|
|
|
$response = $this
|
|
|
|
->from("/member/{$member->id}")
|
|
|
|
->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true, 'firstname' => '::firstname::']));
|
|
|
|
|
|
|
|
Http::assertSent(fn ($request) => $request->method() === 'PUT'
|
2022-02-11 01:56:02 +01:00
|
|
|
&& $request['kontoverbindung'] === '{"a":"b"}'
|
|
|
|
&& $request['missingkey'] === 'missingvalue'
|
|
|
|
&& $request['vorname'] === '::firstname::'
|
2022-02-11 01:24:09 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItUpdatesVersion(): void
|
|
|
|
{
|
2022-02-19 18:08:29 +01:00
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
2022-02-11 01:24:09 +01:00
|
|
|
$member = $this->member();
|
|
|
|
$this->fakeRequest();
|
|
|
|
|
|
|
|
$response = $this
|
|
|
|
->from("/member/{$member->id}")
|
|
|
|
->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true]));
|
|
|
|
|
|
|
|
$this->assertEquals(44, $member->fresh()->version);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function member(): Member
|
|
|
|
{
|
|
|
|
return Member::factory()
|
|
|
|
->for(Group::factory()->state(['nami_id' => 10]))
|
|
|
|
->for(Confession::factory())
|
|
|
|
->for(Nationality::factory())
|
|
|
|
->for(Subscription::factory()->for(Fee::factory()))
|
|
|
|
->for(Country::factory())
|
|
|
|
->create(['nami_id' => 135]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function fakeRequest(): void
|
|
|
|
{
|
|
|
|
Http::fake(function ($request) {
|
|
|
|
if ($request->url() === app(FakeBackend::class)->singleMemberUrl(10, 135) && $request->method() === 'GET') {
|
2022-02-11 01:56:02 +01:00
|
|
|
return Http::response('{ "success": true, "data": {"missingkey": "missingvalue", "kontoverbindung": {"a": "b"} } }', 200);
|
2022-02-11 01:24:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->url() === app(FakeBackend::class)->singleMemberUrl(10, 135) && $request->method() === 'PUT') {
|
|
|
|
return Http::response('{ "success": true, "data": { "version": 44 } }', 200);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|