Add member update test
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2022-02-11 01:24:09 +01:00
parent 2f9370f0b3
commit 4adeae0cf4
5 changed files with 154 additions and 1 deletions

View File

@ -2,10 +2,14 @@
namespace App;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Confession extends Model
{
use HasFactory;
public $fillable = ['name', 'nami_id', 'is_null'];
public $timestamps = false;
}

View File

@ -0,0 +1,25 @@
<?php
namespace Database\Factories;
use App\Confession;
use Illuminate\Database\Eloquent\Factories\Factory;
class ConfessionFactory extends Factory
{
protected $model = Confession::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->sentence(),
'is_null' => false,
];
}
}

@ -1 +1 @@
Subproject commit 2d66d23f6ca98ff5db0ade8bd323f26f4d014899
Subproject commit b833537f32835adb881d873a924b56d63c61d327

View File

@ -7,6 +7,7 @@ use App\Course\Models\CourseMember;
use App\Member\Member;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use Zoomyboy\LaravelNami\Backend\FakeBackend;
class IndexTest extends TestCase
{
@ -15,6 +16,25 @@ class IndexTest extends TestCase
public function testItGetsMembers(): void
{
$backend = app(FakeBackend::class)
->fakeMember([
'vorname' => '::firstname::',
'nachname' => '::lastname::',
'beitragsartId' => 300,
'geburtsDatum' => '2014-07-11 00:00:00',
'gruppierungId' => 1000,
'id' => 411,
'eintrittsdatum' => '2020-11-17 00:00:00',
'geschlechtId' => 303,
'landId' => 302,
'staatsangehoerigkeitId' => 291,
'zeitschriftenversand' => true,
'strasse' => '::street',
'plz' => '12346',
'ort' => '::location::',
'gruppierung' => '::group::',
'version' => 40,
]);
$this->withoutExceptionHandling();
$this->login();

View File

@ -0,0 +1,104 @@
<?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;
use Tests\TestCase;
use Zoomyboy\LaravelNami\Backend\FakeBackend;
class UpdateTest extends TestCase
{
use DatabaseTransactions;
public function testItRedirectsToMemberOverview(): void
{
$this->withoutExceptionHandling()->login();
$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
{
$this->withoutExceptionHandling()->login();
$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
{
$this->withoutExceptionHandling()->login();
$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['missingkey'] === 'missingvalue' && $request['vorname'] === '::firstname::'
);
}
public function testItUpdatesVersion(): void
{
$this->withoutExceptionHandling()->login();
$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') {
return Http::response('{ "success": true, "data": {"missingkey": "missingvalue"} }', 200);
}
if ($request->url() === app(FakeBackend::class)->singleMemberUrl(10, 135) && $request->method() === 'PUT') {
return Http::response('{ "success": true, "data": { "version": 44 } }', 200);
}
});
}
}