seed(RolesAndPermissionsSeeder::class); $this->pressRelease = PressRelease::factory()->published()->create([ 'classification' => PressReleaseClassification::Green->value, ]); }); test('an admin ends running and queued boosts with a reason', function () { /** @var TestCase $this */ $admin = User::factory()->create(); $admin->assignRole('admin'); $running = Boost::factory()->for($this->pressRelease)->create(); $queued = Boost::factory()->for($this->pressRelease)->create([ 'starts_at' => now()->addDays(7), 'ends_at' => now()->addDays(14), ]); $expired = Boost::factory()->for($this->pressRelease)->expired()->create(); $expiredEnd = $expired->ends_at; $this->actingAs($admin); Livewire::test('admin.press-releases.show', ['id' => $this->pressRelease->id]) ->assertSee('Boost beenden') ->set('boostEndReason', 'Test-Boost für die Screenshots beendet') ->call('endBoost') ->assertHasNoErrors(); expect($this->pressRelease->boosts()->active()->exists())->toBeFalse() ->and($running->fresh()->ends_at->lessThanOrEqualTo(now()))->toBeTrue() ->and($queued->fresh()->starts_at->lessThanOrEqualTo($queued->fresh()->ends_at))->toBeTrue() ->and($expired->fresh()->ends_at->equalTo($expiredEnd))->toBeTrue() ->and(Boost::query()->count())->toBe(3); $event = ActivityEvent::query()->where('type', ActivityType::BoostEnded->value)->sole(); expect($event->description)->toContain('Test-Boost für die Screenshots beendet') ->and($event->meta['boost_ids'])->toEqualCanonicalizing([$running->id, $queued->id]); }); test('ending a boost requires a reason', function () { /** @var TestCase $this */ $admin = User::factory()->create(); $admin->assignRole('admin'); Boost::factory()->for($this->pressRelease)->create(); $this->actingAs($admin); Livewire::test('admin.press-releases.show', ['id' => $this->pressRelease->id]) ->set('boostEndReason', '') ->call('endBoost') ->assertHasErrors(['boostEndReason']); expect($this->pressRelease->boosts()->active()->exists())->toBeTrue(); }); test('an editor sees the boost but cannot end it', function () { /** @var TestCase $this */ $editor = User::factory()->create(); $editor->assignRole('editor'); Boost::factory()->for($this->pressRelease)->create(); $this->actingAs($editor); Livewire::test('admin.press-releases.show', ['id' => $this->pressRelease->id]) ->assertSee('Gebuchte Platzierung') ->assertDontSee('Boost beenden') ->set('boostEndReason', 'Versuch ohne Abrechnungsrecht') ->call('endBoost') ->assertForbidden(); expect($this->pressRelease->boosts()->active()->exists())->toBeTrue(); });