seed(RolePermissionSeeder::class); } #[Test] public function it_finds_what_closes_or_comes_off_soon_and_nothing_else(): void { $closing = Call::factory()->create(['status' => CallStatus::Open, 'closes_at' => now()->addDays(3)]); Call::factory()->create(['status' => CallStatus::Open, 'closes_at' => now()->addMonths(2)]); Call::factory()->create(['status' => CallStatus::Closed, 'closes_at' => now()->addDays(3)]); $leaving = Page::factory()->published()->create(['unpublish_at' => now()->addDays(5)]); Page::factory()->draft()->create(['unpublish_at' => now()->addDays(5)]); $items = Expiring::within(14); $this->assertSame([[$closing->id, 'closes'], [$leaving->id, 'unpublishes']], $items->map(fn ($i) => [$i['record']->id, $i['event']])->all()); } #[Test] public function the_dashboard_shows_it_to_whoever_can_act(): void { Call::factory()->create(['status' => CallStatus::Open, 'closes_at' => now()->addDays(3), 'title' => ['es' => 'Backend', 'en' => 'Backend']]); $this->actingAs($this->userWithRoles('editor')); $this->assertTrue(ExpiringSoonWidget::canView()); Livewire::test(ExpiringSoonWidget::class)->assertSee('Backend'); $this->actingAs($this->userWithRoles('viewer')); $this->assertFalse(ExpiringSoonWidget::canView()); } #[Test] public function editors_are_reminded_a_week_and_a_day_ahead_only(): void { Notification::fake(); $editor = $this->userWithRoles('editor'); $viewer = $this->userWithRoles('viewer'); Call::factory()->create(['status' => CallStatus::Open, 'closes_at' => now()->addDays(7)]); Call::factory()->create(['status' => CallStatus::Open, 'closes_at' => now()->addDays(4)]); $this->artisan('content:expiring')->assertSuccessful(); Notification::assertSentTo($editor, ExpiringSoon::class, fn (ExpiringSoon $n) => $n->items->count() === 1); Notification::assertNotSentTo($viewer, ExpiringSoon::class); } }