Add initializer for activities with meta info
This commit is contained in:
parent
a418a4b898
commit
b73e7f34e6
|
@ -14,7 +14,7 @@ class Activity extends Model
|
||||||
use HasNamiField;
|
use HasNamiField;
|
||||||
use Sluggable;
|
use Sluggable;
|
||||||
|
|
||||||
public $fillable = ['is_try', 'is_member', 'name', 'is_filterable', 'nami_id'];
|
public $fillable = ['is_try', 'has_efz', 'is_member', 'name', 'is_filterable', 'nami_id'];
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
public $casts = [
|
public $casts = [
|
||||||
|
|
|
@ -6,15 +6,50 @@ use Zoomyboy\LaravelNami\Api;
|
||||||
|
|
||||||
class ActivityCreator
|
class ActivityCreator
|
||||||
{
|
{
|
||||||
|
/** @var array<int, string> */
|
||||||
private array $tries = [
|
private array $tries = [
|
||||||
'Schnuppermitgliedschaft',
|
'Schnuppermitgliedschaft',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** @var array<int, string> */
|
||||||
private array $members = [
|
private array $members = [
|
||||||
'€ Mitglied',
|
'€ Mitglied',
|
||||||
'Schnuppermitgliedschaft',
|
'Schnuppermitgliedschaft',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** @var array<int, string> */
|
||||||
|
private array $filterableActivities = [
|
||||||
|
'€ Mitglied',
|
||||||
|
'€ passive Mitgliedschaft',
|
||||||
|
'€ KassiererIn',
|
||||||
|
'€ LeiterIn',
|
||||||
|
'Schnuppermitgliedschaft',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @var array<int, string> */
|
||||||
|
private array $filterableSubactivities = [
|
||||||
|
'Biber',
|
||||||
|
'Wölfling',
|
||||||
|
'Jungpfadfinder',
|
||||||
|
'Pfadfinder',
|
||||||
|
'Vorstand',
|
||||||
|
'Rover',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @var array<int, string> */
|
||||||
|
private array $ageGroups = [
|
||||||
|
'Biber',
|
||||||
|
'Wölfling',
|
||||||
|
'Jungpfadfinder',
|
||||||
|
'Pfadfinder',
|
||||||
|
'Rover',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @var array<int, string> */
|
||||||
|
private array $efz = [
|
||||||
|
'€ LeiterIn',
|
||||||
|
];
|
||||||
|
|
||||||
public function createFor(Api $api, int $groupId): void
|
public function createFor(Api $api, int $groupId): void
|
||||||
{
|
{
|
||||||
$api->activities($groupId)->each(function ($activity) use ($api) {
|
$api->activities($groupId)->each(function ($activity) use ($api) {
|
||||||
|
@ -23,6 +58,8 @@ class ActivityCreator
|
||||||
'name' => $activity->name,
|
'name' => $activity->name,
|
||||||
'is_try' => in_array($activity->name, $this->tries),
|
'is_try' => in_array($activity->name, $this->tries),
|
||||||
'is_member' => in_array($activity->name, $this->members),
|
'is_member' => in_array($activity->name, $this->members),
|
||||||
|
'is_filterable' => in_array($activity->name, $this->filterableActivities),
|
||||||
|
'has_efz' => in_array($activity->name, $this->efz),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$groups = [];
|
$groups = [];
|
||||||
|
@ -30,6 +67,8 @@ class ActivityCreator
|
||||||
$group = \App\Subactivity::updateOrCreate(['nami_id' => $group->id], [
|
$group = \App\Subactivity::updateOrCreate(['nami_id' => $group->id], [
|
||||||
'nami_id' => $group->id,
|
'nami_id' => $group->id,
|
||||||
'name' => $group->name,
|
'name' => $group->name,
|
||||||
|
'is_filterable' => in_array($group->name, $this->filterableSubactivities),
|
||||||
|
'is_age_group' => in_array($group->name, $this->ageGroups),
|
||||||
]);
|
]);
|
||||||
$groups[] = $group->id;
|
$groups[] = $group->id;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 94094aebcd4141f590942db4931bc5812154a965
|
Subproject commit e8d26ab774dbc101729c4942e5259a30fbe9e342
|
15
phpstan.neon
15
phpstan.neon
|
@ -205,16 +205,6 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: app/Http/Views/MemberView.php
|
path: app/Http/Views/MemberView.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Property App\\\\Initialize\\\\ActivityCreator\\:\\:\\$members type has no value type specified in iterable type array\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: app/Initialize/ActivityCreator.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Property App\\\\Initialize\\\\ActivityCreator\\:\\:\\$tries type has no value type specified in iterable type array\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: app/Initialize/ActivityCreator.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\LazyCollection\\<int,Zoomyboy\\\\LaravelNami\\\\Member\\>\\:\\:each\\(\\) expects callable\\(int, int\\)\\: mixed, Closure\\(Zoomyboy\\\\LaravelNami\\\\Member\\)\\: void given\\.$#"
|
message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\LazyCollection\\<int,Zoomyboy\\\\LaravelNami\\\\Member\\>\\:\\:each\\(\\) expects callable\\(int, int\\)\\: mixed, Closure\\(Zoomyboy\\\\LaravelNami\\\\Member\\)\\: void given\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
@ -1094,11 +1084,6 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: packages/laravel-nami/tests/TestCase.php
|
path: packages/laravel-nami/tests/TestCase.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Parameter \\#2 \\$membershipIds of method Zoomyboy\\\\LaravelNami\\\\Fakes\\\\MembershipFake\\:\\:fetches\\(\\) expects array\\<int, array\\{id\\: int, entries_taetigkeit\\?\\: string, entries_aktivVon\\?\\: string, entries_aktivBis\\?\\: string, entries_untergliederung\\?\\: string, entries_gruppierung\\?\\: string\\}\\|int\\>, array\\{array\\{entries_aktivBis\\: '', entries_untergliederung\\: ''\\}\\} given\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: packages/laravel-nami/tests/Unit/Api/MembershipIndexTest.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method Zoomyboy\\\\LaravelNami\\\\Tests\\\\Unit\\\\PullMemberTest\\:\\:dataProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
|
message: "#^Method Zoomyboy\\\\LaravelNami\\\\Tests\\\\Unit\\\\PullMemberTest\\:\\:dataProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Initialize;
|
||||||
|
|
||||||
|
use App\Activity;
|
||||||
|
use App\Initialize\InitializeActivities;
|
||||||
|
use App\Setting\NamiSettings;
|
||||||
|
use App\Subactivity;
|
||||||
|
use Generator;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Zoomyboy\LaravelNami\Fakes\ActivityFake;
|
||||||
|
use Zoomyboy\LaravelNami\Fakes\GroupFake;
|
||||||
|
|
||||||
|
class InitializeActivitiesTest extends TestCase
|
||||||
|
{
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function testItInitializesActivities(): void
|
||||||
|
{
|
||||||
|
app(GroupFake::class)
|
||||||
|
->fetches(null, [1000 => ['name' => 'testgroup']])
|
||||||
|
->fetches(1000, []);
|
||||||
|
app(ActivityFake::class)->fetches(1000, [
|
||||||
|
['id' => 46, 'descriptor' => 'testakt'],
|
||||||
|
])->fetchesSubactivity(46, [
|
||||||
|
['id' => 47, 'descriptor' => 'subakt'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
|
||||||
|
(new InitializeActivities(app(NamiSettings::class)->login()))->handle();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('activities', [
|
||||||
|
'name' => 'testakt',
|
||||||
|
'slug' => 'testakt',
|
||||||
|
'is_filterable' => false,
|
||||||
|
'nami_id' => 46,
|
||||||
|
'is_member' => false,
|
||||||
|
'is_try' => false,
|
||||||
|
'has_efz' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('subactivities', [
|
||||||
|
'name' => 'subakt',
|
||||||
|
'slug' => 'subakt',
|
||||||
|
'is_age_group' => false,
|
||||||
|
'is_filterable' => false,
|
||||||
|
'nami_id' => 47,
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('activity_subactivity', [
|
||||||
|
'activity_id' => Activity::firstWhere('name', 'testakt')->id,
|
||||||
|
'subactivity_id' => Subactivity::firstWhere('name', 'subakt')->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function activityDataProvider(): Generator
|
||||||
|
{
|
||||||
|
yield [
|
||||||
|
fn (ActivityFake $fake) => $fake->fetches(1000, [
|
||||||
|
['id' => 46, 'descriptor' => '€ Mitglied'],
|
||||||
|
])->fetchesSubactivity(46, [
|
||||||
|
['id' => 47, 'descriptor' => 'Wölfling'],
|
||||||
|
]),
|
||||||
|
['nami_id' => 46, 'is_filterable' => true, 'is_member' => true],
|
||||||
|
['nami_id' => 47, 'is_filterable' => true, 'is_age_group' => true],
|
||||||
|
];
|
||||||
|
|
||||||
|
yield [
|
||||||
|
fn (ActivityFake $fake) => $fake->fetches(1000, [
|
||||||
|
['id' => 46, 'descriptor' => 'Schnuppermitgliedschaft'],
|
||||||
|
])->fetchesSubactivity(46, []),
|
||||||
|
['nami_id' => 46, 'is_filterable' => true, 'is_member' => true, 'is_try' => true],
|
||||||
|
];
|
||||||
|
|
||||||
|
yield [
|
||||||
|
fn (ActivityFake $fake) => $fake->fetches(1000, [
|
||||||
|
['id' => 46, 'descriptor' => '€ LeiterIn'],
|
||||||
|
])->fetchesSubactivity(46, []),
|
||||||
|
['nami_id' => 46, 'has_efz' => true, 'is_filterable' => true],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider activityDataProvider
|
||||||
|
*
|
||||||
|
* @param array<string, string|null> $activityCheck
|
||||||
|
* @param array<string, string|null> $subactivityCheck
|
||||||
|
*/
|
||||||
|
public function testItInitsOtherFields(callable $activityFake, array $activityCheck, ?array $subactivityCheck = null): void
|
||||||
|
{
|
||||||
|
app(GroupFake::class)
|
||||||
|
->fetches(null, [1000 => ['name' => 'testgroup']])
|
||||||
|
->fetches(1000, []);
|
||||||
|
|
||||||
|
$activityFake(app(ActivityFake::class));
|
||||||
|
|
||||||
|
$this->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
|
||||||
|
(new InitializeActivities(app(NamiSettings::class)->login()))->handle();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('activities', $activityCheck);
|
||||||
|
|
||||||
|
if ($subactivityCheck) {
|
||||||
|
$this->assertDatabaseHas('subactivities', $subactivityCheck);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue