seed(RolesAndPermissionsSeeder::class); $this->wallet = app(CreditWalletService::class); }); /** * @return array{customer: User, pr: PressRelease} */ function publishedGreenPrForOwner(): array { $customer = User::factory()->create(['is_active' => true]); $customer->assignRole('customer'); $company = Company::factory()->presseecho()->create(); $customer->companies()->attach($company->id, ['role' => 'owner']); $pr = PressRelease::factory()->published()->create([ 'user_id' => $customer->id, 'company_id' => $company->id, 'category_id' => Category::factory()->create()->id, 'portal' => $company->portal->value, 'classification' => PressReleaseClassification::Green->value, ]); return compact('customer', 'pr'); } test('a published green release shows the boost and proof add-ons', function () { /** @var TestCase $this */ ['customer' => $customer, 'pr' => $pr] = publishedGreenPrForOwner(); $this->wallet->credit($customer, 40); $this->actingAs($customer); LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id]) ->assertSee('Add-ons') ->assertSee('Boost — Platzierung') ->assertSee('7 Tage · 12 Credits') ->assertSee('Veröffentlichungsnachweis') ->assertSee('Für 3 Credits kaufen'); }); test('booking a boost from the detail page debits the wallet and activates it', function () { /** @var TestCase $this */ ['customer' => $customer, 'pr' => $pr] = publishedGreenPrForOwner(); $this->wallet->credit($customer, 40); $this->actingAs($customer); LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id]) ->call('buyBoost', 14); expect($customer->fresh()->creditBalance())->toBe(20); // 40 - 20 (14 Tage) expect($pr->fresh()->isBoosted())->toBeTrue(); }); test('buying a proof from the detail page unlocks the download', function () { /** @var TestCase $this */ ['customer' => $customer, 'pr' => $pr] = publishedGreenPrForOwner(); $this->wallet->credit($customer, 10); $this->actingAs($customer); LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id]) ->call('buyProof') ->assertSee('Nachweis herunterladen'); expect(app(ProofPdfService::class)->hasPurchased($customer->fresh(), $pr))->toBeTrue(); expect($customer->fresh()->creditBalance())->toBe(7); }); test('a non-green release cannot be boosted from the detail page', function () { /** @var TestCase $this */ ['customer' => $customer, 'pr' => $pr] = publishedGreenPrForOwner(); $pr->update(['classification' => PressReleaseClassification::Yellow->value]); $this->wallet->credit($customer, 40); $this->actingAs($customer); LivewireVolt::test('customer.press-releases.show', ['id' => $pr->id]) ->assertSee('Nur grün geprüfte Pressemitteilungen sind boostbar') ->call('buyBoost', 7); expect($customer->fresh()->creditBalance())->toBe(40); // nichts abgebucht expect($pr->fresh()->isBoosted())->toBeFalse(); });