mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-05-18 20:34:52 +00:00
🚀 **Automate Meetup Activity Recalculation**
- Introduced `recalculateActivity` method in `Meetup` model to centralize activity and event timestamp updates. - Added `MeetupEventObserver` to trigger activity recalculation on event save/delete. - Updated `/meetups:update-activity` command to leverage the new model method for cleanup. - Enhanced tests to cover various `MeetupEvent` scenarios affecting activity states.
This commit is contained in:
@@ -49,8 +49,8 @@ it('keeps a meetup active when it only has a future event', function () {
|
||||
->and($meetup->last_event_at)->toBeNull();
|
||||
});
|
||||
|
||||
it('keeps a meetup active when a recurring event has no end date', function () {
|
||||
$meetup = Meetup::factory()->create(['is_active' => false, 'last_event_at' => null]);
|
||||
it('marks a meetup as inactive when a recurring event has no end date but is older than a year', function () {
|
||||
$meetup = Meetup::factory()->create(['is_active' => true, 'last_event_at' => now()]);
|
||||
MeetupEvent::factory()->create([
|
||||
'meetup_id' => $meetup->id,
|
||||
'start' => now()->subYears(3),
|
||||
@@ -60,6 +60,21 @@ it('keeps a meetup active when a recurring event has no end date', function () {
|
||||
|
||||
$this->artisan('meetups:update-activity')->assertSuccessful();
|
||||
|
||||
$meetup->refresh();
|
||||
expect($meetup->is_active)->toBeFalse();
|
||||
});
|
||||
|
||||
it('keeps a meetup active when a recurring event has an end date in the future', function () {
|
||||
$meetup = Meetup::factory()->create(['is_active' => false, 'last_event_at' => null]);
|
||||
MeetupEvent::factory()->create([
|
||||
'meetup_id' => $meetup->id,
|
||||
'start' => now()->subYears(3),
|
||||
'recurrence_type' => RecurrenceType::Monthly,
|
||||
'recurrence_end_date' => now()->addMonths(6),
|
||||
]);
|
||||
|
||||
$this->artisan('meetups:update-activity')->assertSuccessful();
|
||||
|
||||
$meetup->refresh();
|
||||
expect($meetup->is_active)->toBeTrue();
|
||||
});
|
||||
@@ -74,6 +89,36 @@ it('marks a meetup as inactive when no events exist at all', function () {
|
||||
->and($meetup->last_event_at)->toBeNull();
|
||||
});
|
||||
|
||||
it('flips a meetup from inactive to active immediately when a future event is created', function () {
|
||||
$meetup = Meetup::factory()->create(['is_active' => false, 'last_event_at' => null]);
|
||||
|
||||
MeetupEvent::factory()->create([
|
||||
'meetup_id' => $meetup->id,
|
||||
'start' => now()->addDays(7),
|
||||
'recurrence_type' => null,
|
||||
]);
|
||||
|
||||
$meetup->refresh();
|
||||
expect($meetup->is_active)->toBeTrue();
|
||||
});
|
||||
|
||||
it('flips a meetup back to inactive when its only future event is deleted', function () {
|
||||
$meetup = Meetup::factory()->create(['is_active' => false, 'last_event_at' => null]);
|
||||
$event = MeetupEvent::factory()->create([
|
||||
'meetup_id' => $meetup->id,
|
||||
'start' => now()->addDays(7),
|
||||
'recurrence_type' => null,
|
||||
]);
|
||||
|
||||
$meetup->refresh();
|
||||
expect($meetup->is_active)->toBeTrue();
|
||||
|
||||
$event->delete();
|
||||
|
||||
$meetup->refresh();
|
||||
expect($meetup->is_active)->toBeFalse();
|
||||
});
|
||||
|
||||
it('marks a meetup as inactive when a recurring event has ended more than a year ago', function () {
|
||||
$meetup = Meetup::factory()->create(['is_active' => true, 'last_event_at' => now()]);
|
||||
MeetupEvent::factory()->create([
|
||||
|
||||
Reference in New Issue
Block a user